wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Stacks and Queues Worksheet

Total questions: 43

Worksheet time: 22mins

Name
Class
Date
1.

Which property defines the primary difference between a Stack and a Queue?

a)

The time complexity of insertion

b)

The order of element removal (LIFO vs FIFO)

c)

The ability to store primitive data types

d)

The underlying memory allocation method

2.

In a Circular Queue implemented with an array of size n, what is the condition for the queue being full?

a)

rear == n - 1

b)

front == rear

c)

(rear + 1) % n == front

d)

front + rear == n

3.

What is the result of converting the infix expression (A + B) * C to postfix notation?

a)

* + A B C

b)

A B + C *

c)

A B C + *

d)

A B + * C

4.

Which of the following is an application of a Monotonic Stack?

a)

Finding the Next Greater Element

b)

Implementing a recursive function

c)

Scheduling tasks in an OS

d)

Level-order traversal of a tree

5.

If you implement a Queue using two Stacks, what is the amortized time complexity of the Dequeue operation?

a)

O(n)O(n)

b)

O(logn)O(\log n)

c)

O(n2)O(n^2)

d)

O(1)O(1)

6.

A 'Deque' (Double-Ended Queue) can be used to implement which of the following?

a)

Only a Stack

b)

Only a Queue

c)

Both a Stack and a Queue

d)

Only a Priority Queue

7.

When evaluating a postfix expression using a stack, what is the correct action when an operator is encountered?

a)

Push the operator onto the stack

b)

Pop two operands, apply the operator, and push the result back

c)

Pop one operand and push the operator

d)

Clear the stack and restart

8.

In the 'Two Stacks in one Array' implementation, where do the stacks typically start to maximize space efficiency?

a)

Both at index 0, growing in the same direction

b)

One at index 0, the other at index n/2

c)

At opposite ends of the array, growing towards the middle

d)

At the middle, growing towards the ends

9.

What happens if you attempt a 'Peek' operation on an empty Stack?

a)

Overflow error

b)

Underflow error or null return

c)

The program crashes automatically

d)

It returns the last deleted value

10.

Which scheduling algorithm in Operating Systems is a direct application of a Queue?

a)

First-Come, First-Served (FCFS)

b)

Shortest Job First

c)

Priority Scheduling

d)

Last-In, First-Out Scheduling

11.

In a linked list implementation of a Stack, why is it better to push at the head rather than the tail?

a)

It uses less memory

b)

It ensures O(1)O(1) time for both push and pop

c)

Linked lists cannot have a tail pointer

d)

It prevents stack overflow

12.

Which data structure is required to implement Depth First Search (DFS) on a graph non-recursively?

a)

Queue

b)

Stack

c)

Priority Queue

d)

Hash Map

13.

What is the primary disadvantage of a linear Queue implemented with a static array?

a)

Insertion is O(n)O(n)

b)

Space is wasted after several dequeue operations

c)

It cannot store integers

d)

Deletion is O(n)O(n)

14.

Which structure is best suited for implementing a 'Back' button in a web browser?

a)

Queue

b)

Circular Queue

c)

Stack

d)

Binary Search Tree

15.

How many stacks are typically needed to simulate a Priority Queue logic?

a)

One

b)

Two (with sorting during push or pop)

c)

Zero

d)

Four

16.

What is the time complexity to retrieve the 'Minimum' element in a specifically designed 'Min Stack'?

a)

O(n)O(n)

b)

O(logn)O(\log n)

c)

O(1)O(1)

d)

O(1)O(1) amortized

17.

In a Queue, the operation 'Front' or 'Peek' returns:

a)

The oldest element without removing it

b)

The newest element without removing it

c)

The oldest element and removes it

d)

The middle element

18.

What is the postfix form of A + B * C?

a)

A B + C *

b)

A B C * +

c)

+ A * B C

d)

A B * C +

19.

Which data structure is typically used to manage 'undo' operations in a text editor?

a)

Queue

b)

Hash Table

c)

Stack

d)

Graph

20.

What is the time complexity of reversing a Queue using an auxiliary Stack?

a)

O(n2)O(n^2)

b)

O(n)O(n)

c)

O(1)O(1)

d)

O(logn)O(\log n)

21.

A 'Priority Queue' can be used to efficiently implement which of the following?

a)

Dijkstra's Algorithm

b)

Expression Evaluation

c)

String Reversal

d)

Balanced Parentheses

22.

In a Deque, which operations are available that are NOT in a standard Queue?

a)

Peek and Enqueue

b)

IsFull and IsEmpty

c)

