1 / 3

MergeSort

MergeSort. O( n log n ), Ω ( n log n ) Sort (list of n ) If n <2, return. Else Sort (left half). Sort (right half). Merge sorted halves. int main (void) { int ans = factR(5); }. int fact(5) factR (int numR) { //base case! if (numR <=1)

cicero
Télécharger la présentation

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 • O(n log n), Ω(n log n) Sort (list of n) Ifn<2,return. Else Sort(lefthalf). Sort(righthalf). Mergesortedhalves.

  2. int main (void) { int ans = factR(5); } int fact(5) factR (int numR) { //base case! if (numR <=1) return 1; else return numR * factR(numR-1); } How it happens int fact(4) factR (int numR) { //base case! if (numR <=1) return 1; else return numR * factR(numR-1); } int fact(3) factR (int numR) { //base case! if (numR <=1) return 1; else return numR * factR(numR-1); } int fact(2) factR (int numR) { //base case! if (numR <=1) return 1; else return numR * factR(numR-1); } int fact(1) factR (int numR) { //base case! if (numR <=1) return 1; else return numR * factR(numR-1); } int fact(0) factR (int numR) { //base case! if (numR <=1) return 1; else return numR * factR(numR-1); }

  3. int main (void) { int ans = factR(5); return 0; } int fact(5) factR (int numR) { //base case! if (numR <=1) return 1; else return numR * factR(numR-1); } How it happens 1 ans = 120! int fact(4) factR (int numR) { //base case! if (numR <=1) return 1; else return numR * factR(numR-1); } 1 int fact(3) factR (int numR) { //base case! if (numR <=1) return 1; else return numR * factR(numR-1); } 2 int fact(2) factR (int numR) { //base case! if (numR <=1) return 1; else return numR * factR(numR-1); } int fact(1) factR (int numR) { //base case! if (numR <=1) return 1; else return numR * factR(numR-1); } 6 ( 24 ) int fact(0) factR (int numR) { //base case! if (numR <=1) return 1; else return numR * factR(numR-1); } ( 6 ) 24 ( 2 ) ( 1 ) 120 ( 1 )

More Related