SlideShare a Scribd company logo
Shell Sort
&
Selection Sort
Shell Sort
Algorithm
It is a highly efficient sorting algorithm and is based
on insertion sort algorithm.
Shell Sort
This algorithm avoids large shifts as in case of
insertion sort, if the smaller value is to the far right
and has to be moved to the far left.
Uses insertion sort on a widely spread elements,
sort them and then sorts the less widely spaced
elements. This spacing is termed as interval.
Shell Sort
This interval is calculated based on Knuth's formula
(h = h * 3 +1) where − h is interval with initial
value 1
This algorithm is quite efficient for medium-sized
data sets as its average and worst case complexity
are of Ο(n), where n is the number of items.
Shell Sort
THEOREM:
 Any sorting algorithm that only swaps adjacent
elements has average time no faster than
(O(n^{2})).
 The Shell sort (named for its inventor, Donald Shell)
is an early and interesting attempt to do this.
Shell Sort
 Insertion sort is fastest when;
a) The array is nearly sorted.
b) The array contains only small number of
data items
Shell Sort
 Makes use of intrinsic strength of Insertion sort.
THEOREM:
Shell Sort
 Shell sort works well because :
a) It always deals with a small number of
elements.
b) Elements are moved a long way through
array with each swap this leaves it more
nearly sorted.
THEOREM:
Shell Sort Best Case:
Shell Sort
• The best case in the shell sort is when the
array is already sorted in the right order.
• The number of comparisons is less.
Shell Sort Worst Case:
Shell Sort
• The running time of Shell sort depends on the
choice of increment sequence.
• Pairs of increments are not necessarily relatively
prime and smaller increments can have little
effect.
Shell Sort
Example:
Shell Sort
Shell Sort
Interval Sequence:
 The sequence h1,h2,h3….ht is a sequence of
increasing integer values which will be used as a
sequence (from right to left) of interval values.
• Any sequence will work as long as it is increasing
and h1=1.
Shell Sort
• For any interval value, we all have A[i] <=A[i + h].
• An array A for which this is true is hk sorted.
• An array which is hk and is then hk-1 sorted remains
as hk sorted.
 Implementation of Shell Sort
Shell Sort
Shell Sort
Shell Sort
 Output:
Selection
Sort
Algorithm
Selection Sort
 It sorts an array by repeatedly finding the minimum
element (considering ascending order) from
unsorted part and putting it at the beginning.
 The algorithm maintains two sub-arrays in a given
array.
1) The sub-array which is already sorted.
2) Remaining sub-array which is unsorted.
Selection Sort
 It is conceptually the simplest sorting algorithm.
 It is unstable sort and at the same time it can be
also stable.
 It is unstable sort and at the same time it can be
also stable.
Selection Sort
 Idea of Selection Sort: Largest-to-Smallest
• The first element of the sorted array will be the
one with the largest value.
• Second will be the largest element of the rest of
the array.
• Third will be the largest element of the new rest of
the array (initial array without the two already
sorted elements).
Selection Sort
HOW DOES SELECTION SORT WORKS?
1ST:
Find the index of the largest element and exchange
the position with the element at the last index.
2nd:
Decrement the last index
When the array ends like this, the sorting stops.
Selection Sort
Selection Sort
Three procedures inside the selection sort:
1. Comparison, the times of comparison in a n value
array is (n(n-1))/2.
2. Value Assignment, the times of value assignment
is between 0 to 3(n-1).
3. Exchanging, the times need is between 0 to (n-1).
 Implementation of Selection Sort
Selection Sort
Selection Sort
 Output:
Selection Sort

More Related Content

PPT
Selection sort
PPT
Shell sort
PPT
3.3 shell sort
PPTX
Quick sort
PPT
3.8 quick sort
PPTX
Insertion Sort
PPT
Shell sort
PDF
Insertion sort
Selection sort
Shell sort
3.3 shell sort
Quick sort
3.8 quick sort
Insertion Sort
Shell sort
Insertion sort

