MCQs / Computer Science / NSCT: Data Structures & Algorithms

NSCT: Data Structures & Algorithms MCQs — Computer Science

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.

1. Increasing the table size and reinserting all keys when the load factor is high is called:

  1. Hash collision
  2. Rehashing
  3. Chaining
  4. Probing

Answer: B) Rehashing

Explanation: It keeps operations near O(1). Lesson 3.5 · Data Structures & Algorithms

Discuss this question

2. The postfix form of the infix expression A + B C is:

  1. A B + C
  2. + A B C
  3. A B C +
  4. A B C +

Answer: D) A B C +

Explanation: Multiplication has higher precedence. Lesson 3.2 · Data Structures & Algorithms

Discuss this question

3. Which traversal visits the root last?

  1. In-order
  2. Level-order
  3. Post-order
  4. Pre-order

Answer: C) Post-order

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

Discuss this question

4. All-pairs shortest paths in a small dense graph can be found with:

  1. BFS from one vertex
  2. Floyd-Warshall
  3. Merge sort
  4. Kruskal

Answer: B) Floyd-Warshall

Explanation: It uses dynamic programming in O(V³). Lesson 3.4 · Data Structures & Algorithms

Discuss this question

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

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

Answer: D) [3, 2, 6, 4, 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

6. Breadth-first search uses which data structure?

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

Answer: C) Queue

Explanation: Nodes are processed in the order they were discovered. Lesson 3.2 · Data Structures & Algorithms

Discuss this question

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

  1. 10, 30, 20, 50, 60, 40
  2. 10, 20, 30, 40, 50, 60
  3. 40, 20, 10, 30, 60, 50
  4. 60, 50, 40, 30, 20, 10

Answer: A) 10, 30, 20, 50, 60, 40

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

Discuss this question

8. Function calls and recursion are managed by the:

  1. Ready queue
  2. Call stack
  3. Hash map
  4. Heap tree

Answer: B) Call stack

Explanation: Each call pushes a frame; returning pops it. Lesson 3.2 · Data Structures & Algorithms

Discuss this question

9. Keys 5, 28, 19, 15, 20 are inserted in this order into a hash table of size 9 using h(k) = k mod 9 and linear probing. At which index is 20 stored?

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

Answer: A) 3

Explanation: Final table: [None, 28, 19, 20, None, 5, 15, None, None]. Lesson 3.5 · Data Structures & Algorithms

Discuss this question

10. A double-ended queue (deque) allows insertion and deletion:

  1. At both ends
  2. Only at the rear
  3. Only at the front
  4. Only in the middle

Answer: A) At both ends

Explanation: Deque = double-ended queue. Lesson 3.2 · Data Structures & Algorithms

Discuss this question

11. Which Python and Java structures are implemented as hash tables?

  1. dict and HashMap
  2. deque and Stack
  3. list and ArrayList
  4. tuple and Array

Answer: A) dict and HashMap

Explanation: They give average O(1) lookup by key. Lesson 3.5 · Data Structures & Algorithms

Discuss this question

12. Keys 50, 30, 70, 20, 40, 60, 80 are inserted in this order into an empty BST. What is the height of the tree (root at height 0)?

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

Answer: C) 2

Explanation: The longest root-to-leaf path has 2 edges. Lesson 3.3 · Data Structures & Algorithms

Discuss this question

13. The 0/1 knapsack problem is efficiently solved using:

  1. Dynamic programming
  2. BFS
  3. Greedy choice by value only
  4. Binary search

Answer: A) Dynamic programming

Explanation: Greedy fails for 0/1 knapsack; DP gives the optimum. Lesson 3.6 · Data Structures & Algorithms

Discuss this question

14. Inserting an element at the beginning of a singly linked list takes:

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

Answer: A) O(1)

Explanation: Only the head pointer changes. Lesson 3.2 · Data Structures & Algorithms

Discuss this question

15. Course prerequisites (take DSA before AI) can be ordered using:

  1. Topological sort
  2. Bubble sort
  3. Hashing
  4. Binary search

Answer: A) Topological sort

Explanation: It orders tasks respecting dependencies. Lesson 3.4 · Data Structures & Algorithms

Discuss this question

16. Dijkstra's and Kruskal's algorithms are examples of:

  1. Greedy algorithms
  2. Backtracking
  3. Brute force
  4. Dynamic programming

Answer: A) Greedy algorithms

Explanation: They choose the best local option at each step. Lesson 3.6 · Data Structures & Algorithms

Discuss this question

17. Accessing the k-th element of a singly linked list takes:

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

Answer: B) O(k)

Explanation: You must follow k links from the head. Lesson 3.2 · Data Structures & Algorithms

Discuss this question

18. Starting with an empty queue, these operations are performed: enqueue 5, enqueue 8, dequeue, enqueue 3, enqueue 9, dequeue, enqueue 1. Which element is at the front?

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

Answer: C) 3

Explanation: Queue after all operations (front→rear): ['3', '9', '1']. Lesson 3.2 · Data Structures & Algorithms

Discuss this question

19. Merge sort has worst-case time complexity:

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

Answer: D) O(n log n)

Explanation: It always splits evenly and merges in linear time. Lesson 3.6 · Data Structures & Algorithms

Discuss this question

20. Which complexity grows the slowest for large n?

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

Answer: C) O(log n)

Explanation: log n grows slower than any power of n. Lesson 3.1 · Data Structures & Algorithms

Discuss this question

21. Starting with an empty queue, these operations are performed: enqueue 10, enqueue 20, dequeue, dequeue, enqueue 30, enqueue 40, enqueue 50, dequeue. Which element is at the front?

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

Answer: B) 40

Explanation: Queue after all operations (front→rear): ['40', '50']. Lesson 3.2 · Data Structures & Algorithms

Discuss this question

22. Starting with an empty queue, these operations are performed: enqueue x, enqueue y, dequeue, enqueue z, enqueue w. Which element is at the front?

  1. x
  2. y
  3. w
  4. z

Answer: B) y

Explanation: Queue after all operations (front→rear): ['y', 'z', 'w']. Lesson 3.2 · Data Structures & Algorithms

Discuss this question

23. Dijkstra's algorithm fails when the graph has:

  1. More than 100 vertices
  2. Undirected edges
  3. Negative edge weights
  4. Cycles

Answer: C) Negative edge weights

Explanation: Its greedy choice assumes edges cannot reduce a finalised distance. Lesson 3.4 · Data Structures & Algorithms

Discuss this question

24. The values 10, 4, 7, 1, 9 are inserted one by one into an empty min-heap. Which value is at the root?

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

Answer: A) 1

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

Discuss this question

25. Keys 40, 20, 60, 10, 30, 50 are inserted in this order into an empty binary search tree. What is the pre-order traversal?

  1. 40, 20, 10, 30, 60, 50
  2. 50, 30, 10, 60, 20, 40
  3. 10, 20, 30, 40, 50, 60
  4. 10, 30, 20, 50, 60, 40

Answer: A) 40, 20, 10, 30, 60, 50

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

Discuss this question

Page 1 of 6 Next

Practise NSCT: Data Structures & Algorithms MCQs

More Computer Science chapters