Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

void mergesort (int n , keytype S[]) { if (n>1) { const int h = floor(n/2) , m = n h ; keytype U [1..h]

void mergesort (int n , keytype S[])

{

if (n>1)

{

const int h = floor(n/2) , m = n h ;

keytype U [1..h] , V[1 ..m];

copy S[1] through S[h] to U[1] through U[h]

copy S[h+1] through S[n] to V[1] through V[m]

mergesort( h , U);

mergesort(m ,V);

merge(h , m , U , V, S);

}

}

void merge (int h , int m , const keytype U[], const keytype V[], const keytype S[])

{

index i , j , k ;

i = 1 ;

j = 1 ; k = 1

while (i <= h && j <= m )

{

if ( U[i] < V[j])

{

S[k] = U[i ] ; i++;

} else{

S[k] = V[j ] ; j++; }

k++; }

If ( i >h )

copy V[j] through V[m] to S[K] through S[h+m]

else

copy U[i] through U[h] to S[k] through S[h+ m]

}

Can you complete what's missing as well as use the master theorem to find the time complexity?

The language is Java

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

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions