Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 oddimage text in transcribed

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

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

Step: 3

blur-text-image

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

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions