MCQs / Computer Science / NSCT: Data Structures & Algorithms

NSCT: Data Structures & Algorithms MCQs — Computer Science (page 3)

150 multiple-choice questions on NSCT: Data Structures & Algorithms from Computer Science, each with the correct answer and, where available, a teacher's explanation. Read through them to revise the chapter, then practise the same questions one by one to test yourself.

51. What is the maximum number of comparisons binary search needs to find an item in a sorted array of 5,000 elements?

  1. 13
  2. 26
  3. 10
  4. 2500

Answer: A) 13

Explanation: ⌊log₂ 5000⌋ + 1 = 13. Lesson 3.6 · Data Structures & Algorithms

Discuss this question

52. Print jobs waiting for a printer are best managed with a:

  1. Heap
  2. Tree
  3. Queue
  4. Stack

Answer: C) Queue

Explanation: Jobs are served in arrival order. Lesson 3.2 · Data Structures & Algorithms

Discuss this question

53. Evaluate the postfix expression: 2 3 4 + 5 -

  1. 8
  2. 18
  3. 9
  4. 11

Answer: C) 9

Explanation: Push operands; on an operator pop two values and push the result. Answer 9. Lesson 3.2 · Data Structures & Algorithms

Discuss this question

54. A sorting algorithm is stable if:

  1. It uses O(1) memory
  2. It never crashes
  3. It works only on integers
  4. Equal keys keep their original relative order

Answer: D) Equal keys keep their original relative order

Explanation: Stability matters when sorting records by several keys. Lesson 3.6 · Data Structures & Algorithms

Discuss this question

55. Which traversal visits the root first?

  1. None of the depth-first traversals
  2. Post-order
  3. In-order
  4. Pre-order

Answer: D) Pre-order

Explanation: Pre-order: root, left, right. Lesson 3.3 · Data Structures & Algorithms

Discuss this question

56. A queue in which the last position connects back to the first is a:

  1. Circular queue
  2. Stack
  3. Priority queue
  4. Deque

Answer: A) Circular queue

Explanation: It reuses freed slots at the front. Lesson 3.2 · Data Structures & Algorithms

Discuss this question

57. Huffman coding (used in file compression) is a:

  1. Dynamic programming algorithm
  2. Greedy algorithm
  3. Sorting algorithm
  4. Search algorithm

Answer: B) Greedy algorithm

Explanation: It repeatedly merges the two least frequent symbols. Lesson 3.6 · Data Structures & Algorithms

Discuss this question

58. 3n² + 100n + 5000 is expressed in Big-O as:

  1. O(n)
  2. O(3n²)
  3. O(5000)
  4. O(n²)

Answer: D) O(n²)

Explanation: Keep the fastest-growing term and drop constants. Lesson 3.1 · Data Structures & Algorithms

Discuss this question

59. Using the hash function h(k) = k mod 11, what is the index of key 47?

  1. 3
  2. 8
  3. 2
  4. 4

Answer: A) 3

Explanation: 47 mod 11 = 3. Lesson 3.5 · Data Structures & Algorithms

Discuss this question

60. What is the time complexity of this code fragment? c for (i = 0; i < n; i++) for (j = 1; j < n; j = j 2) sum++;

  1. O(n log n)
  2. O(1)
  3. O(n³)
  4. O(n)

Answer: A) O(n log n)

Explanation: Count how often the innermost statement runs as n grows: O(n log n). Lesson 3.1 · Data Structures & Algorithms

Discuss this question

61. In-order traversal of a binary search tree gives the keys in:

  1. Level order
  2. Sorted (ascending) order
  3. Reverse order
  4. Random order

Answer: B) Sorted (ascending) order

Explanation: Left – root – right visits keys in increasing order. Lesson 3.3 · Data Structures & Algorithms

Discuss this question

62. After the FIRST pass of bubble sort (ascending) on [5, 1, 4, 2, 8], the list is:

  1. [1, 5, 4, 2, 8]
  2. [5, 1, 4, 2, 8]
  3. [1, 4, 2, 5, 8]
  4. [1, 2, 4, 5, 8]

Answer: C) [1, 4, 2, 5, 8]

Explanation: One pass swaps adjacent out-of-order pairs and moves the largest element to the end. Lesson 3.6 · Data Structures & Algorithms

Discuss this question

63. Evaluate the postfix expression: 6 2 / 3 +

  1. 12
  2. 8
  3. 6
  4. 5

Answer: C) 6

Explanation: Push operands; on an operator pop two values and push the result. Answer 6. Lesson 3.2 · Data Structures & Algorithms

Discuss this question

