Stack Operations for DSA Beginners
Stack Operations for DSA Beginners
(DATA STRUCTURE)
STACK OPERATIONS
BEGINNERS
[Link]
sses?si=XkKXyJ_2a16NiK-K
MAARULA CLASSES
DSA
(STACK OPERATIONS)
DPP-#01
TARGET- NIMCET / [Link] By: Amit Katiyar (MCA-JNU)
Scan the QR & Download Our App Now.
ADDRESS: 117/466, O Block, Geeta Nagar, Sharda Nagar, NEAR: ANURAG HOSPITAL Kanpur, Uttar Pradesh 208025
website: [Link] 0512-3163515 9935985550 9554548576
MAARULA CLASSES
DSA
(STACK OPERATIONS)
DPP-#01
TARGET- NIMCET / [Link] By: Amit Katiyar (MCA-JNU)
Scan the QR & Download Our App Now.
17. The prefix form of A-B/ (C * D ^ E) is? 25. Consider the following operation performed on a
a) -/*^ACBDE b) -ABCD*^DE stack of size 5.
c) -A/B*C^DE d) -A/BC*^DE Push(1);
18. What is the result of the following operation? Pop();
Top (Push (S, X)) Push(2);
a) X b) X+S Push(3);
c) S d) XS Pop();
19. The prefix form of an infix expression (p + q) – (r * Push(4);
t) is? Pop();
a) + pq – *rt b) – +pqr * t Pop();
c) – +pq * rt d) – + * pqrt Push(5);
20. Which data structure is used for implementing After the completion of all operation, the number
recursion? of elements present in stack is?
a) Queue b) Stack (a) 1 (b) 2
c) Array d) List (c) 3 (d) 4
21. The result of evaluating the postfix expression 5, 4, 26. Which of the following is not an inherent
6, +, *, 4, 9, 3, /, +, * is? application of stack?
(a) 600 (b) 350 (a) Reversing a string
(c) 650 (d) 588 (b) Evaluation of postfix expression
22. Convert the following infix expressions into its (c) Implementation of recursion
equivalent postfix expressions. (d) Job scheduling
(A + B ⋀D)/(E – F)+G 27. The type of expression in which operator succeeds
(a) (A B D ⋀ + E F – / G +) its operands is?
(b) (A B D +⋀ E F – / G +) (a) Infix Expression
(c) (A B D ⋀ + E F/- G +) (b) Prefix Expression
(d) (A B D E F + ⋀ / – G +) (c) Postfix Expression
23. Convert the following Infix expression to Postfix (d) Both Prefix and Postfix Expressions
form using a stack. 28. Assume that the operators +,-, x are left associative
x + y * z + (p * q + r) * s, Follow usual precedence and ^ is right associative. The order of precedence
rule and assume that the expression is legal. (from highest to lowest) is ^, x, +, -. The postfix
(a) xyz*+pq*r+s*+ expression for the infix expression a + b x c – d ^ e
(b) xyz*+pq*r+s+* ^ f is?
(c) xyz+*pq*r+s*+ (a) a b c x + d e f ^ ^ –
(d) xyzp+**qr+s*+ (b) a b c x + d e ^ f ^ –
24. Which of the following statement(s) about stack (c) a b + c x d – e ^ f ^
data structure is/are NOT correct? (d) – + a x b c ^ ^ d e f
(a) Linked List are used for implementing Stacks 29. If the elements “A”, “B”, “C” and “D” are placed in a
(b) Top of the Stack always contain the new node stack and are deleted one at a time, what is the
(c) Stack is the FIFO data structure order of removal?
(d) Null link is present in the last node at the (a) ABCD (b) DCBA
bottom of the stack (c) DCAB (d) ABDC
ADDRESS: 117/466, O Block, Geeta Nagar, Sharda Nagar, NEAR: ANURAG HOSPITAL Kanpur, Uttar Pradesh 208025
website: [Link] 0512-3163515 9935985550 9554548576
MAARULA CLASSES
DSA
(STACK OPERATIONS)
DPP-#01
TARGET- NIMCET / [Link] By: Amit Katiyar (MCA-JNU)
Scan the QR & Download Our App Now.
class Stack
STACK USING LINKED LIST {
1. What is the best case time complexity of deleting a Node first;
node in a Singly Linked list? int size=0;
a) O (n) b) O (n2) Stack()
c) O (nlogn) d) O (1) {
2. Which of the following statements are not correct with first=null;
respect to Singly Linked List(SLL) and Doubly Linked }
List(DLL)? }
a) Complexity of Insertion and Deletion at known a)
position is O(n) in SLL and O(1) in DLL
public Object pop()
b) SLL uses lesser memory per node than DLL
{
c) DLL has more searching power than SLL
if(size == 0)
d) Number of node fields in SLL is more than DLL
[Link]("underflow");
3. Given below is the Node class to perform basic list
operations and a Stack class with a no arg constructor. else
Select from the options the appropriate pop() {
operation that can be included in the Stack class. Also Object o = [Link]();
‘first’ is the top-of-the-stack. first = [Link]();
class Node size--;
{ return o;
protected Node next; }
protected Object ele; }
Node() b)
{ public Object pop()
this(null,null); {
}
if(size == 0)
Node(Object e,Node n)
[Link]("underflow");
{
else
ele=e;
next=n; {
} Object o = [Link]();
public void setNext(Node n) first = [Link]().getNext();
{ size--;
next=n; return o;
} }
public void setEle(Object e) }
{ c)
ele=e; public Object pop()
} {
public Node getNext() if(size == 0)
{ [Link]("underflow");
return next;
else
}
{
public Object getEle()
first = [Link]();
{
return ele; Object o = [Link]();
} size--;
} return o;
}
}
ADDRESS: 117/466, O Block, Geeta Nagar, Sharda Nagar, NEAR: ANURAG HOSPITAL Kanpur, Uttar Pradesh 208025
website: [Link] 0512-3163515 9935985550 9554548576
MAARULA CLASSES
DSA
(STACK OPERATIONS)
DPP-#01
TARGET- NIMCET / [Link] By: Amit Katiyar (MCA-JNU)
Scan the QR & Download Our App Now.
ADDRESS: 117/466, O Block, Geeta Nagar, Sharda Nagar, NEAR: ANURAG HOSPITAL Kanpur, Uttar Pradesh 208025
website: [Link] 0512-3163515 9935985550 9554548576
MAARULA CLASSES
DSA
(STACK OPERATIONS)
DPP-#01
TARGET- NIMCET / [Link] By: Amit Katiyar (MCA-JNU)
Scan the QR & Download Our App Now.
ADDRESS: 117/466, O Block, Geeta Nagar, Sharda Nagar, NEAR: ANURAG HOSPITAL Kanpur, Uttar Pradesh 208025
website: [Link] 0512-3163515 9935985550 9554548576
MAARULA CLASSES
DSA
(STACK OPERATIONS)
DPP-#01
TARGET- NIMCET / [Link] By: Amit Katiyar (MCA-JNU)
Scan the QR & Download Our App Now.
ADDRESS: 117/466, O Block, Geeta Nagar, Sharda Nagar, NEAR: ANURAG HOSPITAL Kanpur, Uttar Pradesh 208025
website: [Link] 0512-3163515 9935985550 9554548576
MAARULA CLASSES
DSA
(STACK OPERATIONS)
DPP-#01
TARGET- NIMCET / [Link] By: Amit Katiyar (MCA-JNU)
Scan the QR & Download Our App Now.
ADDRESS: 117/466, O Block, Geeta Nagar, Sharda Nagar, NEAR: ANURAG HOSPITAL Kanpur, Uttar Pradesh 208025
website: [Link] 0512-3163515 9935985550 9554548576
MAARULA CLASSES
DSA
(STACK OPERATIONS)
DPP-#01
TARGET- NIMCET / [Link] By: Amit Katiyar (MCA-JNU)
Scan the QR & Download Our App Now.
ADDRESS: 117/466, O Block, Geeta Nagar, Sharda Nagar, NEAR: ANURAG HOSPITAL Kanpur, Uttar Pradesh 208025
website: [Link] 0512-3163515 9935985550 9554548576
MAARULA CLASSES
DSA
(STACK OPERATIONS)
DPP-#01
TARGET- NIMCET / [Link] By: Amit Katiyar (MCA-JNU)
Scan the QR & Download Our App Now.
ADDRESS: 117/466, O Block, Geeta Nagar, Sharda Nagar, NEAR: ANURAG HOSPITAL Kanpur, Uttar Pradesh 208025
website: [Link] 0512-3163515 9935985550 9554548576
MAARULA CLASSES
DSA
(STACK OPERATIONS)
DPP-#01
TARGET- NIMCET / [Link] By: Amit Katiyar (MCA-JNU)
Scan the QR & Download Our App Now.
while(count>0) d)
[Link]([Link]()); public int pop()
res = [Link](); {
} int res=-999,count=0;
return res; if([Link]()>0)
} {
b)
count = [Link]();
public int pop()
while(count>1)
{
[Link]([Link]());
int res=-999,count=0;
res = [Link]();
if([Link]()>0)
{ }
count = [Link](); if([Link]()>0)
while(count>1) {
[Link]([Link]()); count = [Link]();
res = [Link](); while(count>1)
} [Link]([Link]());
if([Link]()>0) res = [Link]();
{ }
count = [Link](); return res;
while(count>1) }
[Link]([Link]()); 7. What is the functionality of the following piece of
res = [Link]();
code?
}
public void fun(int x)
return res;
{
}
[Link](x);
c)
public int pop() }
{ a) Perform push() with push as the costlier
int res=-999,count=0; operation
if([Link]()>0) b) Perform push() with pop as the costlier
{ operation
count = [Link](); c) Perform pop() with push as the costlier
while(count>1) operation
[Link]([Link]()); d) Perform pop() with pop as the costlier
res = [Link](); operation
}
if([Link]()>0)
{
count = [Link]();
while(count>1)
[Link]([Link]());
res = [Link]();
}
return res;
}
ADDRESS: 117/466, O Block, Geeta Nagar, Sharda Nagar, NEAR: ANURAG HOSPITAL Kanpur, Uttar Pradesh 208025
website: [Link] 0512-3163515 9935985550 9554548576
MAARULA CLASSES
DSA
(STACK OPERATIONS)
DPP-#01
TARGET- NIMCET / [Link] By: Amit Katiyar (MCA-JNU)
Scan the QR & Download Our App Now.
ANSWER KEY
STACK OPERATIONS
1. 2. 3. 4. 5.
b d a a d
6. 7. 8. 9. 10.
d c b d d
11. 12. 13. 14. 15.
c a b d b
16. 17. 18. 19. 20.
d c a c b
21. 22. 23. 24. 25.
b a a c a
26. 27. 28. 29.
d c a b
STACK USING LINKED LIST
1. 2. 3. 4. 5.
d d a c b
6. 7. 8. 9. 10.
b a d d c
STACK USING ARRAY
1. 2. 3. 4. 5.
a c c d a
6. 7. 8. 9. 10.
b c d a a
STACK USING QUEUES
1. 2. 3. 4. 5.
b a b c b
6. 7.
c b
ADDRESS: 117/466, O Block, Geeta Nagar, Sharda Nagar, NEAR: ANURAG HOSPITAL Kanpur, Uttar Pradesh 208025
website: [Link] 0512-3163515 9935985550 9554548576