MCQs / Computer Science / NSCT: Data Structures & Algorithms

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

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.

101. Evaluate the postfix expression: 9 3 1 - /

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

Answer: C) 4

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

Discuss this question

102. After the FIRST pass of selection sort (ascending) on [3, 8, 2, 6, 4], the list is:

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

Answer: D) [2, 8, 3, 6, 4]

Explanation: Selection sort swaps the minimum into position 0. Lesson 3.6 · Data Structures & Algorithms

Discuss this question

103. The undo feature in a text editor is best implemented using a:

  1. Stack
  2. Hash table
  3. Queue
  4. Graph

Answer: A) Stack

Explanation: The latest action is undone first. Lesson 3.2 · Data Structures & Algorithms

Discuss this question

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

  1. O(n log n)
  2. O(n³)
  3. O(n)
  4. O(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

105. The worst-case time complexity of linear search on n items is:

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

Answer: C) O(n)

Explanation: It may need to check every item. Lesson 3.1 · Data Structures & Algorithms

Discuss this question

106. Which sort needs O(n) extra memory?

  1. Bubble sort
  2. Merge sort
  3. Selection sort
  4. Heap sort

Answer: B) Merge sort

Explanation: Merging requires a temporary array. Lesson 3.6 · Data Structures & Algorithms

Discuss this question

107. Average-case search time in a well-designed hash table is:

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

Answer: D) O(1)

Explanation: The hash function points directly to the slot. Lesson 3.5 · Data Structures & Algorithms

Discuss this question

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

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

Answer: D) O(n²)

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

Discuss this question

109. Storing answers to subproblems to avoid recomputation is the core idea of:

  1. Linear search
  2. Divide and conquer
  3. Greedy algorithms
  4. Dynamic programming

Answer: D) Dynamic programming

Explanation: Memoisation or tabulation. Lesson 3.6 · Data Structures & Algorithms

Discuss this question

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

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

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

Explanation: Post-order visits left, right, then root – the first key inserted (root) comes last. Lesson 3.3 · Data Structures & Algorithms

Discuss this question

111. Keys 50, 30, 70, 20, 40, 60, 80 are inserted in this order into an empty binary search tree. What is the post-order traversal?

  1. 80, 70, 60, 50, 40, 30, 20
  2. 20, 30, 40, 50, 60, 70, 80
  3. 50, 30, 20, 40, 70, 60, 80
  4. 20, 40, 30, 60, 80, 70, 50

Answer: D) 20, 40, 30, 60, 80, 70, 50

Explanation: Post-order visits left, right, then root – the first key inserted (root) comes last. Lesson 3.3 · Data Structures & Algorithms

Discuss this question

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

  1. 20
  2. 10
  3. 7
  4. 500

Answer: B) 10

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

Discuss this question

113. An autocomplete feature that suggests words by prefix is best implemented with a:

  1. Circular list
  2. Max-heap
  3. Trie
  4. Queue

Answer: C) Trie

Explanation: Each path from the root spells a prefix. Lesson 3.3 · Data Structures & Algorithms

Discuss this question

114. Which sorting algorithm is best for an almost-sorted list?

  1. Insertion sort
  2. Heap sort
  3. Quick sort with first-element pivot
  4. Selection sort

Answer: A) Insertion sort

Explanation: Insertion sort runs in nearly O(n) on almost-sorted data. Lesson 3.6 · Data Structures & Algorithms

Discuss this question

115. The naive recursive Fibonacci function fib(n) = fib(n−1) + fib(n−2) runs in:

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

Answer: B) O(2ⁿ)

Explanation: The call tree roughly doubles at each level. Lesson 3.1 · Data Structures & Algorithms

Discuss this question

116. What is the maximum number of comparisons binary search needs to find an item in a sorted array of 100 elements?

  1. 4
  2. 50
  3. 7
  4. 14

Answer: C) 7

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

Discuss this question

117. A queue is implemented with two stacks. The amortised cost of each operation is:

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

Answer: A) O(1)

Explanation: Each element moves between stacks at most once. Lesson 3.2 · Data Structures & Algorithms

Discuss this question

118. The maximum number of nodes in a binary tree of height 3 (root at height 0) is:

  1. 7
  2. 15
  3. 8
  4. 16

Answer: B) 15

Explanation: 2^(h+1) − 1 = 15. Lesson 3.3 · Data Structures & Algorithms

Discuss this question

119. A max-heap contains 10, 4, 7, 1, 9. After deleting the root once, which value becomes the new root?

  1. 10
  2. 4
  3. 1
  4. 9

Answer: D) 9

Explanation: Deleting the maximum leaves the second largest at the root. Lesson 3.3 · Data Structures & Algorithms

Discuss this question

120. A graph consists of:

  1. Vertices and edges
  2. Rows and columns
  3. Keys and values
  4. Nodes and pointers only

Answer: A) Vertices and edges

Explanation: G = (V, E). Lesson 3.4 · Data Structures & Algorithms

Discuss this question

121. Solving a Sudoku by trying a number and undoing it when it leads to a conflict is:

  1. Divide and conquer
  2. Backtracking
  3. Hashing
  4. Greedy

Answer: B) Backtracking

Explanation: Backtracking explores and retreats. Lesson 3.6 · Data Structures & Algorithms

Discuss this question

122. Shortest path in an unweighted graph is found with:

  1. Kruskal
  2. BFS
  3. DFS
  4. Heap sort

Answer: B) BFS

Explanation: BFS explores by distance in levels. Lesson 3.4 · Data Structures & Algorithms

Discuss this question

123. Starting with an empty stack, these operations are performed: push 5, push 8, pop, push 3, push 9, pop, push 1. What is on top of the stack?

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

Answer: D) 1

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

Discuss this question

124. Removing an element from an empty stack causes:

  1. Deadlock
  2. Underflow
  3. Segmentation of memory
  4. Overflow

Answer: B) Underflow

Explanation: Pop on an empty stack is underflow. Lesson 3.2 · Data Structures & Algorithms

Discuss this question

125. Which sorting algorithm repeatedly swaps adjacent elements that are out of order?

  1. Heap sort
  2. Bubble sort
  3. Selection sort
  4. Merge sort

Answer: B) Bubble sort

Explanation: Large values bubble to the end. Lesson 3.6 · Data Structures & Algorithms

Discuss this question

Previous Page 5 of 6 Next

Practise NSCT: Data Structures & Algorithms MCQs

More Computer Science chapters