GATE | GATE-CS-2015 (Mock Test) | Question 10



Select the correct asymptotic complexity of an algorithm with runtime T(n, n) where

T(x, c) = Θ(x) for c <= 2,
T(c, y) = Θ(y) for c <= 2, and
T(x, y) = Θ(x+y) + T(x/2, y/2) 

(A) Θ(nLogn)
(B) Θ(n2)
(C) Θ(n)
(D) Θ(n2Logn)


Answer: (C)

Explanation: The recurrence is

T(x, y) = Θ(x+y) + T(x/2, y/2) 

It can be written as below.

T(x, y) = Θ(x+y) + Θ((x+y)/2) + Θ((x+y)/4) +  Θ((x+y)/8)  .....
T(x, y) = Θ((x+y) + (x+y)/2 + (x+y)/4 + (x+y)/8  ..... )

The above expression forms a geometric series with ratio as 2 and starting element as (x+y)/2

T(x, y) is upper bounded by Θ(x+y) as sum of infinite series is 2(x+y). It is lower bounded by (x+y)

Source: http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-006-introduction-to-algorithms-fall-2011/assignments/MIT6_006F11_ps1.pdf


Quiz of this Question



My Personal Notes arrow_drop_up