Exercises for Chapter #9 of A Common-Sense Guide To Data Structures and Algorithms
Get The Book!You can technically use recursion to replace any loop. Write a function that prints to the terminal "HELLO" 10 times - but don’t use a loop! Use a recursive function instead.
Write a recursive function that prints out all even numbers from 2 until 100.
Fibonacci numbers are numbers that follow this pattern: 1, 1, 2, 3, 5, 8, 13, 21, 34, ... that is, each number is the sum of the two immediate numbers that precede it. Write a recursive function that prints out the list of fibonacci numbers up to 987.
Write a recursive function that accepts an array of numbers and returns the sum.
Write a recursive function that reverses a string.
Write a recursive function that reverses a string.
Write a recursive function that accepts two numbers (a numerator and denominator), and returns the remainder if you divide the numerator by the denominator. The catch: Do not use the modulo operator!
Write a recursive binary search function.
Write a recursive function that accepts two numbers and calculates one by the power of the other. For example, if the numbers were 2 and 5, it would calculate 25. Do not use any built-in power operations provided by your computer language.
Write a recursive function that returns all anagrams of a string (even if the anagrams aren’t words themselves). For example, the anagrams of cat are cat, cta, act, atc, tac, tca.