Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Let T ( n ) denote the number of times that the recursive function DoSomething ( n ) prints ` ` banana . int

Let T(n) denote the number of times that the recursive function DoSomething(n) prints ``banana."
int DoSomething(int n)
{
for (int i=1; i <= n; i=i+1){ print "banana";}
if (n <=2) return 1;
else {
x =0;
for (int j=1; j<= n; j++){ x = x+DoSomething(n/2);}
return x*x;
}
}
Give a recurrence relationship for T(n)? For simplicity you may assume that n is a power of 2.
a. T(n)= n*T(n/2)+ n for n >2 and T(n)= n for n<=2.
b. T(n)= n*T(n/2)+ log n for n >2 and T(n)=1 for n<=2.
c.T(n)= n*T(n/2)+ n for n >2 and T(n)=0 for n<=2.
d. T(n)=2*T(n/2)+ n for n >2 and T(n)=0 for n<=2.
e. T(n)= T(n/2)+ n for n >2 and T(n)=0 for n<=2.
f. T(n)= T(n/2)+ log n for n >2 and T(n)=0 for n<=2.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil, Elizabeth O'Neil

2nd Edition

1558605800, 978-1558605800

More Books

Students also viewed these Databases questions