Data Structure
Data Structure
QUEUE
STACK 2
STACK 1
Implementation of Stack using two Queues
q1
q2
STACK
1
2 3 3
2 9
3 2 5
2 5
-4
Infix to postfix
SCANNED STACK EXPRESSION
( (
a a
+ (+ a
b (+ ab
) ab+
* * ab+
( *( ab+
c *( ab+c
+ *(+ ab+c
d *(+ ab+cd
) * ab+cd+
ab+cd+*
infix to prefix: (a + b) ∗ (c + d)
inverse infix expression: (d+c)*(b+a)
Solution:
Write a function to display all the nodes values in a given singly linked list.
Solution:
Write a function that searches a given key ‘x’ in a given singly linked list. The
function should return true if x is present in linked list and false otherwise.
Solution:
Write a GetNth() function that takes a linked list and an integer index and
returns the data value stored in the node at that index position.
Solution:
Can you implement the dynamic-set operation INSERT on a singly linked list
in O(1) time? How about DELETE?
Solution:
INSERT - yes, words can be inserted directly at the beginning of the list,
DELETE - no, because it requires traversing the whole list.
Implement a stack using a singly linked list L. The operations PUSH and POP
should still take O(1) time.
Solution:
The PUSH operation adds an element in the beginning of the list and
the POP operation removes the first element from the list.
Solution:
We need to keep track of the last element of the list.
Whenever we ENQUEUE, we should be inserting the element after it
and marking the new last element of the list.
Whenever we DEQUEUE, we should pop the first element of the list.
Worst Case time complexity of different data structures for different operations
Unstable sorting: - If a sorting algorithm, after sorting the contents, changes the
sequence of similar content in which they appear, it is called unstable sorting.
Example: - QuickSort, Heap Sort, and Selection sort