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

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

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

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 total number of arrays
B. The array capacity
C. The top element's index
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. Adds an element to the top
B. Removes an element from the top
C. Finds an element in the middle
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. Stack underflow
B. Queue overflow
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. Moves all elements into another stack
B. Copies the middle element
C. Adds the bottom element
D. Removes the top element

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

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

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

Arithmetic expressions Easy
A. Between the operands
B. After both operands
C. Inside a separate stack after the expression has been fully evaluated
D. Before 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 * A B
C. * A B
D. A * B

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

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

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 the highest-priority value to the lowest-priority value in every queue
B. From middle to rear
C. From rear to front
D. From front to rear

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

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

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

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

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

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

20 What is a defining feature of a deque?

Deques Easy
A. Elements are always removed according to numerical priority
B. Insertion and deletion are allowed at both ends
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. The stack is empty
B. 9
C. 12
D. 7

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 = null, then top.next = N
C. Set N.next = top, then top = 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. Both pushes cause underflow
B. Both pushes succeed
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. 4, 15, 8, 16
B. 4, 8, 15, 16
C. 16, 15, 8, 4
D. 16, 8, 15, 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 + 1] = item; top = top - 1
B. top = top + 1; S[top] = item
C. top = top - 1; S[top] = item
D. S[top] = 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 = 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. 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. 9
B. 13
C. 17
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 front must always remain at index 0
B. The unused indices are reserved for deletion
C. The queue can contain only three elements
D. The rear has reached the last array index

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 rear
C. Only front
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, 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 = (front + 1) % n
B. rear = (rear - 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. Only front becomes null
B. Only rear becomes null
C. Both front and rear become 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. 2
B. 7
C. 5
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. 9, 4
B. 4, 9
C. 7, 4
D. 7, 9

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

Evaluation of expressions Medium
A. 19
B. 13
C. 7
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. Both * and +
B. Only *
C. Neither operator
D. Only +

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. P, Q, R
C. Q, P, R
D. R, Q, P

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. Reverse the list, delete the first node, then reverse it again
B. Copy the second node into top, then delete the second node
C. Store top, move top to top.next, then delete the stored node
D. Traverse to the last node, delete it, then update its predecessor

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 == 1
B. Check whether top == 0
C. Check whether top == capacity - 1
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. Set both front and rear to NULL
B. Set only front to NULL
C. Set only rear 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 = 2, rear = 3, with one element stored
B. front = 1, rear = 3, with two elements stored
C. front = 0, rear = 4, with four elements stored
D. front = 2, rear = 4, 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 = 0
B. front = 4, rear = 1
C. front = 2, rear = 1
D. front = 3, rear = 0

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. At least two operands are available on the stack
B. The stack contains exactly one operand
C. The most recent token is always an operand
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.