Insertion and deletion at both the front and rear

d)

Random access by index

23.

What is the max number of elements a stack can hold if array size is NN and the top pointer starts at 1-1 ?

a)

N1N - 1

b)

NN

c)

N+1N + 1

d)

Infinite

24.

Which of these is NOT a real-world example of a Queue?

a)

Cars at a toll booth

b)

People waiting for an elevator

c)

A stack of books on a desk

d)

Printer tasks in a spooler

25.

If you push 10, 20, 30 onto a stack and then pop twice, what is the next value returned by a 'Peek'?

a)

20

b)

30

c)

10

d)

None

26.

In the linked list implementation of a Queue, where should 'front' and 'rear' be?

a)

Front at the head, Rear at the tail

b)

Front at the tail, Rear at the head

c)

Both at the head

d)

Both at the tail

27.

What is the prefix form of the expression A+BA + B ?

a)

A B +

b)

+ A B

c)

A + B

d)

B A +

28.

Which of these is a valid implementation of a Stack using only one Queue?

a)

It is impossible with only one queue

b)

Enqueue the element and then rotate the queue n1n-1 times

c)

Simply use 'Dequeue' for 'Pop'

d)

Sort the queue after every insertion

29.

What is 'Stack Overflow'?

a)

An error when pushing onto a full stack

b)

An error when popping from an empty stack

c)

When a stack is converted to a queue

d)

When the stack memory is cleared

30.

Which data structure is most helpful in solving the 'Sliding Window Maximum' problem?

a)

Stack

b)

Deque

c)

Simple Queue

d)

Binary Search Tree

31.

How do you check if a Stack with top initialized to -1 is empty?

a)

top == 0

b)

top == N

c)

top == -1

d)

top == null

32.

In a Priority Queue, if two elements have the same priority, they are typically handled:

a)

By serving the most recent one first

b)

In FIFO order

c)

By discarding one

d)

By throwing an error

33.

Which of these is used to implement a 'Call Stack' in programming?

a)

Stack

b)

Queue

c)

Priority Queue

d)

Linked List

34.

Which data structure is most appropriate for a system handling print jobs?

a)

Stack

b)

Monotonic Stack

c)

Queue

d)

Binary Search Tree

35.

In an array-based implementation of a Stack where the top pointer is initialized to -1, which code correctly implements the push operation?

a)

stack[top++] = x;

b)

stack[++top] = x;

c)

stack[top] = x; top++;

d)

top = top + 1; x = stack[top];

36.

In a Circular Queue of capacity N, which line of code correctly updates the rear index during an enqueue operation?

a)

rear = rear + 1;

b)

rear = (rear % N) + 1;

c)

rear = (rear + 1) % N;

d)

rear = N % (rear + 1);

37.

Which code segment correctly checks if a Circular Queue is FULL?

a)

return (rear + 1) % size == front;

b)

return front == rear + 1;

c)

return rear == size - 1;

d)

return front == 0 && rear == size;

38.

What is the output of the following Python code? Python stack = [10, 20, 30] stack.append(40) stack.pop() stack.pop() print(stack[-1])

a)

10

b)

20

c)

30

d)

40

39.

Python from collections import deque q = deque([1, 2, 3]) q.append(4) q.popleft() q.append(q.popleft()) print(list(q)) What will be the state of the queue q after this execution?

a)

[3, 4, 2]

b)

[1, 2, 3, 4]

c)

[2, 3, 4]

d)

[4, 1, 2]

40.

To evaluate a Postfix expression, what logic completes the following snippet? Python # op2 is the first popped value, op1 is the second if token == '-': stack.append(__________)

a)

op2 - op1

b)

abs(op1 - op2)

c)

op1 - op2

d)

-(op1 + op2)

41.

When implementing a Stack using a Singly Linked List, why is it better to push/pop at the head?

a)

It allows O(1)O(1) time for both operations.

b)

It uses less memory than pushing at the tail.

c)

It prevents the stack from overflowing.

d)

Pushing at the tail requires a Doubly Linked List.

42.

In a "Queue using two Stacks" model, if stack2 (the dequeue stack) is empty, what is the required code logic?

a)

Return "Underflow".

b)

Move all elements from Stack1 to Stack2 and then pop from Stack2.

c)

Pop the bottom-most element from Stack1.

d)

Wait for more elements to be enqueued.

43.

What is the time complexity of retrieving the minimum element from a properly implemented MinStack?

a)

O(n)O(n)

b)

O(logn)O(\log n)

c)

O(1)O(1)

d)

O(n2)O(n^2)