UGC-NET Jun 2014 · Asymptotic Analysis & Recurrences

MCQ · 2 marks · Problem PROG-DIVC-0008

An algorithm is made up of $2$ modules $M_{1}$ and $M_{2}$ . If time complexity of modules $M_{1}$ and $M_{2}$ are $h(n)$ and $g(n)$ respectively, the time complexity of the algorithm is
  1. A
    $\min (h(n), g(n))$
  2. B
    $\max (h(n), g(n))$
  3. C
    $h(n) + g(n)$
  4. D
    $h(n) * g(n)$

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

Show the worked solution\[\boxed{O(h(n))+O(g(n))=O\big(\max(h(n),g(n))\big)}\]The modules run one after the other, so the total time is \(h(n)+g(n)\). Since\[\max(h,g)\le h+g\le 2\max(h,g),\]the sum has the same order as the larger term (rule of sums). The complexity is therefore governed by \(\max(h(n),g(n))\).(A) The minimum ignores the slower module — incorrect.(D) A product would describe nested execution, not sequential modules — incorrect.Answer: B

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