Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz in Stack

Total questions: 40

Worksheet time: 50mins

Name
Class
Date
1.

A programmer uses a stack in a text editor to manage the Undo function. What principle makes this possible?

a)

The most recent change is removed first.

b)

The earliest change is restored first.

c)

All changes are restored simultaneously.

d)

The least frequent change is restored last.

2.

When a new element is pushed into a stack, what happens to the “Top” pointer?

a)

It moves to the first element of the stack.

b)

It shifts one position upward to point to the new element.

c)

It resets to the base address of the stack.

d)

It skips to the last memory address.

3.

A student compares a stack to a pile of books on a table. Which concept is being illustrated?

a)

Each book can be removed from any position.

b)

The last book placed can be removed first.

c)

All books are removed in the order they were stacked.

d)

The smallest book always stays at the bottom.

4.

Why is stack called a restricted data structure?

a)

It only allows one type of data.

b)

It allows operations only at one end of the list.

c)

It requires a linked list representation.

d)

It cannot perform deletion.

5.

What happens when an element is popped from an empty stack?

a)

The stack resets itself.

b)

A stack underflow condition occurs.

c)

The system automatically inserts a null value.

d)

A new memory block is created.

6.

If a stack follows the LIFO principle, which operation sequence will remove elements in reverse order of insertion?

a)

push(10), push(20), pop()

b)

push(10), pop(), push(20), pop()

c)

push(10), push(20), push(30), pop()

d)

pop(), push(10), push(20), pop()

7.

A developer chooses an array-based stack instead of a linked list implementation. What could be the reason?

a)

It uses dynamic memory allocation.

b)

It provides faster access when size is fixed.

c)

It automatically resizes based on input.

d)

It allows deletion from both ends.

8.

When does a stack overflow occur in an array-based stack?

a)

When the top pointer becomes -1.

b)

When the top pointer reaches the maximum index.

c)

When the array size is doubled.

d)

When the stack has only one element.

9.

A linked list-based stack rarely faces overflow errors. Why?

a)

It has a fixed number of nodes.

b)

It expands dynamically as memory allows.

c)

It limits insertion operations.

d)

It requires pre-declared capacity.

10.

Before executing a pop operation, what must be verified?

a)

If the stack is initialized properly.

b)

If the stack is empty to avoid underflow.

c)

If the top value is greater than zero.

d)

If the stack contains identical elements.

11.

A stack’s “Top” pointer is currently at index 3 in an array of size 5. After a push operation, what will its new index be?

a)

2

b)

3

c)

4

d)

5

12.

Which of the following best differentiates stack overflow from stack underflow?

a)

Overflow occurs on insertion into a full stack; underflow occurs on deletion from an empty stack.

b)

Overflow happens when removing too many elements; underflow happens when inserting too many.

c)

Overflow is caused by recursion; underflow by iteration.

d)

Overflow and underflow are identical conditions in opposite order.

13.

Which operation places a new element at the top of the stack?

a)

Peek

b)

Push

c)

Pop

d)

Display

14.

What will the peek() function return after executing the sequence below? Push(8), Push(12), Pop(), Push(15)

a)

8

b)

12

c)

15

d)

Null

15.

What should happen when the stack is full and push() is called again?

a)

The operation should overwrite the top element.

b)

The system should trigger a stack overflow error.

c)

The new data replaces the bottom element.

d)

The stack expands automatically.

16.

Which situation best illustrates the concept of pop() operation in real life?

a)

Placing a new book on top of a stack.

b)

Taking off the top bangle from a pile.

c)

Adding a car to a single-lane garage.

d)

Counting plates in a stack.

17.

If Push(5), Push(10), Push(15), Pop() are performed, what remains on the stack (from bottom to top)?

a)

15, 10, 5

b)

5, 10

c)

10, 15

d)

5, 10, 15

18.

Why must programmers check isEmpty() before calling pop()?

a)

To avoid retrieving the wrong element.

b)

To prevent an underflow condition.

c)

To ensure data order remains unchanged.

d)

To identify duplicate values.

19.

In an infix expression, operators are placed:

a)

Before their operands.

b)

Between their operands.

c)

After their operands.

d)

Independently of their operands.

20.

What is the postfix equivalent of (A + B) * C?

a)

A B + C *

b)

A + B * C

c)

C A B + *

d)

A B C * +

21.

Which of the following is the prefix form of A * (B + C)?

a)

A B C + *

b)

* + A B C

c)

+ * A B C

d)

* A + B C

22.

Why is stack preferred for expression evaluation?

a)

It stores operands and manages operator precedence effectively.

b)

It allows random access to operands.

c)

It stores operators in sorted order.

d)

It simplifies syntax checking by ignoring parentheses.

23.

What happens when two operators of equal precedence appear consecutively during conversion?

a)

The one on the left is processed first.

b)

The one on the right is processed first.

c)

Both are skipped.

d)

Evaluation stops temporarily.

24.

If the expression A + B * C - D is converted to postfix, what is the correct result?

a)

A B C * + D -

b)

A B C + D * -

c)

A B * C + D -

d)

A + B C D * -

25.

Which namespace allows access to the built-in Stack class in C#?

a)

System.Data

b)

System.Collections

c)

System.IO

d)

System.Stack

26.

What does the following C# code display?

a)

X

b)

Y

c)

Z

d)

Null

27.

What will be the final output?

a)

A B D

b)

D B A

c)

A C D

d)

C B A

28.

What are the two numbers printed?

a)

20 and 10

b)

10 and 20

c)

20 and 20

d)

10 and 10

29.

What is displayed on the screen?

a)

Z Y X

b)

W Y

c)

W X

d)

X W

30.

What is the final stack content?

a)

15 10 5

b)

20 10 5

c)

20 15 10

d)

10 5 20

31.

What is the output?

a)

A B C

b)

C B

c)

Stack Underflow occurs

d)

B A

32.

Assume a custom stack class with maximum size = 3. What is the output?

a)

False, True

b)

True, True

c)

True, False

d)

False, False

33.

What are the boolean values printed?

a)

True, False

b)

False, True

c)

False, False

d)

True, True

34.

What is the final output?

a)

300 200

b)

300 100

c)

100 300

d)

200 100

35.

What will be printed?

a)

M

b)

N

c)

O

d)

Error

36.

What is the output?

a)

Green

b)

Blue

c)

Yellow

d)

Red

37.

Evaluate the postfix expression: 2 3 4 * + 5 - What is the final result?

a)

9

b)

15

c)

11

d)

7

38.

Convert the infix expression A * (B + C) to postfix.

a)

A B C + *

b)

A + B C *

c)

A + B + C

d)

A B * C +

39.

Evaluate the postfix expression: 6 2 / 3 * 4 + 5 - What is the final result?

a)

8

b)

9

c)

11

d)

10

40.

What is printed on the screen?

a)

15

b)

10

c)

20

d)

5