wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Stack and Queue

Total questions: 30

Worksheet time: 3600secs

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.

Only top element can be accessed in stack

a)

TRUE

b)

FALSE

3.

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

4.

If the elements “A”, “B”, “C” and “D” are placed in a queue and are deleted one at a time, in what order will they be removed?

a)

ABCD

b)

DCBA

c)

DCAB

d)

ABDC

5.

If the elements “A”, “B”, “D” and “C” are placed in a stack and are deleted one at a time, in what order will they be removed?

a)

ABCD

b)

ABDC

c)

CDBA

d)

DCAB

6.

In linked list implementation of a queue, the important condition for a queue to be empty is?

a)

FRONT is null

b)

REAR is null

c)

LINK is empty

d)

None of the mentioned

7.
Are stacks FIFO or FILO?
a)
FILO
b)
FIFO
c)
LIFO
d)
LILO
8.

How many stacks are needed to implement a queue. Consider the situation where no other data structure like arrays, linked list is available to you.

a)

1

b)

2

c)

3

d)

4

9.

How many queues are needed to implement a stack. Consider the situation where no other data structure like arrays, linked list is available to you.

a)

1

b)

2

c)

3

d)

4

10.

Which of the following is true about linked list implementation of queue?

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

11.

Suppose a circular queue of capacity (n – 1) elements is implemented with an array of n elements. Assume that the insertion and deletion operation are carried out using REAR and FRONT as array index variables, respectively. Initially, REAR = FRONT = 0. The conditions to detect queue full and queue empty are

a)

Full: (REAR+1) mod n == FRONT, empty: REAR == FRONT

b)

Full: (REAR+1) mod n == FRONT, empty: (FRONT+1) mod n == REAR

c)

Full: REAR == FRONT, empty: (REAR+1) mod n == FRONT

d)

Full: (FRONT+1) mod n == REAR, empty: REAR == FRONT

12.

Consider the following operation along with Enqueue and Dequeue operations on queues, where k is a global parameter.

What is the worst case time complexity of a sequence of n MultiDequeue() operations on an initially empty queue?

a)

O(n)

b)

O(n+k)

c)

O(nk)

d)

O(n^2)

13.

Suppose implementation supports an instruction REVERSE, which reverses the order of elements on the stack, in addition to the PUSH and POP instructions. Which one of the following statements is TRUE with respect to this modified stack?

a)

A queue cannot be implemented using this stack.

b)

A queue can be implemented where ENQUEUE takes a single instruction and DEQUEUE takes a sequence of two instructions.

c)

A queue can be implemented where ENQUEUE takes a sequence of three instructions and DEQUEUE takes a single instruction.

d)

A queue can be implemented where both ENQUEUE and DEQUEUE take a single instruction each.

14.

Let Q denote a queue containing sixteen numbers and S be an empty stack. Head(Q) returns the element at the head of the queue Q without removing it from Q. Similarly Top(S) returns the element at the top of S without removing it from S. Consider the algorithm given below.


The maximum possible number of iterations of the while loop in the algorithm is

a)

16

b)

32

c)

64

d)

256

15.

Following is C like pseudo code of a function that takes a number as an argument, and uses a stack S to do processing.


What does the above function do in general?

a)

Prints binary representation of n in reverse order

b)

Prints binary representation of n

c)

Prints the value of Logn

d)

Prints the value of Logn in reverse order

16.

The following postfix expression with single digit operands is evaluated using a stack:

Note that ^ is the exponentiation operator. The top two elements of the stack after the first * is evaluated are:

a)

6,1

b)

5,7

c)

3,2

d)

1,5

17.

If the sequence of operations - push (1), push (2), pop, push (1), push (2), pop, pop, pop, push (2), pop are performed on a stack, the sequence of popped out values

a)

2,2,1,1,2

b)

2,2,1,2,2

c)

2,1,2,2,1

d)

2,1,2,2,2

18.

The five items: A, B, C, D, and E are pushed in a stack, one after other starting from A. The stack is popped four items and each element is inserted in a queue. The two elements are deleted from the queue and pushed back on the stack. Now one item is popped from the stack. The popped item is

a)

A

b)

B

c)

C

d)

D

e)

E

19.

Consider the following operations performed on a stack of size 5 : Push (a); Pop() ; Push(b); Push(c); Pop(); Push(d); Pop();Pop(); Push (e) Which of the following statements is correct?

a)

Underflow occurs

b)

Stack operations are performed smoothly

c)

Overflow occurs

d)

None of the above

20.

Which of the following is not an inherent application of stack?

a)

Implementation of recursion

b)

Evaluation of a postfix expression

c)

Job scheduling

d)

Reverse a string

21.

Which of them is an abstract data structure (ADT)?

a)

A) Stacks

b)

B) Queues

c)

Both A and C

d)

C) Functions

22.

Consider the usual algorithm for determining whether a sequence of parentheses is balanced.

Suppose that you run the algorithm on a sequence that contains 2 left parentheses and 3 right parentheses (in some order).

The maximum number of parentheses that appear on the stack AT ANY ONE TIME during the computation?

a)

1

b)

2

c)

3

d)

4 or more

23.

User perform following operations on stack of size 5 then -

push(1);

pop();

push(2);

push(3);

pop();

push(2);

pop();

pop();

push(4);

pop();

pop();

push(5);

a)

Overflow Occurs

b)

Stack Operations will be performed Smoothly

c)

Underflow Occurs

d)

None of these

24.

What is the value of the postfix expression 6 3 2 4 + – *

a)

1

b)

40

c)

74

d)

-18

25.

The following postfix expression with single digit operands is evaluated using a stack:

8 2 3 ^ / 2 3 * + 5 1 * -

a)

6,1

b)

5,7

c)

3,2

d)

1,5

26.

To evaluate an expression without any embedded function calls:

a)

One stack is enough

b)

Two stacks are needed

c)

As many stacks as the height of the expression tree are needed

d)

A Turing machine is needed in the general case

27.

What will be the postfix form of the above expression -

(A+B)∗(C∗D-E)∗F/G

a)

None of these

b)

A B + C D ∗ E − F G ∗ / ∗

c)

A B + C D E ∗ − F G / ∗ ∗

d)

A B + C D ∗ E − F G / ∗ ∗

28.

Which one of the following is an application of Stack Data Structure?

a)

Managing function calls

b)

The stock span problem

c)

Arithmetic expression evaluation

d)

All of the above

29.

List of data in which element can be inserted and removed at the same end is called as __________.

a)

array

b)

stack

c)

linked list

d)

queue

30.

Convert the infix exression

(A + B) * (C + D)

to Postfix.

a)

A B C * + D +

b)

A B + C D + *

c)

A B * C D * +

d)

A B + C + D +