What's hot (20)

PPTX
Shellshort ppt
PDF
Sorting Algorithms
PPT
Algorithm: Quick-Sort
PPTX
Sorting Algorithms
PPTX
Insertion sort
PPTX
closed hashing.pptx
PPTX
Quicksort Algorithm..simply defined through animations..!!
PPT
Shell sort
PDF
Quick Sort , Merge Sort , Heap Sort
PPTX
Rahat &amp; juhith
PPTX
Merge sort algorithm power point presentation
PPTX
Bubble Sort Algorithm Presentation
PPTX
Complexity analysis in Algorithms
PPTX
Recursion fib
PPTX
Sorting algorithms
PPTX
Algorithm Complexity and Main Concepts
PPT
Priority queues
PDF
Lecture 3 insertion sort and complexity analysis
PPTX
Bubble Sort
Shellshort ppt
Sorting Algorithms
Algorithm: Quick-Sort
Sorting Algorithms
Insertion sort
closed hashing.pptx
Quicksort Algorithm..simply defined through animations..!!
Shell sort
Quick Sort , Merge Sort , Heap Sort
Rahat &amp; juhith
Merge sort algorithm power point presentation
Bubble Sort Algorithm Presentation
Complexity analysis in Algorithms
Recursion fib
Sorting algorithms
Algorithm Complexity and Main Concepts
Priority queues
Lecture 3 insertion sort and complexity analysis
Bubble Sort
Ad

Similar to Shell Sort and Selection Sort Algorithm (20)

PPTX
Analysis and Design of Algorithms -Sorting Algorithms and analysis
PPTX
SHELL SORT-2.pptx
PDF
Chapter 8 advanced sorting and hashing for print
PPT
Chapter 6 - Advanced Sorting Algorithms (1).ppt
PDF
Sorting Algorithms
PPTX
It elective cs366-barizo-shell
PPTX
Ch2 Part III-Advanced Sorting algorithms.pptx
PPT
Shell sorting
 
PPTX
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
PPT
sorting_part1.ppt
PPTX
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
PPT
358 33 powerpoint-slides_14-sorting_chapter-14
PPTX
Unit vii sorting
PPT
Advanced s and s algorithm.ppt
PPTX
Sorting Algorithms to arrange data in particular format
PPTX
DSA-sortijejjejjdjjdjdjjsjsjsjsjsjsjng.pptx
PPTX
Sorting-Algorithms-A-Comprehensive-Guide.pptx
PPTX
Different Searching and Sorting Methods.pptx
PPT
SEARCHING AND SORTING ALGORITHMS
PPT
Sorting Techniques
Analysis and Design of Algorithms -Sorting Algorithms and analysis
SHELL SORT-2.pptx
Chapter 8 advanced sorting and hashing for print
Chapter 6 - Advanced Sorting Algorithms (1).ppt
Sorting Algorithms
It elective cs366-barizo-shell
Ch2 Part III-Advanced Sorting algorithms.pptx
Shell sorting
 
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
sorting_part1.ppt
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
358 33 powerpoint-slides_14-sorting_chapter-14
Unit vii sorting
Advanced s and s algorithm.ppt
Sorting Algorithms to arrange data in particular format
DSA-sortijejjejjdjjdjdjjsjsjsjsjsjsjng.pptx
Sorting-Algorithms-A-Comprehensive-Guide.pptx
Different Searching and Sorting Methods.pptx
SEARCHING AND SORTING ALGORITHMS
Sorting Techniques
Ad

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Machine Learning_overview_presentation.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Cloud computing and distributed systems.
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
sap open course for s4hana steps from ECC to s4
cuic standard and advanced reporting.pdf
Network Security Unit 5.pdf for BCA BBA.
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
NewMind AI Weekly Chronicles - August'25-Week II
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Machine Learning_overview_presentation.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Review of recent advances in non-invasive hemoglobin estimation
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
20250228 LYD VKU AI Blended-Learning.pptx
MYSQL Presentation for SQL database connectivity
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Assigned Numbers - 2025 - Bluetooth® Document
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Digital-Transformation-Roadmap-for-Companies.pptx
Spectral efficient network and resource selection model in 5G networks
Cloud computing and distributed systems.
The AUB Centre for AI in Media Proposal.docx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
sap open course for s4hana steps from ECC to s4

