Post on 05-Apr-2022
STACK
Stack is a linear data structure, which is used to arrange elements in a list (array
list or link list) , using LIFO ( Last In First Out ) order.
Basic operations on stack
• push: Insert element in a stack
• pop: remove element from a stack
• push and pop only two operations are implemented in the top of the stack
with time complexity O(1)
Application of Stack Data structure
• Tree Traversal using DFS• Graph Traversal using DFS• To convert infix to postfix or prefix expression• Evaluating arithmetic operations• Keeping track of previous choices (as in backtracking)• Reverse data, string, file, list etc.• Implementation of Quick sort• Implementation of Merge sort• Convert a number into binary• Function recursion • Execution Sequence of Function in C program follows stack data structure• Undo sequence in a text editor
Questions
Write a C program to push and pop elements in a stack
Write a C program to convert a number into binary
Write a program sort the elements in a stack
Write a program to check the string “([]({()}[()]))” is balanced or not
Write a program to convert infix expression to postfix and prefix expression
Write a program to evaluate the postfix or prefix expression
Objective types
What is the data structures used to perform recursion?
How many stack is used to evaluate arithmetic expression?
What is the difference between ARRAY and STACK?
How get stack overflow in an array list and link list?
How to stack underflow in an array and link list?
The postfix form of the expression (A+ B)*(C*D- E)*F / G is?
a) AB+ CD*E - FG /**
b) AB + CD* E - F **G /
c) AB + CD* E - *F *G /
d) AB + CDE * - * F *G /
The data structure required to check whether an expression contains
balanced parenthesis is?
a) Stack
b) Queue
c) Array
d) Tree
The result of evaluating the postfix expression 5, 4, 6, +, *, 4, 9, 3, /, +, * is?
a) 600
b) 350
c) 650
d) 588
Consider the following operation performed on a stack of size 5.
Push(1);
Pop();
Push(2);
Push(3);
Pop();
Push(4);
Pop();
Pop();
Push(5);
After the completion of all operation, the no of element present on stack are
a) 1
b) 2
c) 3
d) 4
What is the minimum number of stacks of size n required to
implement a queue of size n?
a) One
b) Two
c) Three
d) Four
What is the maximum number of parentheses that will appear on stack at
any instance of time during the analysis of ( ( ) ( ( ) ) ( ( ) ) )?
a) 1
b) 2
c) 3
d) 4
When the user tries to delete the element from the empty stack then the
condition is said to be a ____
a) Underflow
b) Garbage collection
c) Overflow
d) None of the above
Which one of the following is not the application of the stack data
structure
a) String reversal
b) Recursion
c) backtracking
d) Asynchronous data transfer
Which one of the following node is considered the top of the stack if the
stack is implemented using the linked list?
a) First node
b) Second node
c) Last node
d) None of the above
Which of the following is true about linked list implementation of stack?
a) In push operation, if new nodes are inserted at the beginning of linked list, then in pop
operation, nodes must be removed from end.
b) In push operation, if new nodes are inserted at the end, then in pop operation, nodes
must be removed from the beginning.
c) Both of the above
d) None of the above
What is the time complexity of the program to reverse stack when
linked list is used for its implementation?
a) O(n)
b) O(n log n)
c) O(n2)
d) O(log n)
What is the other name for a postfix expression?
a) Normal polish Notation
b) Reverse polish Notation
c) Warsaw notation
d) Infix notation
While evaluating a postfix expression, when an operator is encountered,
what is the correct operation to be performed?
a) push it directly on to the stack
b) pop 2 operands, evaluate them and push the result on to the stack
c) pop the entire stack
d) ignore the operator
In infix to postfix conversion algorithm, the operators are associated
from?
a) right to left
b) left to right
c) centre to left
d) centre to right
The time complexity of converting a prefix notation to infix notation is
_________
a) O(n) where n is the length of the equation
b) O(n) where n is number of operands
c) O(1)
d) O(log n) where n is length of the equation
In stack, for accessing an nth element from the top, which
command needs to use?
a) S [ Top-n ]
b) S[ Top+n ]
c) S[ Top-n+1 ]
d) None of the above
When a lady wears and removes her bangles what type of data structure
she is using.
a) stack
b) queue
c) priority queue
d) hashing
Which of the following approach Recursive algorithms are worked on?
a) Bottom-up approach
b) Top-down approach
c) Hierarchical approach
d) All of the above
what is the time complexity to sort elements of a stack
a) O(1)
b) O(n)
c) O(n^2)
d) None
What type of data structure is used to create an internal space for
parameters and local variables.
a) stack
b) queue
c) array
d) tree