applications of datastructure
applications of datastructure
Of
Data_structure
• Stack:-
Check whether the string is palindrome [O (n)]:
Algorithms
1- Make to indexes one at the beginning ‘i’ and the other at the
end ‘j’
2- Compare ‘i’ and j values if they are the same:
True: increment ‘i’, decrease ‘j’
False: the string is not palindrome
3- If ‘i’ and ‘j’ met at the middle(X) the n the string is
palindrome.
Code
Output
1- Create a stack
2- Iterate for symbols in the given string a. Ignore any
symbol expect the parentheses
b. Push the symbol to the stack if it is opening (, {, [
c. If it is closing, check if the stack empty reports an error,
if not pop the stack.
d. If the popped symbol does not correspond to an opening
symbol, report, and error.
3- At the end, if the stack is empty then the symbols are
balanced.
Code
Output
• Tree:-
This tree represents the expression ((((3
+1)*3)/((9 −5)+2))−((3×(7−4)) +6)).
Algorithms
• Queue:-
When you go to super market you take a
number to wait this example print the first
element and dequeue it:
Algorithms
Output
• Linked list:-
Implement stack using linked-list:
Algorithms
Code
Output
• Graph:-
Represent a graph by adjacency matrix
V = {‘el maadi’, ’helwan’, ’dar el Salam’, ’el
basaten ‘}
E = {{‘el maadi’, ’helwan’},{’helwan’, ’dar el
salam’},{’dar el salam’, ’el basaten ‘},{’el
basaten ‘,’helwan’},{ el maadi’, ’dar el salam’}}
Algorithm
1- Add nodes.
2- Add edges.
3- Print adj matrix.
Code
Output
Output