IT 117: Intermediate Scripting
Answers to Class 24 Ungraded Quiz

  1. What do you call a function that calls itself?
    a recursive function
  2. What must a recursive algorithm have in order to work?
    a condition under which the recursion will stop
  3. What do call the situation where a function calls itself directly?
    direct recursion
  4. What do you call the situation where a function calls another function, which then calls the original function?
    indirect recursion
  5. Can you rewrite any recursive function using a loop instead of recursion?
  6. Which is more efficient, a recursive algorithm or a non-recursive algorithm that does the same thing?
    a non-recursive algorithm
  7. Write a recursive function that counts down from some number. In other words, this function prints it's argument, than all numbers down to 1.
    def count_down(num):
             if num > 1:
                 count_down(num - 1)
  8. Write a recursive function that calculates the factorial of a number.
    def factorial(num):
             if num == 1:
                 return 1
                 return factorial(num -1) * num