Question

Let W(n)W(n) and A(n)A(n) denote respectively, the worst case and average case running time of an algorithm executed on an input of size nn. Which of the following is ALWAYS TRUE?

Choose one option
Official answer and solution
Official answer
C
From
Official GATE 2012 answer key

Solution

Analyze the definitions of worst-case complexity W(n)W(n) and average-case complexity A(n)A(n).

  1. Let InI_n be the set of all valid inputs of size nn, and let t(x)t(x) denote the running time of the algorithm on input x∈Inx \in I_n.

  2. The worst-case running time is the maximum running time over all inputs of size nn:

W(n)=max⁡x∈Int(x)W(n) = \max_{x \in I_n} t(x)
  1. The average-case running time A(n)A(n) is the expected running time across all inputs distributed according to probability distribution P(x)P(x):
A(n)=∑x∈InP(x)⋅t(x)A(n) = \sum_{x \in I_n} P(x) \cdot t(x)
  1. Since t(x)≤W(n)t(x) \le W(n) for every input x∈Inx \in I_n, and ∑x∈InP(x)=1\sum_{x \in I_n} P(x) = 1, we have:
A(n)≤∑x∈InP(x)⋅W(n)=W(n)⋅∑x∈InP(x)=W(n)A(n) \le \sum_{x \in I_n} P(x) \cdot W(n) = W(n) \cdot \sum_{x \in I_n} P(x) = W(n)
  1. Since A(n)≤W(n)A(n) \le W(n) for all nn, by definition of asymptotic upper bound, A(n)=O(W(n))A(n) = O(W(n)) is always true.

  2. Examination of other options:

  • In QuickSort, A(n)=Θ(nlog⁡n)A(n) = \Theta(n \log n) while W(n)=Θ(n2)W(n) = \Theta(n^2). Here A(n)≠Ω(W(n))A(n) \ne \Omega(W(n)) and A(n)≠Θ(W(n))A(n) \ne \Theta(W(n)), ruling out (A) and (B).
  • In MergeSort, A(n)=Θ(nlog⁡n)A(n) = \Theta(n \log n) and W(n)=Θ(nlog⁡n)W(n) = \Theta(n \log n), so A(n)≠o(W(n))A(n) \ne o(W(n)), ruling out (D).
Final answer

C

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2012 Computer Science and Information Technology (CS)
Question
18 of 65, printed as CS Q.18
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.