Unit 3: Stacks and Queues - Practice Quiz

CSE205 — Data Structures And Algorithms 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 Which principle determines the order in which elements are removed from a stack?

Introduction to stacks Easy
A. Last In, First Out
B. Lowest Value, First Out
C. First In, First Out
D. Highest Value, First Out

2 Which everyday object best illustrates the behavior of a stack?

Introduction to stacks Easy
A. A pile of plates
B. A circular running track
C. A line of customers
D. A row of lockers

3 In a linked-list representation of a stack, which pointer usually identifies the element available for removal?

List representation of stacks Easy
A. The rear pointer
B. The top pointer
C. The traversal pointer that always identifies the final node in the list
D. The middle pointer

4 What does the top variable usually store in an array-based stack?

Array representation of stacks Easy
A. The first free value
B. The array capacity
C. The total number of arrays
D. The top element's index

5 In which direction are elements commonly visited when traversing a stack?

Stack traversal Easy
A. From top to bottom
B. From center to top
C. From rear to front
D. From the smallest element to the largest element regardless of position

6 What does the push operation do?

Push operation Easy
A. Adds an element to the top
B. Finds an element in the middle
C. Removes an element from the top
D. Rearranges every element into ascending order

7 What condition occurs when an element is pushed onto a full array-based stack?

Push operation Easy
A. Queue overflow
B. Automatic expansion in every array implementation without any additional logic
C. Stack overflow
D. Stack underflow

8 What does the pop operation do?

Pop operation Easy
A. Adds the bottom element
B. Copies the middle element
C. Removes the top element
D. Moves all elements into another stack

9 What condition occurs when pop is attempted on an empty stack?

Pop operation Easy
A. Stack overflow
B. Stack underflow
C. A complete reversal of every stored element
D. Queue underflow

10 In the infix expression $A + B$, where is the operator placed?

Arithmetic expressions Easy
A. Inside a separate stack after the expression has been fully evaluated
B. Before both operands
C. Between the operands
D. After both operands

11 Which expression is the prefix form of $A + B$?

Polish notation Easy
A. A + B
B. + A B
C. A B + +
D. A B +

12 What is the value of the postfix expression 5 2 +?

Evaluation of expressions Easy
A.
B.
C.
D.

13 Which postfix expression is equivalent to the infix expression A * B?

Transformation of expressions Easy
A. * A B
B. A * B
C. A B *
D. A B * A B

14 Which two indices are commonly maintained in an array-based queue?

Array representation of queues Easy
A. current, previous, and next for every array element
B. left and right
C. top and bottom
D. front and rear

15 In a linked-list queue, where is a new node normally inserted?

List representation of queues Easy
A. At the node containing the smallest stored value
B. At the middle
C. At the front
D. At the rear

16 In what order are elements normally visited during queue traversal?

Queue traversal Easy
A. From rear to front
B. From front to rear
C. From the highest-priority value to the lowest-priority value in every queue
D. From middle to rear

17 What is the standard name for inserting an element into a queue?

Queue insertion Easy
A. Enqueue
B. Traverse
C. Push
D. Pop

18 From which end is an element removed in a standard queue?

Queue deletion Easy
A. The end containing the largest element after the queue is sorted
B. The middle
C. The rear
D. The front

19 What mainly determines the removal order in a priority queue?

Priority queues Easy
A. The element's color
B. The element's priority
C. The queue's memory address
D. The alphabetical order of the variable names used by the program

20 What is a defining feature of a deque?

Deques Easy
A. Insertion and deletion are allowed at both ends
B. Elements are always removed according to numerical priority
C. Deletion is allowed only at the front
D. Insertion is allowed only at the rear

21 A sequence of operations on an empty stack is push(12), push(7), pop(), and push(9). Which element is now at the top?

Introduction to stacks Medium
A. 12
B. 7
C. The stack is empty
D. 9

22 In a singly linked-list stack whose top is stored at the head, which operation sequence correctly pushes a new node N?

List representation of stacks Medium
A. Set top = N.next, then N = top
B. Set N.next = top, then top = N
C. Set N.next = null, then top.next = N
D. Set top.next = N, then top = N

23 An array stack has capacity 8 and uses top = -1 when empty. If top = 6, what happens when two push operations are attempted?

