Question: Modify the following algorithm so that it works when n is odd and show that the time complexity is: 3n/2 -2 comparisons if n is

Modify the following algorithm so that it works when n is odd and show that the time complexity is: 3n/2 -2 comparisons if n is even 3n/2 3/2 comparisons if n is odd Modify the following algorithm so that it works when n is

someone gave me this solution but it does not make sense, can someone else elaborate and write the proof step by step?

If n is odd then the for loop will change to

for(i= 2; i

Since the loop is jumping twice every time and we are running it until n-1 times

so the complexity will be 3n/2 - 2.

and if n is odd then it will be (3n/2)-3/2

void fina-both(nt n, n is assumed to be even const keytype S keytype& sma keytype& large) index i if (S[1

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!