Docsity

Merge-Sort and Quick-Sort Algorithms Analysis, Slides of Design and Analysis of Algorithms

Partial preview of the text

Download Merge-Sort and Quick-Sort Algorithms Analysis and more Slides Design and Analysis of Algorithms in PDF only on Docsity!

26

Merge-Sort(A, 1, 1)

, base case

A:

27

Merge-Sort(A, 1, 1), return

A:

29

Merge-Sort(A, 0, 1), return

A:

30

Merge-Sort(A, 2, 3)

, divide

A:

32

Merge-Sort(A, 2, 2), return

A:

33

Merge-Sort(A, 3, 3), base case

A:

35

Merge(A, 2, 2, 3)

A:

36

Merge-Sort(A, 2, 3), return

A:

38

Merge-Sort(A, 0, 3), return

A:

39

Merge-Sort(A, 4, 7)

A:

41

Merge-Sort(A, 4, 7), return

A:

42

Merge(A, 0, 3, 7)

A:

Merge-Sort(A, 0, 7), done!

44

Merge-Sort Summary

Approach: divide and conquer

Time

 Most of the work is in the merging

 Total time: (n log n)

Space:

 (n), more space than other sorts.

45

Overview

 Divide and Conquer

 Merge Sort

 Quick Sort