Unfolding a recursive definition with cases

A function pow(b,n)\text{pow}(b, n) is defined for a positive integer bb and every nonnegative integer nn by three clauses:

  • Base case: pow(b,0)=1\text{pow}(b, 0) = 1.
  • Even clause: if n≥2n \ge 2 is even, pow(b,n)=(pow(b,n/2))2\text{pow}(b, n) = \big(\text{pow}(b, n/2)\big)^2.
  • Odd clause: if nn is odd, pow(b,n)=b⋅pow(b,n−1)\text{pow}(b, n) = b \cdot \text{pow}(b, n - 1).

Evaluate the definition by unfolding it. Give each answer as an exact integer:

  1. the value of pow(3,6)\text{pow}(3, 6);
  2. the number of times the even or odd clause is applied in evaluating pow(b,6)\text{pow}(b, 6) before the base case is reached (do not count the base case itself);
  3. the same count for pow(b,13)\text{pow}(b, 13).
Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Recursive Definitions Questions: