Consider the algorithm for computing a\" where a and n are integers. If n- 0, th
ID: 3911744 • Letter: C
Question
Consider the algorithm for computing a" where a and n are integers. If n- 0, then return 1. If n is even then compute a" 2 recursively, and square it. Otherwise, compute a recursively and multiply the result by a 1. How many multiplications does this method use when n -9 2, How many multiplications does this mcthod use when n = 247 3, How many miultiplications does this method use when n 2k for some positive integer k? 4. How many multiplications does this method use when n 2*-1 for some positive integer k? 5. What exactly determines the number of multiplications for general n. Be as specific as possible.Explanation / Answer
Ans1- 3 multiply required
Ans2- 2 multiply required
Ans3- 2 multiply required
Ans4- k+1 multiply are required
Ans5- at any recursive step n passed is even or odd it all depends on it
Ans6-mycube(int n)
{
if(n>0)
return (n*n*n)+mycube(n-1);
else
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.