Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question
100%

Using Java implementations presented in the algorithms below.Practice Mergesort algorithm with Comparable Java objects whose class definition implements Java's Comparable interface. For example, using sample Comparable Student objects  or Comparable Java class objects of your own implementation. 

Algorithm:

void mergesort(E[] A, E[] temp, int l, int r) { int i, j, k, mid = (l+r)/2; if (l == r) return; // List has one element if ((mid-l) >= THRESHOLD) mergesort(A, temp, l, mid); else inssort(A, l, mid-l+1); if ((r-mid) > THRESHOLD) mergesort(A, temp, mid+1, r); else inssort(A, mid+1, r-mid); // Do merge. First, copy 2 halves to temp. for (i=l; i<=mid; i++) temp[i] = A[i]; for (j=1; j<=r-mid; j++) temp[r-j+1] = A[j+mid]; // Merge sublists back to array for (i=l,j=r,k=l; k<=r; k++) if (temp[i].compareTo(temp[j])<0) A[k] = temp[i++]; else A[k] = temp[j--];}

Page <
202
>
of 344
ZOOM
+
Mergesort
List mergesort(List inlist) {
if (inlist.length() <= 1) return inlist;
List 11 = half of the items from inlist;
List 12
= other half of items from inlist;
return merge (mergesort(11),
mergesort(12));
}
36 20 17 13 28 14 23 15
20 36 13 17|14 28||15 23
13 17 20 36|| 14 15 23 28
13 14 15 17 20 23 28 36
expand button
Transcribed Image Text:Page < 202 > of 344 ZOOM + Mergesort List mergesort(List inlist) { if (inlist.length() <= 1) return inlist; List 11 = half of the items from inlist; List 12 = other half of items from inlist; return merge (mergesort(11), mergesort(12)); } 36 20 17 13 28 14 23 15 20 36 13 17|14 28||15 23 13 17 20 36|| 14 15 23 28 13 14 15 17 20 23 28 36
Page <
203
of 344
ZOOM
+
Mergesort Implementation
static <E extends Comparable<? super E>>
void mergesort(E[] A, E[] temp, int l, int r) {
int mid = (1+r)/2;
if (1 =
mergesort(A, temp, l, mid);
mergesort (A, temp, mid+1, r);
for (int i=i; i<=r; i++)' // Copy subarray
temp[i] = A[i];
// Do the merge operation back to A
int il
r) return;
1; int i2 = mid + 1;
for (int curr=l; curr<=r; curr++) {
if (il
A[curr] =
else if (i2 > r) ¯// Right sublist exhausted
A[curr] = temp[il++] ;
else if (temp[il].compareTo (temp[i2])<0)
A[curr] = temp[il++];
else A[curr] = temp[i2++] ;
}
}
mid+1) // Left sublist exhausted
temp[i2++] ;
expand button
Transcribed Image Text:Page < 203 of 344 ZOOM + Mergesort Implementation static <E extends Comparable<? super E>> void mergesort(E[] A, E[] temp, int l, int r) { int mid = (1+r)/2; if (1 = mergesort(A, temp, l, mid); mergesort (A, temp, mid+1, r); for (int i=i; i<=r; i++)' // Copy subarray temp[i] = A[i]; // Do the merge operation back to A int il r) return; 1; int i2 = mid + 1; for (int curr=l; curr<=r; curr++) { if (il A[curr] = else if (i2 > r) ¯// Right sublist exhausted A[curr] = temp[il++] ; else if (temp[il].compareTo (temp[i2])<0) A[curr] = temp[il++]; else A[curr] = temp[i2++] ; } } mid+1) // Left sublist exhausted temp[i2++] ;
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY