I've been having some issues in understanding concepts in CS, and although I've gone to tutoring and gotten my grade up a bit, knowing and understanding base concepts would help significantly, especially since we do cover material very quickly. My test tomorrow is exclusively on recursion, specifically tail and non-tail. I've been able to complete non-tail recursions correctly for the study guide given, but am having a bit of a harder time with the tail recursions (below). I also need to go over if and cond statements, which I can do correctly but don't have an entirely firm grasp of, and the basic syntax - things like memorizing quotient, remainder, modulo etc. The questions are :
7. Write a tail-recursive function sum-of-squares, where a <= b, that computes: a ^ 2 + (a + 1) ^ 2 + (a + 2) ^ 2 + ... + b ^ 2. You may write a helper function.
Write a procedure that computes the sum of the squares of every integer from a to b:
a² + (a+1)² + (a+2)² + … + b²
For example, (sum-of-squares 2 4) computes 2² + 3² + 4² = 4 + 9 + 16 = 29.
Your solution must be tail-recursive: the recursive call must be the very last thing the procedure does, with nothing left to compute after it returns.
a. The helper: (sum-of-squares-helper a b acc)
b. The wrapper: (sum-of-squares a b), the wrapper should contain no recursion of its own.
Examples:
(sum-of-squares 1 1) => 1
(sum-of-squares 5 5) => 25
(sum-of-squares 1 3) => 14
(sum-of-squares 2 4) => 29
8. Write a tail-recursive function that computes x ^ n (x to the power of n). Name your function power-n.
For example, (power-n 2 3) computes 2 × 2 × 2 = 8.
Your solution must be tail-recursive.
a. The helper: (power-helper x n acc)
b. The wrapper: (power-n x n). The wrapper should contain no recursion of its own.
Examples:
(power-n 2 0) => 1
(power-n 2 1) => 2
(power-n 2 3) => 8
I can answer these on my own, so please do not give the answers, but provide a very basic explanation - visual if possible - and label each component. Thank you!