basic operations on stack push: insert element in a stack
TRANSCRIPT
![Page 1: Basic operations on stack push: Insert element in a stack](https://reader030.vdocuments.site/reader030/viewer/2022040620/624be1e6c81fc60cc224d089/html5/thumbnails/1.jpg)
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)
![Page 2: Basic operations on stack push: Insert element in a stack](https://reader030.vdocuments.site/reader030/viewer/2022040620/624be1e6c81fc60cc224d089/html5/thumbnails/2.jpg)
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
![Page 3: Basic operations on stack push: Insert element in a stack](https://reader030.vdocuments.site/reader030/viewer/2022040620/624be1e6c81fc60cc224d089/html5/thumbnails/3.jpg)
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?
![Page 4: Basic operations on stack push: Insert element in a stack](https://reader030.vdocuments.site/reader030/viewer/2022040620/624be1e6c81fc60cc224d089/html5/thumbnails/4.jpg)
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 /
![Page 5: Basic operations on stack push: Insert element in a stack](https://reader030.vdocuments.site/reader030/viewer/2022040620/624be1e6c81fc60cc224d089/html5/thumbnails/5.jpg)
The data structure required to check whether an expression contains
balanced parenthesis is?
a) Stack
b) Queue
c) Array
d) Tree
![Page 6: Basic operations on stack push: Insert element in a stack](https://reader030.vdocuments.site/reader030/viewer/2022040620/624be1e6c81fc60cc224d089/html5/thumbnails/6.jpg)
The result of evaluating the postfix expression 5, 4, 6, +, *, 4, 9, 3, /, +, * is?
a) 600
b) 350
c) 650
d) 588
![Page 7: Basic operations on stack push: Insert element in a stack](https://reader030.vdocuments.site/reader030/viewer/2022040620/624be1e6c81fc60cc224d089/html5/thumbnails/7.jpg)
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
![Page 8: Basic operations on stack push: Insert element in a stack](https://reader030.vdocuments.site/reader030/viewer/2022040620/624be1e6c81fc60cc224d089/html5/thumbnails/8.jpg)
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
![Page 9: Basic operations on stack push: Insert element in a stack](https://reader030.vdocuments.site/reader030/viewer/2022040620/624be1e6c81fc60cc224d089/html5/thumbnails/9.jpg)
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
![Page 10: Basic operations on stack push: Insert element in a stack](https://reader030.vdocuments.site/reader030/viewer/2022040620/624be1e6c81fc60cc224d089/html5/thumbnails/10.jpg)
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
![Page 11: Basic operations on stack push: Insert element in a stack](https://reader030.vdocuments.site/reader030/viewer/2022040620/624be1e6c81fc60cc224d089/html5/thumbnails/11.jpg)
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
![Page 12: Basic operations on stack push: Insert element in a stack](https://reader030.vdocuments.site/reader030/viewer/2022040620/624be1e6c81fc60cc224d089/html5/thumbnails/12.jpg)
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
![Page 13: Basic operations on stack push: Insert element in a stack](https://reader030.vdocuments.site/reader030/viewer/2022040620/624be1e6c81fc60cc224d089/html5/thumbnails/13.jpg)
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
![Page 14: Basic operations on stack push: Insert element in a stack](https://reader030.vdocuments.site/reader030/viewer/2022040620/624be1e6c81fc60cc224d089/html5/thumbnails/14.jpg)
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)
![Page 15: Basic operations on stack push: Insert element in a stack](https://reader030.vdocuments.site/reader030/viewer/2022040620/624be1e6c81fc60cc224d089/html5/thumbnails/15.jpg)
What is the other name for a postfix expression?
a) Normal polish Notation
b) Reverse polish Notation
c) Warsaw notation
d) Infix notation
![Page 16: Basic operations on stack push: Insert element in a stack](https://reader030.vdocuments.site/reader030/viewer/2022040620/624be1e6c81fc60cc224d089/html5/thumbnails/16.jpg)
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
![Page 17: Basic operations on stack push: Insert element in a stack](https://reader030.vdocuments.site/reader030/viewer/2022040620/624be1e6c81fc60cc224d089/html5/thumbnails/17.jpg)
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
![Page 18: Basic operations on stack push: Insert element in a stack](https://reader030.vdocuments.site/reader030/viewer/2022040620/624be1e6c81fc60cc224d089/html5/thumbnails/18.jpg)
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
![Page 19: Basic operations on stack push: Insert element in a stack](https://reader030.vdocuments.site/reader030/viewer/2022040620/624be1e6c81fc60cc224d089/html5/thumbnails/19.jpg)
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
![Page 20: Basic operations on stack push: Insert element in a stack](https://reader030.vdocuments.site/reader030/viewer/2022040620/624be1e6c81fc60cc224d089/html5/thumbnails/20.jpg)
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
![Page 21: Basic operations on stack push: Insert element in a stack](https://reader030.vdocuments.site/reader030/viewer/2022040620/624be1e6c81fc60cc224d089/html5/thumbnails/21.jpg)
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
![Page 22: Basic operations on stack push: Insert element in a stack](https://reader030.vdocuments.site/reader030/viewer/2022040620/624be1e6c81fc60cc224d089/html5/thumbnails/22.jpg)
what is the time complexity to sort elements of a stack
a) O(1)
b) O(n)
c) O(n^2)
d) None
![Page 23: Basic operations on stack push: Insert element in a stack](https://reader030.vdocuments.site/reader030/viewer/2022040620/624be1e6c81fc60cc224d089/html5/thumbnails/23.jpg)
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