Merge Sort (Analysis )

8
Tim Roughgarden Introductio n Merge Sort (Analysis) Design and Analysis of Algorithms I

description

Introduction. Merge Sort (Analysis ). Design and Analysis of Algorithms I. Running Time of Merge Sort. Claim: For every input array of numbers, Merge Sort produces a sorted output array and uses operations. Proof of claim (assuming n = power of 2):. - PowerPoint PPT Presentation

Transcript of Merge Sort (Analysis )

Page 1: Merge Sort (Analysis )

Tim Roughgarden

IntroductionMerge Sort (Analysis)

Design and Analysis of Algorithms I

Page 2: Merge Sort (Analysis )

Tim Roughgarden

Running Time of Merge Sort

Claim: For every input array of numbers, Merge Sort produces a sorted output array and uses operations.

Page 3: Merge Sort (Analysis )

Tim Roughgarden

Proof of claim (assuming n = power of 2):

Page 4: Merge Sort (Analysis )

A constant number (independent of n).

log 2𝑛√𝑛𝑛

Roughly how many levels does this recursion tree have (as a function of n, the length of the input array)?

Page 5: Merge Sort (Analysis )

Tim Roughgarden

Proof of claim (assuming n = power of 2):

Page 6: Merge Sort (Analysis )

2j and 2j, respectively.

n /2 j    and   n /2 j ,  respectively .2 j    and  n /2 j ,  respectively .n /2 j    and  2 j ,  respectively .

What is the pattern? Fill in the blanks in the following statement: at each level j=0,1,2,…, , there are <blank> subproblems, each of size <blank>.

Page 7: Merge Sort (Analysis )

Tim Roughgarden

Proof of claim (assuming n = power of 2):

At each level j=0,1,2,…, , there are 2j subproblems, each of size n/2j.

Page 8: Merge Sort (Analysis )

Tim Roughgarden

Running Time of Merge Sort

Claim: For every input array of numbers, Merge Sort produces a sorted output array and uses operations.