wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Stack and Queue

Total questions: 25

Worksheet time: 14mins

Name
Class
Date
1.

Choose correct output for the following sequence of operations.

push(5)

push(8)

pop

push(2)

push(5)

pop

pop

pop

push(1)

pop

a)

8 5 2 5 1

b)

8 5 5 2 1

c)

8 2 5 5 1

d)

8 1 2 5 5

2.

Stack can be implemented using _________ and ________ ?

a)

Array and Binary Tree

b)

Linked List and Graph

c)

Array and Linked List

d)

Queue and Linked List

3.

When the function calls another function then the details of the previous function are stored in Stack?

a)

Yes

b)

No

4.

Consider an empty stack of an integers. Let the numbers 4,5,6,7,8 to be pushed on to this stack only in the order they appeared from left to right. Let P indicates PUSH and Q indicates POP operation. What sequence of operations should be performed on stack in order to get the output as 548.

a)

PPPXPPXX

b)

PPXPPPXX

c)

PPXXPPPX

d)

PXXPPXPX

5.

What is the postfix expression for the corresponding infix expression?

a+b*c+(d*e)

a)

abc*+de*+

b)

abc+*de*+

c)

a+bc*de+*

d)

abc*+(de)*+

6.

What is the postfix expression for the infix expression?

a-b-c

a)

abc--

b)

ab – c –

c)

– -abc

d)

-ab-c

7.

Which of the following statement is incorrect with respect to infix to postfix conversion algorithm?

a)

operand is always placed in the output

b)

operator is placed in the stack when the stack operator has lower precedence

c)

parenthesis are included in the output

d)

higher and equal priority operators follow the same condition

8.

What is the corresponding postfix expression for the given infix expression?

a+(b*c(d/e^f)*g)*h)

a)

ab*cdef/^*g-h+

b)

abcdef^/*g*h*+

c)

abcd*^ed/g*-h*+

d)

abc*de^fg/*-*h+

9.

What is the correct postfix expression for the following expression?

a+b*(c^d-e)^(f+g*h)-i

a)

abc^de-fg+*^*+i-

b)

abcde^-fg*+*^h*+i-

c)

abcd^e-fgh*+^*+i-

d)

ab^-dc*+ef^gh*+i-

10.

In linked list implementation of a queue, where does a new element be inserted?

a)

At the head of link list

b)

At the tail of the link list

c)

At the centre position in the link list

d)

None

11.

If the MAX_SIZE is the size of the array used in the implementation of circular queue, array index start with 0, front point to the first element in the queue, and rear point to the last element in the queue. Which of the following condition specify that circular queue is FULL?

a)

Front=rear= -1

b)

Front=(rear+1)%MAX_SIZE

c)

Rear=front+1

d)

Rear=(front+1)%MAX_SIZE

12.

A circular queue is implemented using an array of size 10. The array index starts with 0, front is 6, and rear is 9. The insertion of next element takes place at the array index.

a)

0

b)

7

c)

9

d)

10

13.

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

14.

What is the outcome of the prefix expression +, -, *, 3, 2, /, 8, 4, 1 ?

a)

12

b)

11

c)

5

d)

4

15.

If the elements '1', '2', '3' and '4' are inserted in a queue, what would be order for the removal?

If the elements '1', '2', '3' and '4' are inserted in a stack, what would be order for the removal?

a)

1234

4321

b)

4321

1234

c)

3241

4123

d)

None

16.

The time complexity of enqueue operation in Queue is __

a)

O(1)

b)

O(n)

c)

O(logn)

d)

O(nlogn)

17.

Consider the following code.

int fun() {  

    if(isEmpty())  

{  

       return -10;   

 }  

  else  

  {  

      int n;  

     n= q[front];  

     front++;  

      return n;   

  }  

    

}   

Which operation does the above code perform?

a)

Enqueue

b)

Dequeue

c)

Return the front element

d)

Both b and c

18.

What would be the output after performing the following operations in a Deque?

Insertfront(10);  

Insertfront(20);  

Insertrear(30);  

Insertrear(40);  

Deletefront();  

Insertfront(50);  

Deleterear();  

Display();  

a)

10, 20, 30

b)

50, 10, 30

c)

40, 20, 30

d)

None of the above

19.

Consider the implementation of the singly linked list having the head pointer only in the representation. Which of the following operations can be performed in O(1) time?

i) Deletion of the last node in the linked list

ii) Insertion at the front of the linked list

iii) Deletion of the first node in the linked list

iv) Insertion at the end of the linked list

a)

ii

b)

both ii and iii

c)

both i and iv

d)

both i and ii

20.

Find the output of the following prefix expression.

*+2-2 1/-4 2+-5 3 1

a)

2

b)

12

c)

10

d)

4

21.

If -*+abcd = 11, find a, b, c, d using evaluation of prefix algorithm.

a)

a=2, b=3, c=5, d=4

b)

a=1, b=2, c=5, d=4

c)

a=5, b=4, c=7,d=5

d)

a=1, b=2, c=3, d=4

22.

n the given C snippet, find the statement number that has error.

//C code to push an element into a stack

1. void push( struct stack *s, int x)

2. {

3. if(s->top==MAX-1)

4. {

5. printf(“stack overflow”);

6. }

7. else

8. {

9. s->items[++s->top]=x;

10. s++;

11. }

12. }

a)

1

b)

9

c)

10

d)

11

23.

The result of evaluating the postfix expression 5, 4, 6, +, , 4, 9, 3, /, +, is?

a)

600

b)

350

c)

650

d)

588

24.

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

25.

Consider the usual implementation of parentheses balancing program using stack. 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