Array representation of stacks Medium
A. The first succeeds; the second overflows
B. Both pushes cause underflow
C. The first overflows; the second succeeds
D. Both pushes succeed

24 An array stack contains [4, 8, 15, 16] from bottom to top. Which output is produced by a standard traversal from top downward?

Stack traversal Medium
A. 4, 15, 8, 16
B. 4, 8, 15, 16
C. 16, 8, 15, 4
D. 16, 15, 8, 4

25 For an array-based stack using top = -1 initially, which pseudocode correctly performs a push after checking for overflow?

Push operation Medium
A. top = top - 1; S[top] = item
B. S[top] = item; top = top + 1
C. top = top + 1; S[top] = item
D. S[top + 1] = item; top = top - 1

26 An array stack contains [3, 6, 9] with top = 2. After one valid pop, what are the returned value and new value of top?

Pop operation Medium
A. Returned 9; top = 2
B. Returned 9; top = 1
C. Returned 6; top = 1
D. Returned 3; top = 0

27 What is the value of the infix expression $8 + 3 \times 4 - 6 \div 2$ under standard precedence rules?

Arithmetic expressions Medium
A. 23
B. 41
C. 17
D. 19

28 Which prefix expression represents the infix expression $(A-B) \times (C+D)$?

Polish notation Medium
A. * - A B + C D
B. - * A B + C D
C. * A - B + C D
D. + - A B * C D

29 What is the result of evaluating the postfix expression 5 2 3 * + 4 -?

Evaluation of expressions Medium
A. 13
B. 17
C. 7
D. 9

30 What is the postfix form of the infix expression A + B * (C - D)?

Transformation of expressions Medium
A. A B + C D - *
B. A B C D - * +
C. A B * C D - +
D. A B C * D - +

31 A linear array queue of capacity 6 has front = 2 and rear = 5. Although indices 0 and 1 are unused, why can a normal insertion still fail?

Array representation of queues Medium
A. The rear has reached the last array index
B. The front must always remain at index 0
C. The unused indices are reserved for deletion
D. The queue can contain only three elements

32 A linked queue maintains front and rear pointers. When inserting into a nonempty queue, which pointer changes to reference the new node?

List representation of queues Medium
A. Both pointers
B. Neither pointer
C. Only rear
D. Only front

33 A circular queue of capacity 7 has front = 5 and rear = 1. Which index order visits all occupied positions from front to rear?

Queue traversal Medium
A. 5, 4, 3, 2, 1
B. 5, 6, 0, 1
C. 5, 6, 1
D. 1, 0, 6, 5

34 In a circular queue of capacity $n$, which update moves rear to the next position during insertion?

Queue insertion Medium
A. rear = rear + front
B. rear = (rear + 1) % n
C. rear = (rear - 1) % n
D. rear = (front + 1) % n

35 A linked queue contains exactly one node. Which pointer state should result after deleting that node?

Queue deletion Medium
A. Only front becomes null
B. Both front and rear become null
C. Only rear becomes null
D. Both pointers keep the deleted node

36 A min-priority queue contains items with priorities 7, 2, 5, and 3, where a smaller number means higher priority. Which priority is removed first?

Priority queues Medium
A. 5
B. 7
C. 2
D. 3

37 Starting with an empty deque, perform insertRear(4), insertFront(7), insertRear(9), and deleteFront(). What remains from front to rear?

Deques Medium
A. 7, 4
B. 9, 4
C. 4, 9
D. 7, 9

38 While evaluating the prefix expression - + 9 4 * 2 3, what final value is obtained?

Evaluation of expressions Medium
A. 7
B. 13
C. 9
D. 19

39 During infix-to-postfix conversion, the operator stack currently has + below *. When a - is read, which operators are popped before - is pushed?

Transformation of expressions Medium
A. Only *
B. Only +
C. Neither operator
D. Both * and +

40 A stable priority queue receives P, Q, and R in that order, all with the same priority. In what order should they be removed?

Priority queues Medium
A. R, Q, P
B. Q, P, R
C. P, R, Q
D. P, Q, R

41 A stack has capacity and uses top = -1 initially. The operations are: push(A), push(B), push(C), pop(), push(D), push(E), push(F). What is the final stack from bottom to top and the value of top?

Array representation of stacks Hard
A. , top = 4
B. , top = 4
C. , top = 4
D. , top = 3

