1 / 77

Mergesort

Mergesort. Mergesort: Algorithm. void mergesort( Elem[] a, Elem[] temp, int Ieft, int right ) { int I, j, k, mid = (left+right)/2 if( left == right ) return mergesort( a, temp, left, mid); mergesort( a, temp, mid+1, right); // do the merge operation

abril
Download Presentation

Mergesort

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Mergesort

  2. Mergesort: Algorithm void mergesort( Elem[] a, Elem[] temp, int Ieft, int right ) { int I, j, k, mid = (left+right)/2 if( left == right ) return mergesort( a, temp, left, mid); mergesort( a, temp, mid+1, right); // do the merge operation for( i = left; i <= mid; i++ ) temp[i] = a[i] for( j = 1; j <= right-mid; j++ ) temp[ right-j+1 ] = a[ j+mid ] // merge sublists back to array for( i=left, j=right, k=left; k<=right; k++ ) { if( temp[ i ] < temp[ j ] ) a[k] = temp[ i++ ] else a[k]=temp[ j-- ] } }

  3. Mergesort: Illustration 85 24 63 45 17 31 96 50

  4. Mergesort: Illustration 85 24 63 45 17 31 96 50

  5. Mergesort: Illustration 17 31 96 50 85 24 63 45

  6. Mergesort: Illustration 17 31 96 50 63 45 85 24

  7. Mergesort: Illustration 17 31 96 50 63 45 85 24

  8. Mergesort: Illustration 17 31 96 50 24 63 45 85

  9. Mergesort: Illustration 17 31 96 50 24 63 45 85

  10. Mergesort: Illustration 17 31 96 50 24 85 63 45

  11. Mergesort: Illustration 17 31 96 50 24 85 63 45

  12. Mergesort: Illustration 17 31 96 50 24 85 63 45

  13. Mergesort: Illustration 17 31 96 50 24 85 63 45

  14. Mergesort: Illustration 17 31 96 50 24 85 63 45

  15. Mergesort: Illustration 17 31 96 50 24 85 45 63

  16. Mergesort: Illustration 17 31 96 50 24 85 45 63

  17. Mergesort: Illustration 17 31 96 50 24 85 45 63

  18. Mergesort: Illustration 17 31 96 50 24 85 45 63

  19. Mergesort: Illustration 17 31 96 50 24 85 45 63

  20. Mergesort: Illustration 17 31 96 50 2485 4563

  21. Mergesort: Illustration 24 17 31 96 50 85 4563

  22. Mergesort: Illustration 24 17 31 96 50 85 4563

  23. Mergesort: Illustration 24 45 17 31 96 50 85 63

  24. Mergesort: Illustration 2445 17 31 96 50 85 63

  25. Mergesort: Illustration 2445 63 17 31 96 50 85

  26. Mergesort: Illustration 244563 17 31 96 50 85

  27. Mergesort: Illustration 24456385 17 31 96 50

  28. Mergesort: Illustration 24 45 63 85 17 31 96 50

  29. Mergesort: Illustration 24 45 63 85 17 31 96 50

  30. Mergesort: Illustration 24 45 63 85 17 31 96 50

  31. Mergesort: Illustration 24 45 63 85 96 50 17 31

  32. Mergesort: Illustration 24 45 63 85 96 50 17 31

  33. Mergesort: Illustration 24 45 63 85 17 96 50 31

  34. Mergesort: Illustration 24 45 63 85 17 96 50 31

  35. Mergesort: Illustration 24 45 63 85 17 31 96 50

  36. Mergesort: Illustration 24 45 63 85 17 31 96 50

  37. Mergesort: Illustration 24 45 63 85 17 31 96 50

  38. Mergesort: Illustration 24 45 63 85 17 31 96 50

  39. Mergesort: Illustration 24 45 63 85 17 31 96 50

  40. Mergesort: Illustration 24 45 63 85 17 31 50 96

  41. Mergesort: Illustration 24 45 63 85 17 31 50 96

  42. Mergesort: Illustration 24 45 63 85 17 31 50 96

  43. Mergesort: Illustration 24 45 63 85 17 31 50 96

  44. Mergesort: Illustration 24 45 63 85 17 31 50 96

  45. Mergesort: Illustration 24 45 63 85 1731 5096

  46. Mergesort: Illustration 24 45 63 85 17 31 5096

  47. Mergesort: Illustration 24 45 63 85 17 31 5096

  48. Mergesort: Illustration 24 45 63 85 17 31 5096

  49. Mergesort: Illustration 24 45 63 85 1731 5096

  50. Mergesort: Illustration 24 45 63 85 173150 96

More Related