GATE / CS ARCHIVE

GATE CSE 2015 SET 1 / QUESTION 60

GATE CSE 2015 Set 1 Q60

Data Structures · Arrays & Linked Lists · Full GATE CSE 2015 Set 1 paper

GATE 2015 Set 1, Q60 2 marks · MCQ
Report issue

Arrays & Linked Lists

Question 60, GATE 2015: An algorithm performs N inserts and sqrt(log N) each of find, delete, decrease-key on ordered keys. Delete and decrease-key receive pointers to their records. Which structure minimizes total asymptotic cost? A unsorted array; B min-heap; C sorted array; D sorted doubly linked list.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Let k=sqrt(log N). Unsorted insertion is constant amortized time, while each arbitrary-key find scans O(N), giving O(N+Nk)=O(Nsqrt(log N)). Even charging O(N) per deletion for compaction leaves the same order; decrease-key requires no ordering repair. A binary heap's online inserts can cost Θ(Nlog N) altogether and it does not speed arbitrary-key search. Sorted structures pay to locate or maintain insertion positions, potentially Θ(N²). Pointer access removes the search for a deletion target, not the need to preserve a chosen ordering.

Solution: Let k=sqrt(log N). With an unsorted array, N insertions take O(N) amortized and k arbitrary-key finds take O(Nk); pointer-directed deletion and decrease-key need at most O(Nk) total even if compaction work is charged. Total O(Nsqrt(log N)). A standard online binary min-heap costs O(Nlog N) for N worst-case insertions, and arbitrary-key finds are still linear. Maintaining sorted arrays or lists can cost Θ(N²) over the N insertions. Thus the unsorted array is best among the listed textbook online structures, A. This comparison is for the specified operation model, not an alternative offline bulk-sorting/heap-building algorithm.

Original paper, page 22 · Answer key