Consider the following definition of the gcd function:

var gcd = function (a,b) {
    if (b === 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
};

This question has two parts. First, is the gcd function above tail recursive? Second, how many recursive calls to gcd are made when we call it with the arguments (6,21) in this order, counting only the recursive calls, not the top-level call?

Yes; 3 recursive calls
  • Yes; 2 recursive calls
  • Yes; 4 recursive calls
  • Yes; 5 recursive calls
  • No; 2 recursive calls
  • No; 3 recursive calls
  • No; 4 recursive calls
  • No; 5 recursive calls

Review the definition of a tail call and a tail-recursive function.

Trace the call to gcd(6,21) with pencil and paper.