MCQs / Computer Science / NSCT: Data Structures & Algorithms

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

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.

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

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

Answer: C) O(1)

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

Discuss this question

27. Inserting into the middle of an array of n elements in the worst case takes:

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

Answer: D) O(n)

Explanation: Elements after the position must be shifted. Lesson 3.2 · Data Structures & Algorithms

Discuss this question

28. The postfix expression 5 3 2 + evaluates to:

  1. 21
  2. 16
  3. 11
  4. 13

Answer: C) 11

Explanation: 3 × 2 = 6, then 5 + 6 = 11. Lesson 3.2 · Data Structures & Algorithms

Discuss this question

29. What is the time complexity of accessing the i-th element of an array?

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

Answer: D) O(1)

Explanation: The address is computed directly from the index. Lesson 3.1 · Data Structures & Algorithms

Discuss this question

30. Big-Ω (Omega) notation describes:

  1. Memory only
  2. A lower bound on growth
  3. The exact running time in seconds
  4. An upper bound on growth

Answer: B) A lower bound on growth

Explanation: Ω gives a lower bound; O an upper bound; Θ a tight bound. Lesson 3.1 · Data Structures & Algorithms

Discuss this question

31. Which of these sorting algorithms is NOT comparison-based?

  1. Quick sort
  2. Merge sort
  3. Counting sort
  4. Heap sort

Answer: C) Counting sort

Explanation: Counting sort counts occurrences of keys. Lesson 3.6 · Data Structures & Algorithms

Discuss this question

32. Quick sort's worst case O(n²) occurs when:

  1. The pivot is the median
  2. The array is random
  3. The array has 2 elements
  4. The pivot is always the smallest or largest element

Answer: D) The pivot is always the smallest or largest element

Explanation: Partitions become extremely unbalanced. Lesson 3.6 · Data Structures & Algorithms

Discuss this question

33. Starting with an empty stack, these operations are performed: push x, push y, pop, push z, push w. What is on top of the stack?

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

Answer: D) w

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

Discuss this question

34. The time complexity of BFS or DFS with an adjacency list is:

  1. O(E log V)
  2. O(V²)
  3. O(V + E)
  4. O(V × E)

Answer: C) O(V + E)

Explanation: Each vertex and edge is processed once. Lesson 3.4 · Data Structures & Algorithms

Discuss this question

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

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

36. Hash table sizes are often chosen as prime numbers to:

  1. Allow sorting
  2. Save memory
  3. Spread keys more uniformly
  4. Avoid resizing

Answer: C) Spread keys more uniformly

Explanation: Primes reduce patterns in k mod m. Lesson 3.5 · Data Structures & Algorithms

Discuss this question

37. Inserting already-sorted keys 1, 2, 3, …, n into an ordinary BST produces:

  1. A heap
  2. A skewed tree with O(n) search time
  3. A complete tree
  4. A balanced tree

Answer: B) A skewed tree with O(n) search time

Explanation: Every new key goes to the right, forming a chain. Lesson 3.3 · Data Structures & Algorithms

Discuss this question

38. Starting with an empty stack, these operations are performed: push A, push B, push C, pop, pop, push D. What is on top of the stack?

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

Answer: C) D

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

Discuss this question

39. The lower bound for comparison-based sorting in the worst case is:

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

Answer: B) Ω(n log n)

Explanation: A decision tree with n! leaves has height ≥ log₂ n!. Lesson 3.6 · Data Structures & Algorithms

Discuss this question

40. After the FIRST pass of bubble sort (ascending) on [9, 7, 5, 3, 1], the list is:

  1. [9, 7, 5, 3, 1]
  2. [7, 5, 3, 1, 9]
  3. [1, 9, 7, 5, 3]
  4. [1, 3, 5, 7, 9]

Answer: B) [7, 5, 3, 1, 9]

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

41. AVL trees keep the tree balanced using:

  1. Rotations
  2. Hashing
  3. Recursion only
  4. Sorting

Answer: A) Rotations

Explanation: Rotations restore the height balance after insertions and deletions. Lesson 3.3 · Data Structures & Algorithms

Discuss this question

42. Searching in a balanced binary search tree with n nodes takes:

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

Answer: A) O(log n)

Explanation: Each comparison discards half the tree. Lesson 3.3 · Data Structures & Algorithms

Discuss this question

43. Which data structure is used for database indexes in most relational DBMSs?

  1. Binary heap
  2. B+ tree
  3. Linked list
  4. Stack

Answer: B) B+ tree

Explanation: B+ trees are shallow and disk-friendly. Lesson 3.3 · Data Structures & Algorithms

Discuss this question

44. A max-heap contains 3, 8, 2, 5, 6, 1. After deleting the root once, which value becomes the new root?

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

Answer: B) 6

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

Discuss this question

45. Keys 25, 15, 50, 10, 22, 35, 70 are inserted in this order into an empty BST. What is the height of the tree (root at height 0)?

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

Answer: A) 2

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

Discuss this question

46. Keys 31, 44, 18, 57 are inserted in this order into a hash table of size 13 using h(k) = k mod 13 and linear probing. At which index is 57 stored?

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

Answer: D) 8

Explanation: Final table: [None, None, None, None, None, 31, 44, 18, 57, None, None, None, None]. Lesson 3.5 · Data Structures & Algorithms

Discuss this question

47. Binary search requires the data to be:

  1. Unique strings
  2. In a linked list
  3. Sorted
  4. Unsorted

Answer: C) Sorted

Explanation: It discards half of a sorted range each step. Lesson 3.6 · Data Structures & Algorithms

Discuss this question

48. Storing colliding keys in a linked list at each slot is called:

  1. Linear probing
  2. Rehashing
  3. Separate chaining
  4. Double hashing

Answer: C) Separate chaining

Explanation: Each bucket holds a chain. Lesson 3.5 · Data Structures & Algorithms

Discuss this question

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

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

Answer: A) 5

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

Discuss this question

50. 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

Previous Page 2 of 6 Next

Practise NSCT: Data Structures & Algorithms MCQs

More Computer Science chapters