GATE / CS ARCHIVE

GATE CSE 2003 / QUESTION 22

Binary search inside insertion sort

Algorithms · Searching, Sorting & Selection · Full GATE CSE 2003 paper

GATE 2003, Q22 1 mark · MCQ
Report issue

Searching, Sorting & Selection

Question 22, GATE 2003: Array insertion sort normally uses linear search to find where the next element belongs. If binary search replaces that search, what happens to worst-case total running time? A. It remains Θ(n²); B. It becomes Θ(n(log n)²); C. It becomes Θ(n log n); D. It becomes Θ(n).
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

1. During insertion into a sorted prefix of length i, search needs O(log i) comparisons but opening an array slot may move i elements. Summing these movements over all prefixes dominates the sum of logarithmic searches. Binary search improves comparisons, not the cost of physically maintaining the sorted array.

2. Binary search reduces comparisons needed to locate each insertion position, but array elements still must shift to make room. A reverse-sorted input needs 1+2+...+(n−1)=Θ(n²) moves. The worst-case runtime therefore remains Θ(n²), A, despite O(n log n) comparisons.

Original paper, page 3