64. What is the complexity of: for i in 1..n: j = 1; while j < n: j = j 2

  1. O(n²)
  2. O(log n)
  3. O(n)
  4. O(n log n)

Answer: D) O(n log n)

Explanation: The inner loop runs log n times for each of n outer iterations. Lesson 3.1 · Data Structures & Algorithms

Discuss this question

65. Topological sorting is possible only for:

  1. Weighted graphs only
  2. Complete graphs
  3. Undirected graphs
  4. Directed acyclic graphs

Answer: D) Directed acyclic graphs

Explanation: A cycle would make an ordering impossible. Lesson 3.4 · Data Structures & Algorithms

Discuss this question

66. Keys 25, 15, 50, 10, 22, 35, 70 are inserted in this order into an empty binary search tree. What is the pre-order traversal?

  1. 70, 35, 22, 10, 50, 15, 25
  2. 10, 22, 15, 35, 70, 50, 25
  3. 10, 15, 22, 25, 35, 50, 70
  4. 25, 15, 10, 22, 50, 35, 70

Answer: D) 25, 15, 10, 22, 50, 35, 70

Explanation: Pre-order visits root, then left subtree, then right subtree. Lesson 3.3 · Data Structures & Algorithms

Discuss this question

67. What is the time complexity of this code fragment? c for (i = 0; i < n; i++) for (j = 0; j < n; j++) for (k = 0; k < n; k++) sum++;

  1. O(1)
  2. O(n)
  3. O(n³)
  4. O(n log n)

Answer: C) O(n³)

Explanation: Count how often the innermost statement runs as n grows: O(n³). Lesson 3.1 · Data Structures & Algorithms

Discuss this question

68. What is the time complexity of this code fragment? c for (i = 1; i < n; i = i 2) sum++;

  1. O(n³)
  2. O(log n)
  3. O(n log n)
  4. O(n²)

Answer: B) O(log n)

Explanation: Count how often the innermost statement runs as n grows: O(log n). Lesson 3.1 · Data Structures & Algorithms

Discuss this question

69. In a 0-indexed array heap, the children of the element at index 4 are at:

  1. 2 and 3
  2. 5 and 6
  3. 9 and 10
  4. 8 and 9

Answer: C) 9 and 10

Explanation: Children are at 2i + 1 and 2i + 2. Lesson 3.3 · Data Structures & Algorithms

Discuss this question

70. The values 3, 8, 2, 5, 6, 1 are inserted one by one into an empty min-heap. Which value is at the root?

  1. 8
  2. 3
  3. 2
  4. 1

Answer: D) 1

Explanation: The root of a min-heap is always the smallest element. Lesson 3.3 · Data Structures & Algorithms

Discuss this question

71. Starting with an empty stack, these operations are performed: push 10, push 20, pop, pop, push 30, push 40, push 50, pop. What is on top of the stack?

  1. 10
  2. 40
  3. 30
  4. 20

Answer: B) 40

Explanation: Stack after all operations (bottom→top): ['30', '40']. Lesson 3.2 · Data Structures & Algorithms

Discuss this question

72. Binary search (mid = (low + high) // 2) looks for 23 in [2, 5, 8, 12, 16, 23, 38, 56, 72, 91]. Which sequence of middle elements is compared?

  1. 16, 56, 23
  2. 2, 5, 8
  3. 16, 56, 23, 91
  4. 23, 56, 16

Answer: A) 16, 56, 23

Explanation: Each step compares with the middle element and keeps one half. Lesson 3.6 · Data Structures & Algorithms

Discuss this question

73. Binary search (mid = (low + high) // 2) looks for 3 in [1, 3, 5, 7, 9, 11, 13]. Which sequence of middle elements is compared?

  1. 7, 3, 13
  2. 3, 7
  3. 1, 3
  4. 7, 3

Answer: D) 7, 3

Explanation: Each step compares with the middle element and keeps one half. Lesson 3.6 · Data Structures & Algorithms

Discuss this question

74. What is the maximum number of comparisons binary search needs to find an item in a sorted array of 1,000,000 elements?

  1. 40
  2. 20
  3. 17
  4. 500000

Answer: B) 20

Explanation: ⌊log₂ 1000000⌋ + 1 = 20. Lesson 3.6 · Data Structures & Algorithms

Discuss this question

75. Using the hash function h(k) = k mod 17, what is the index of key 99?

  1. 14
  2. 3
  3. 15
  4. 5

Answer: A) 14

Explanation: 99 mod 17 = 14. Lesson 3.5 · Data Structures & Algorithms

Discuss this question

Previous Page 3 of 6 Next

Practise NSCT: Data Structures & Algorithms MCQs

More Computer Science chapters