Learn Stack data structure
About Stack:
A Stack is a simple data structure used for storing data, in which insertion and deletion are done at one end, called Top.
Stack Abstract Type:
The following operations make a stack an Abstract Data Type.
Operations:
- Main operations: push and pop
- Auxilliary operations: top, size, isEmptyStack, isFullStack
Why and when to use Stack:
- Balancing of symbols.
- Infix to postfix conversion.
- Evaluation of postfix expression.
- Implementing function calls.
- Finding of spans (like in stock market).
- Page history in a web browser.
- Undo sequence in a text editor.
- Matching tags in HTML and XML (parses uses stack while tokenising the input)
Practice questions:
- Balancing of symbols using stack.
- Infix to postfix conversion using stack.
- Postfix evaluation using stack.
- Can we evaluate the infix expression with stacks in one pass?
- How to design a stack such that GetMinnimum() should be O(1).
- Optimized solution in terms of space for Q5.
- For a given array with n symbols, how many stack permutations are possible?
- Check if the given string is palindrome or not.
- Consider a linked list instead of a string literal in Q8.
- Q9 using stack.
- How to reverse elements of a stack using only stack operations (push and pop)?
- Implement one queue using two stacks.
- Implement one stack using two queues.
- Implement two stacks using only one array.
- Implement three stacks using only one array.
- Another way of solving Q15.
- Implement m stacks using only one array.
- If the string S2 can be made from string S1, using only stack operations? Where S donates a push operation and X donates a pop operation. Example: let the numbers: 1,2,3,4,5,6 pushed in a stack in chronological order, can they be permuted in this order: O1(3,2,5,6,4,1) and O2(1,5,4,6,2,3)?
- For dynamic array implementation of stack, what will be the complexity of a push operation if we create a new array whose size is (n+k)?
- For a string of n S's and n X's, where S donates a push and X donates a pop operation, check whether a string S is admissible or not?
- Intersection point of two linked lists using stack.
- Finding spans.
- Finding spans with O(n) time complexity.
- Largest area under histogram.
- Largest area under histogram in O(n) time complexity.
- How to check whether a stack is growing up or down in a given machine?
- In a stack of integers, how to check whether the successive pair of numbers are consecutive or not? For stack of odd numbers, consider the top as a left-out pair.
- Recursively remove all adjacent duplicates in a string.
- Replace every element in an array of elements with nearest greater element on the right of that element.
- Q29 with O(n) time complexity.
- How to implement a stack with the following operations in O(1) time complexity?
- push
- pop
- find the middle element
- delete the middle element
Source: Data Structures Made Easy by Narasimha Karumanchi
Comments
Post a Comment