Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part A: Write a program that recursively finds out how many digits there are in

ID: 3661065 • Letter: P

Question

Part A: Write a program that recursively finds out how many digits there are in an integer. Think carefully before trying to solve this one. Think about how you would go about doing this. Chalk out a solution on paper and make sure it works before trying to code it. Part B: Consider the code for the function sum below: // This is a function to sum all natural numbers upto n // Thus, for n = 5 we have sum = 1 + 2 + 3 + 4 + 5; public static int sum(int n) { if(n==0) // base case return 0; else // recursive case return sum(n-1) + n; } Write a tail-recursion version of this same function. Compare the two implementations of sum in terms of execution time, try at least 3 cases and include screenshots for each. What conclusions do you draw from that? Overall, what can you say when you compare tail-recursion with regular recursion. Deliverables: Use one single document for part A and part B. Include sourcecode as well as screenshots. Extra Credit: Is it possible to write a recursive version of MinSort? Is it possible to write a tail-recursive version of MinSort? Why?

Explanation / Answer

int recr(int n, int c) { if(n