UGC-NET Jan 2017 · Asymptotic Analysis & Recurrences

MCQ · 2 marks · Problem PROG-DIVC-0023

Which of the following is true for computation time in insertion, deletion and finding maximum and minimum element in a sorted array ?
  1. A
    Insertion – $0(1)$, Deletion – $0(1)$, Maximum – $0(1)$, Minimum – $0(1)$
  2. B
    Insertion – $0(1)$, Deletion – $0(1)$, Maximum – $0(n)$, Minimum – $0(n)$
  3. C
    Insertion – $0(n)$, Deletion – $0(n)$, Maximum – $0(1)$, Minimum – $0(1)$
  4. D
    Insertion –  $0(n)$, Deletion – $0(n)$, Maximum – $0(n)$, Minimum – $0(n)$

Solve it on GATE DA practice →More Searching & Sorting Algorithms problems

Show the worked solutionIn a sorted array the smallest element is at the first index and the largest at the last, so minimum and maximum are \(O(1)\). Insertion must shift every larger element one place right to keep the order: \(O(n)\) in the worst case. Deletion must shift every later element one place left to close the gap: \(O(n)\).\[\text{Insert }O(n),\ \text{Delete }O(n),\ \text{Max }O(1),\ \text{Min }O(1).\]Answer: C

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com