Transcript
Page 1: Analysis of Quick Sort and Merge Sort

Analysis of Quick Sort and Merge Sort

Aditya Bhutra

Page 2: Analysis of Quick Sort and Merge Sort

Implementation• Code written in JAVA (JDK 6)

• Standard Quick Sort and Merge Sort methods

Implemented

• Array Sizes vary from 106 to 5x107 .

• Array Elements contain double precision floating point

random numbers between 0 and 1 .

• Computing 1000 iterations for each Array Size .

• Time measured for each sort is measured in

nanoseconds using System.nanoTime() method.

• Normalised time is calculated as Time/nlog(n) .

• Normalised number of Comparisons is also calculated as

Comparisons/nlog(n)

Page 3: Analysis of Quick Sort and Merge Sort

Code Snippet

Page 4: Analysis of Quick Sort and Merge Sort
Page 5: Analysis of Quick Sort and Merge Sort

Quick Sort

Array Sizes

Performance increases with Array Size.

Page 6: Analysis of Quick Sort and Merge Sort

Merge Sort (constant Memory)

Array Sizes

Performance worsens with increasing Array Size .

Page 7: Analysis of Quick Sort and Merge Sort

Merge Sort(constant Array Size)

Allotted Memory

Array Size = 106

Performance increases with increasing Memory space.

Page 8: Analysis of Quick Sort and Merge Sort
Page 9: Analysis of Quick Sort and Merge Sort
Page 10: Analysis of Quick Sort and Merge Sort

Observations• Normalised Number of Comparisons remains almost constant with

Array Size for both Sorting methods . Merge Sort – Slightly Incresing Quick Sort – Slightly Decreasing

• Abnormal decrease in the value of Merge Comparisons for Array Size of 5*107 .

• Merge comparisons exceed twice the number of Quick Comparisons. (except the 5*107 case.)

Page 11: Analysis of Quick Sort and Merge Sort

Conclusions• Quick Sort performs better with increasing Array Size.• Merge Sort performs worse with increasing Array Size.

• Quick Sort performance remains independent of Allocated Memory.• Merge Sort performance is enhanced by increasing Allocated Memory.

• For Smaller Array Sizes ( < 2 x 106 ) , Merge Sort performs better than Quick Sort if sufficient memory is allocated.

• Unlike Merge Sort , in Quick Sort , the frequency curve sharpens with increasing Array Size . This signifies that Quick Sort becomes more reliable for very large Array Sizes.


Recommended