Skip to content
Official PYQ · 2012

GATE CS 2012 Q18 — Asymptotic Worst Case Time and Space Complexity

Explain with AI

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
View worked solution

Answer: C

By definition, the worst-case running time W(n)W(n) represents the maximum time taken by the algorithm over all possible inputs of size nn:

W(n)=max⁡∣I∣=nT(I)W(n) = \max_{|I| = n} T(I)

The average-case running time A(n)A(n) is the expected running time over all inputs of size nn, weighted by their probability of occurrence P(I)P(I):

A(n)=∑∣I∣=nP(I)⋅T(I)A(n) = \sum_{|I| = n} P(I) \cdot T(I)

Since the running time T(I)T(I) for any individual input II cannot exceed the worst-case running time W(n)W(n) (i.e., T(I)≤W(n)T(I) \le W(n)), we can write:

A(n)=∑∣I∣=nP(I)⋅T(I)≤∑∣I∣=nP(I)⋅W(n)A(n) = \sum_{|I| = n} P(I) \cdot T(I) \le \sum_{|I| = n} P(I) \cdot W(n)

Since ∑P(I)=1\sum P(I) = 1, this simplifies to:

A(n)≤W(n)A(n) \le W(n)

By the definition of Big-O notation, since A(n)≤1⋅W(n)A(n) \le 1 \cdot W(n) for all nn, it is always true that:

A(n)=O(W(n))A(n) = \text{O}(W(n))

Why other options are incorrect:

  • Option A (A(n)=Ω(W(n))A(n) = \Omega(W(n))) & Option B (A(n)=Θ(W(n))A(n) = \Theta(W(n))): These are not always true. For QuickSort, the average-case is O(nlog⁡n)O(n \log n) and the worst-case is O(n2)O(n^2). Here, A(n)A(n) grows strictly slower than W(n)W(n), so A(n)≠Ω(W(n))A(n) \neq \Omega(W(n)).
  • Option D (A(n)=o(W(n))A(n) = \text{o}(W(n))): This is not always true. For MergeSort, both the average-case and worst-case running times are Θ(nlog⁡n)\Theta(n \log n). Since they grow at the same rate, A(n)≠o(W(n))A(n) \neq \text{o}(W(n)).

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Asymptotic Worst Case Time and Space Complexity questions