UGC-NET Dec 2011 · Asymptotic Analysis & Recurrences

MCQ · 2 marks · Problem PROG-DIVC-0052

Which of the following is a bad example of recursion ?
  1. A
    Factorial
  2. B
    Fibonacci numbers
  3. C
    Tower of Hanai
  4. D
    Tree traversal

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

Show the worked solutionThe naive recursion \(F(n)=F(n-1)+F(n-2)\) recomputes the same subproblems again and again; the number of calls grows like \(\phi^n\approx1.618^n\), while a loop computes \(F(n)\) in \(O(n)\).(A) Factorial makes one call per level, \(O(n)\) — a fine use of recursion.(C) Tower of Hanoi needs \(2^n-1\) moves anyway; recursion is the natural solution.(D) Tree traversal follows the recursive structure of the tree, visiting each node once.So Fibonacci numbers are the bad example.Answer: B

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