GATE CS: Data Structures & Algorithms

5 published questions in this subject.

Tests with Data Structures & Algorithms questions

Questions

Q12023

What is the time complexity of searching in a balanced Binary Search Tree?

  1. A.O(1)
  2. B.O(log n)
  3. C.O(n)
  4. D.O(n log n)
Show answer

Answer: B. O(log n)

In a balanced BST, the height is O(log n), so search requires O(log n) comparisons.

Q22023

Which sorting algorithm has the best average-case time complexity?

  1. A.Bubble Sort O(n²)
  2. B.Merge Sort O(n log n)
  3. C.Insertion Sort O(n²)
  4. D.Selection Sort O(n²)
Show answer

Answer: B. Merge Sort O(n log n)

Merge Sort consistently achieves O(n log n) time complexity in all cases (best, average, worst).

Q32022

In a max-heap with n elements, what is the minimum number of comparisons needed to find the minimum element?

  1. A.O(1)
  2. B.O(log n)
  3. C.O(n/2)
  4. D.O(n)
Show answer

Answer: D. O(n)

In a max-heap, the minimum is always a leaf node. All leaves must be checked: O(n/2) ≈ O(n).

Q42022

Which data structure is used internally by a recursive function?

  1. A.Queue
  2. B.Array
  3. C.Stack
  4. D.Linked List
Show answer

Answer: C. Stack

Function calls use the call stack — each recursive call pushes a new frame, and returns pop frames.

Q52021

Which of the following is a stable sorting algorithm?

  1. A.Heap Sort
  2. B.Quick Sort
  3. C.Merge Sort
  4. D.Selection Sort
Show answer

Answer: C. Merge Sort

Merge Sort is stable — equal elements maintain their relative order. Heap Sort and Quick Sort are not stable.