42 In a singly linked-list implementation of a stack, the top pointer refers to the first node. Which operation sequence correctly performs pop() while preserving time complexity?

List representation of stacks Hard
A. Copy the second node into top, then delete the second node
B. Store top, move top to top.next, then delete the stored node
C. Traverse to the last node, delete it, then update its predecessor
D. Reverse the list, delete the first node, then reverse it again

43 A stack is stored in an array with top = 4, containing from bottom to top. A traversal must display elements from top to bottom without modifying the stack. Which output is correct?

Stack traversal Hard
A.
B.
C.
D.

44 A dynamically resizing array stack doubles its capacity whenever a push is attempted on a full stack. Starting with capacity , what is the amortized time complexity of pushes, and what is the total number of element moves caused by resizing?

Push operation Hard
A. time and exactly moves
B. time and fewer than moves
C. time and fewer than moves
D. time and exactly moves

45 An array stack uses one-based indexing and stores the number of elements in top. Which condition must be checked before pop() to prevent underflow?

Pop operation Hard
A. Check whether top == capacity
B. Check whether top == capacity - 1
C. Check whether top == 1
D. Check whether top == 0

46 Assuming exponentiation has higher precedence than multiplication and is right-associative, which value does the infix expression evaluate to?

Arithmetic expressions Hard
A.
B.
C.
D.

47 Which prefix expression is equivalent to the infix expression ?

Polish notation Hard
A.
B.
C.
D.

48 Evaluate the postfix expression 8 2 / 3 - 4 2 ^ + using integer operands and exact division.

Evaluation of expressions Hard
A.
B.
C.
D.

49 Using standard precedence and right-associative exponentiation, what is the postfix form of ?

Transformation of expressions Hard
A. A B + C D ^ * E F G ^ ^ -
B. A B C ^ D * + E F ^ G ^ -
C. A B C D ^ * + E F G ^ ^ -
D. A B C D ^ * E F G ^ ^ + -

50 A circular queue has capacity , with front = 4 and rear = 1. Here, front points to the first element and rear points to the next insertion position. How many elements are currently stored?

Array representation of queues Hard
A.
B.
C.
D.

51 In a linked-list queue with both front and rear pointers, what must occur when deleting the only node in the queue?

List representation of queues Hard
A. Set only rear to NULL
B. Set both front and rear to NULL
C. Set only front to NULL
D. Move front to the deleted node's successor

52 A circular queue of capacity has front = 5, rear = 2, where rear is the next insertion position. Which index sequence represents a complete traversal from front to rear without including the unused rear position?

Queue traversal Hard
A.
B.
C.
D.

53 A circular queue uses capacity , front as the first element, and rear as the next insertion position. Initially front = rear = 0. After inserting four elements and deleting two elements, which state is correct?

Queue insertion Hard
A. front = 0, rear = 4, with four elements stored
B. front = 2, rear = 3, with one element stored
C. front = 2, rear = 4, with two elements stored
D. front = 1, rear = 3, with two elements stored

54 A circular queue has capacity , front = 3, and rear = 1, with rear indicating the next insertion position. After one deletion, what are the new pointer values?

Queue deletion Hard
A. front = 4, rear = 1
B. front = 3, rear = 0
C. front = 4, rear = 0
D. front = 2, rear = 1

55 A priority queue removes the item with the smallest priority value. Items are inserted in this order: , , , . If equal priorities are served FIFO, what is the deletion order?

Priority queues Hard
A.
B.
C.
D.

56 A deque initially contains from front to rear. Apply insertFront(5), deleteRear(), insertRear(40), and deleteFront(). What is the final deque?

Deques Hard
A.
B.
C.
D.

57 A stack receives the input sequence exactly once. Which output sequence cannot be produced using only push and pop operations?

Introduction to stacks Hard
A.
B.
C.
D.

58 When evaluating a postfix expression containing binary operators, which invariant must hold immediately before applying an operator?

Evaluation of expressions Hard
A. The most recent token is always an operand
B. The stack contains exactly one operand
C. At least two operands are available on the stack
D. All remaining tokens are operators

59 What is the prefix form of the infix expression ?

Transformation of expressions Hard
A.
B.
C.
D.

60 A binary min-heap priority queue contains the array . After deleting the minimum element and restoring heap order, which array can represent the resulting heap?

Priority queues Hard
A.
B.
C.
D.