Question: Consider the following Algorithms and answer the questions Algorithm 1 int fun1(int n) { if (n

Consider the following Algorithms and answer the questions

Algorithm 1
int fun1(int n)
{
if (n <= 1) return n;
return 2*fun1(n-1);
}
Algorithm 2
int fun2(int n)
{
if (n <= 1) return n;
return fun2(n-1) + fun2(n-1);
}
  • If n=8, what will be the final return value of both algorithms?
  • Write both algorithms using loops strategy.

Step by Step Solution

3.49 Rating (162 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

nt fun1int n if n 8 return n else return 2funn1 int main printfd fun2 return 0 output 32 This is the first time we are going to make an attempt to move backward in a program Loops make this backward m... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Document Format (2 attachments)

PDF file Icon

6360f8c30c158_235189.pdf

180 KBs PDF File

Word file Icon

6360f8c30c158_235189.docx

120 KBs Word File

Students Have Also Explored These Related Programming Questions!