Shell Sort and Selection Sort Algorithm

  • 3. It is a highly efficient sorting algorithm and is based on insertion sort algorithm. Shell Sort This algorithm avoids large shifts as in case of insertion sort, if the smaller value is to the far right and has to be moved to the far left.
  • 4. Uses insertion sort on a widely spread elements, sort them and then sorts the less widely spaced elements. This spacing is termed as interval. Shell Sort This interval is calculated based on Knuth's formula (h = h * 3 +1) where − h is interval with initial value 1
  • 5. This algorithm is quite efficient for medium-sized data sets as its average and worst case complexity are of Ο(n), where n is the number of items. Shell Sort
  • 6. THEOREM:  Any sorting algorithm that only swaps adjacent elements has average time no faster than (O(n^{2})).  The Shell sort (named for its inventor, Donald Shell) is an early and interesting attempt to do this. Shell Sort
  • 7.  Insertion sort is fastest when; a) The array is nearly sorted. b) The array contains only small number of data items Shell Sort  Makes use of intrinsic strength of Insertion sort. THEOREM:
  • 8. Shell Sort  Shell sort works well because : a) It always deals with a small number of elements. b) Elements are moved a long way through array with each swap this leaves it more nearly sorted. THEOREM:
  • 9. Shell Sort Best Case: Shell Sort • The best case in the shell sort is when the array is already sorted in the right order. • The number of comparisons is less.
  • 10. Shell Sort Worst Case: Shell Sort • The running time of Shell sort depends on the choice of increment sequence. • Pairs of increments are not necessarily relatively prime and smaller increments can have little effect.
  • 13. Shell Sort Interval Sequence:  The sequence h1,h2,h3….ht is a sequence of increasing integer values which will be used as a sequence (from right to left) of interval values.
  • 14. • Any sequence will work as long as it is increasing and h1=1. Shell Sort • For any interval value, we all have A[i] <=A[i + h]. • An array A for which this is true is hk sorted. • An array which is hk and is then hk-1 sorted remains as hk sorted.
  • 15.  Implementation of Shell Sort Shell Sort
  • 19. Selection Sort  It sorts an array by repeatedly finding the minimum element (considering ascending order) from unsorted part and putting it at the beginning.  The algorithm maintains two sub-arrays in a given array. 1) The sub-array which is already sorted. 2) Remaining sub-array which is unsorted.
  • 20. Selection Sort  It is conceptually the simplest sorting algorithm.  It is unstable sort and at the same time it can be also stable.  It is unstable sort and at the same time it can be also stable.
  • 21. Selection Sort  Idea of Selection Sort: Largest-to-Smallest • The first element of the sorted array will be the one with the largest value. • Second will be the largest element of the rest of the array. • Third will be the largest element of the new rest of the array (initial array without the two already sorted elements).
  • 22. Selection Sort HOW DOES SELECTION SORT WORKS? 1ST: Find the index of the largest element and exchange the position with the element at the last index.
  • 23. 2nd: Decrement the last index When the array ends like this, the sorting stops. Selection Sort
  • 24. Selection Sort Three procedures inside the selection sort: 1. Comparison, the times of comparison in a n value array is (n(n-1))/2. 2. Value Assignment, the times of value assignment is between 0 to 3(n-1). 3. Exchanging, the times need is between 0 to (n-1).
  • 25.  Implementation of Selection Sort Selection Sort