Professional Documents
Culture Documents
Data Structure & Algorithms CS-201: Lecture 05-Sorting Algorithms Dr. Muhammad Mobeen Movania
Data Structure & Algorithms CS-201: Lecture 05-Sorting Algorithms Dr. Muhammad Mobeen Movania
Data Structure & Algorithms CS-201: Lecture 05-Sorting Algorithms Dr. Muhammad Mobeen Movania
CS-201
Lecture 05-Sorting Algorithms
http://interactivepython.org/courselib/static/pythonds/SortSearch/TheShellSort.html
Shell Sort Example
http://interactivepython.org/courselib/static/pythonds/SortSearch/TheShellSort.html
Shell Sort Algorithm
http://mathbits.com/MathBits/CompSci/Arrays/Shell.htm
Shell Sort Efficiency
• Requires nested loops that do not run n times but are
based on increment size
• Outermost loop divides the increment by 2
– Complexity O(log2n)
• The first inner loop runs n-increment times for each outer
loop
– Complexity O(n)
• Total complexity of outer + first inner loop O(nlog2n)
• The inner most loop also runs a few iterations
– Complexity > O(nlog2n)
• Based on experimental analysis, the complexity of shell sort
algorithm is ~O(n1.25)
Bubble Sort
• Simplest sorting algorithm
• Worst performance of all sorting algorithms
• Typically has complexity O(n2)
• For a list of N elements, it requires N-1 passes
• In each pass, the ith element is compared to
(i+1)th element
• For ascending order, the smallest element is
bubbled from unsorted to sorted list
Bubble Sort Concept
Bubble Sort Example