0% found this document useful (0 votes)
11 views5 pages

Stack and Queues - DPP 01

stack and queues practice question

Uploaded by

rahulkuiry04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views5 pages

Stack and Queues - DPP 01

stack and queues practice question

Uploaded by

rahulkuiry04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

1

CSE/IT Batch-Hinglish
Data Structure & Programming
Stacks and Queues DPP-01

[NAT] stacks. If the space is to be used efficiently, the


1. Consider the following sequence of operations on an condition for “stack full” is-
empty stack: (a) (top1=MAXSIZE/2)and(top2=MAXSIZE/2+1)
(b) (top1=MAXSIZE/2)or(top2=MAXSIZE/2+1)
push (5); push (2); pop(); push(4); push(6); p=pop();
(c) top1 + top2 = MAXSIZE
q=pop(); r=pop();
(d) top1=top2-1
The value of p+q-r is-________.
[NAT]
[MCQ] 5. A stack is implemented using a singly linked list that
2. Which of the following includes the applications of uses node structure-
stack?
(a) Recursive function calls struct node
(b) HTML and XML Tag matching {
(c) Checking if an expression contains balanced
parantheses. int data;
(d) Finding the maximum element in a given struct node *next;
sequence. }

[NAT] node;
3. A stack is implemented using array. S represents the Let *head denote the address of the start node
pointer to the top element in the stack. Initially the respectively. Assume, the stack is not empty.
stack contains the elements: a(top), b. Assume Consider the following function that intends to delete
Push(S, i) push an element i into the stack at index S. the topmost element of the stack:
Whenever a Push operation will be performed, it will node * f(node *head)
returns S++ after the push operation. Pop() pops the
{
topmost element and returns the next top index. Top()
is a function that returns the topmost element of the node *p=head; ____________;
stack. Consider the following statements: free(p);
p=NULL;
P: Top(Pop((Pop(Pop((Push(Push(S, c), d)))))))= a
}
Q: Pop(Pop(Pop(Pop(Push(Pop(Push(S, c)), d))))) = a
The missing blank is-
Which of the following statements is/are INVALID? (a) while(p → next!=NULL) p=p→next;
(a) P only (b) Q only
(b) p=p → next;
(c) Both P and Q (d) Neither P nor Q
(c) head=head → next;
(d) None
[MCQ]
4. A single array A[1…MAXSIZE] is used to implement
two stacks. The two stacks grow from opposite ends of
the array. Variables top1 and top2 (topl< top 2) point
to the location of the topmost element in each of the
2

[MSQ] Q: isEmpty(Push(Pop(Pop(Push(Pop(Push(S, c)),


6. Which one of the following permutations cannot be d))))), e) =
obtained in the output string using a stack and FALSE
assuming that the input sequence is a, b, c, d, e in the Which of the following statements is/are VALID?
same order? (a) P only (b) Q only
(a) c d e a b (b) a e b c d (c) Both P and Q (d) Neither P nor Q
(c) c d e b a (d) e d c b a

[MCQ] [NAT]
7. A stack is implemented using array of size 4. S 8. Let S be a stack of size n≥1. Starting with the empty
represents the pointer to the top element in the
stack, suppose we push the first 5 natural numbers in
stack. Initially the stack contains the elements-
sequence, and then perform 5 pop operations.
a(top), b. Assume Push(S, i) push an element i into
Assume that Push and Pop operations take 3 seconds
the stack at index S. Whenever a Push operation
will be performed, it will returns S++ after the push each, and 1 seconds elapse between the end of one
operation. Pop() pops the topmost element and such stack operation and the start of the next
returns the next top index. isEmpty() returns TRUE operation. The average stack-life of an element of
if the stack is empty. isFull() returns TRUE if the this stack is __________.
stack is full. Consider the following statements:
P: isFull(Push(Pop(Push(Push(S, c), d))), e))=
TRUE
3

Answer Key
1. (5) 5. (c)
2. (a, b, c) 6. (a, b)
3. (c) 7. (c)
4. (d) 8. (17)
4

Hints and Solutions

1. (5) The missing statement include-


push (5); head=head->next
push (2);
pop(); //2 is popped 6. (a, b)
push(4); (a) is NOT possible
push(6); Push a;
p=pop(); //6 is popped Push b;
q=pop(); //4 is popped Push c;
r=pop(); //5 is popped Pop c;
Push d;
The final value of p+q-r = 6+4-5= 5
Pop d;
Push e;
2. (a, b, c) Pop e;
The application of stack: Pop a; (Not possible) top contains b.
Recursive Function Calls (b) is NOT possible.
HTML and XML Tag matching Push a;
Checking if an expression contains balanced Pop a;
parantheses. Push b;
Push c;
3. (c) Push d;
Stack already contains a(top), b. Push e;
top(pop((pop(pop((push(push(S, c), d))))))) Pop e;
It pushes c into the stack. It pushes d into the stack. Pop b;(Not possible) top contains d.
It pops d. It pops c.
It pops a. 7. (c)
Top contains b now. isFull(push(pop(push(push(S, c), d))), e))= TRUE
pop(pop(pop(pop(push(pop(push(S, c)), d))))) = a
Push c;
It pushes c and pops it.
Push d;
It pushes d and pops it.
Pop;
It pops a and then b.
Push e;
Last pop operation cannot be implemented as the
The stack is full (b, a, c, e(top)).
stack is already empty.
is Empty(push(pop(pop(push(pop(push(S, c)), d))))),
4. (d) e) = FALSE
If the stacks are growing from two ends, top2-top1=1. Push c;
Pop c;
Push d;
5. (c)
Pop d;
If a stack is implemented using linked list, push and Pop a;
pop occurs from one default location-head/start of the Push e;(Stack contains b, e(top))
linked list.
The stack is not empty.
5

8. (17) Stack Life time of 1=8*3+9*1=33


Stack Life time of 5=1 Average stack-life of an element =
Stack Life time of =2*3+3*1=9 (1+9+17+25+33)/5 = 17
Stack Life time of 3=4*3+5*1=17
Stack Life time of 2=6*3+7*1=25

Any issue with DPP, please report by clicking here:- https://forms.gle/t2SzQVvQcs638c4r5


For more questions, kindly visit the library section: Link for web: https://smart.link/sdfez8ejd80if

PW Mobile APP: https://smart.link/7wwosivoicgd4

You might also like