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. First In, First Out
B. Lowest Value, First Out
C. Highest Value, First Out
D. Last In, First Out

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

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

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 traversal pointer that always identifies the final node in the list
B. The middle pointer
C. The top pointer
D. The rear pointer

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

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

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

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

6 What does the push operation do?

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

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

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

8 What does the pop operation do?

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

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

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

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

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

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 * A B
D. * A B

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

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

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

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

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

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

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

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

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 rear
C. The middle
D. The front

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

Priority queues Easy
A. The element's color
B. The queue's memory address
C. The element's priority
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. Insertion is allowed only at the rear
D. Deletion is allowed only at the front

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. 7
B. 9
C. The stack is empty
D. 12

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.next = N, then top = N
B. Set top = N.next, then N = top
C. Set N.next = top, then top = N
D. Set N.next = null, then top.next = 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. Both pushes succeed
B. Both pushes cause underflow
C. The first succeeds; the second overflows
D. The first overflows; the second succeeds

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. 16, 8, 15, 4
B. 4, 8, 15, 16
C. 4, 15, 8, 16
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. S[top] = item; top = top + 1
B. S[top + 1] = item; top = top - 1
C. top = top - 1; S[top] = item
D. top = top + 1; S[top] = item

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 = 1
B. Returned 9; top = 2
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. 19
B. 23
C. 17
D. 41

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. 9
D. 7

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. Neither pointer
B. Only front
C. Only rear
D. Both pointers

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, 6, 1
B. 5, 6, 0, 1
C. 1, 0, 6, 5
D. 5, 4, 3, 2, 1

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

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

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

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

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. 3
C. 2
D. 7

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. 4, 9
C. 9, 4
D. 7, 9

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

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

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. Both * and +
C. Only +
D. Neither operator

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. P, R, Q
B. Q, P, R
C. R, Q, P
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 = 3
B. , top = 4
C. , top = 4
D. , top = 4

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 exactly moves
C. time and fewer than moves
D. time and fewer than 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 - 1
B. Check whether top == 1
C. Check whether top == 0
D. Check whether top == capacity

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. Move front to the deleted node's successor
B. Set only front to NULL
C. Set only rear to NULL
D. Set both front and rear to NULL

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 = 1, rear = 3, with two elements stored
B. front = 2, rear = 3, with one element stored
C. front = 2, rear = 4, with two elements stored
D. front = 0, rear = 4, with four 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 = 3, rear = 0
B. front = 4, rear = 0
C. front = 4, rear = 1
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. All remaining tokens are operators
D. At least two operands are available on the stack

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.