Question: Question1 if possible, could anyone do with explanation For each of the following code snippets, give both of the following: a. Give the overall T(n)

Question1

if possible, could anyone do with explanation For each of the following code snippets, give both of the following: a. Give the overall T(n) run me analysis expression for the code. b. Describe the worst case running me of the code snippet in BigOh notation.

1.for (int i=0;i

{

for (int j=0;j

{ sum++;}

}

2.void silly(int n,int x,int y)

{ for (int i=0;i

{ if (x

{ for (int j=0;j<100*n*n;j++)

{ cout<< "j="<

else {cout <<"i="<

3.void silly(int n,int m)

{ if (n<1)

{ return ;}

if (n

{ silly(n/2,m+1); }

else

{ silly (n/2, m); }}

4.for (int i=0;i<3*n;i++)

{

sum++;

}

for (int i=1;i

{ for (int j=0;j

{ sum++; }}}

5. for (int i=0;i

{

for (int j=0;j

{ sum++;}}

Question 2 Given the following list of values, perform a binary search for the indicated search item. Show the values of rst, last and middle, and the number of comparisons made after each iteration of the loop. Your should create a table like the following to show your work, where rst and last are the values of the variables at the beginning of the loop, and mid is the midpoint used during that iteration, list[mid] is the value in the list at the midpoint, and No. of key comparisons should be the number of comparisons made during this iteration by the algorithm:

Iteration first last mid list[mid] no of key comparisons

1 0 12 ? ? ?

list [7,9,9,9,10,12,19,20,22,28,28,29,29]

Searching for value:22

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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

Students Have Also Explored These Related Databases Questions!