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++; O(n) O(n²) O(1) 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: O(log n) O(n²) O(1) 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: 21 16 11 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? O(n) O(log n) O(n²) 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: Memory only A lower bound on growth The exact running time in seconds 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? Quick sort Merge sort Counting sort 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: The pivot is the median The array is random The array has 2 elements 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? z y x 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: O(E log V) O(V²) O(V + E) 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++; O(log n) O(1) O(n log n) 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: Allow sorting Save memory Spread keys more uniformly 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: A heap A skewed tree with O(n) search time A complete tree 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? A C D 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: Ω(log n) Ω(n log n) Ω(n) Ω(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: [9, 7, 5, 3, 1] [7, 5, 3, 1, 9] [1, 9, 7, 5, 3] [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: Rotations Hashing Recursion only 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: O(log n) O(n log n) O(1) 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? Binary heap B+ tree Linked list 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 6 2 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)? 2 6 3 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? 5 7 9 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: Unique strings In a linked list Sorted 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: Linear probing Rehashing Separate chaining 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? 5 10 8 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? 40, 20, 10, 30, 60, 50 50, 30, 10, 60, 20, 40 10, 20, 30, 40, 50, 60 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