Upload
neva
View
32
Download
0
Embed Size (px)
DESCRIPTION
Analysis of Quick Sort and Merge Sort. Aditya Bhutra. Implementation. Code written in JAVA (JDK 6) Standard Quick Sort and Merge Sort methods Implemented Array Sizes vary from 10 6 to 5 x 10 7 . Array Elements contain double precision floating point random numbers between 0 and 1 . - PowerPoint PPT Presentation
Citation preview
Analysis of Quick Sort and Merge Sort
Aditya Bhutra
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)
Code Snippet
Quick Sort
Array Sizes
Performance increases with Array Size.
Merge Sort (constant Memory)
Array Sizes
Performance worsens with increasing Array Size .
Merge Sort(constant Array Size)
Allotted Memory
Array Size = 106
Performance increases with increasing Memory space.
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.)
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.