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

What's hot (20)

PPTX
Selection sort 1
asmhemu
 
PPT
SEARCHING AND SORTING ALGORITHMS
Gokul Hari
 
PPTX
closed hashing.pptx
VikasNirgude2
 
PDF
Loop invarient
Amit Kumar Rathi
 
PPTX
Insertion sort
MYER301
 
PPTX
Hash table
Vu Tran
 
PPTX
Searching & Algorithms IN DATA STRUCTURES
RAKSHITDOGRA1
 
PPTX
Merge sort
kajalsharma161
 
PPT
Selection sort
stella D
 
PPTX
Hashing Technique In Data Structures
SHAKOOR AB
 
PPTX
Avl trees
amna izzat
 
PPT
Quick Sort
priyankanaidu6
 
PPTX
Insertion sort
almaqboli
 
PPTX
Insertion Sort, Quick Sort And Their complexity
Motaleb Hossen Manik
 
PPT
Merge sort
Vidushi Pathak
 
PPTX
Algorithm analysis (All in one)
jehan1987
 
PPTX
Deque and its applications
Jsaddam Hussain
 
PPT
Searching algorithms
Trupti Agrawal
 
PPTX
5.Error correction-Hamming Code.pptx
AswathiThotz
 
PPTX
Quicksort Presentation
irdginfo
 
Selection sort 1
asmhemu
 
SEARCHING AND SORTING ALGORITHMS
Gokul Hari
 
closed hashing.pptx
VikasNirgude2
 
Loop invarient
Amit Kumar Rathi
 
Insertion sort
MYER301
 
Hash table
Vu Tran
 
Searching & Algorithms IN DATA STRUCTURES
RAKSHITDOGRA1
 
Merge sort
kajalsharma161
 
Selection sort
stella D
 
Hashing Technique In Data Structures
SHAKOOR AB
 
Avl trees
amna izzat
 
Quick Sort
priyankanaidu6
 
Insertion sort
almaqboli
 
Insertion Sort, Quick Sort And Their complexity
Motaleb Hossen Manik
 
Merge sort
Vidushi Pathak
 
Algorithm analysis (All in one)
jehan1987
 
Deque and its applications
Jsaddam Hussain
 
Searching algorithms
Trupti Agrawal
 
5.Error correction-Hamming Code.pptx
AswathiThotz
 
Quicksort Presentation
irdginfo
 

Similar to Shell Sort and Selection Sort Algorithm (20)

PPTX
Analysis and Design of Algorithms -Sorting Algorithms and analysis
Radhika Talaviya
 
PPTX
SHELL SORT-2.pptx
CS50Bootcamp
 
PDF
Chapter 8 advanced sorting and hashing for print
Abdii Rashid
 
PPT
Chapter 6 - Advanced Sorting Algorithms (1).ppt
afendimohammed288
 
PDF
Sorting Algorithms
IRJET Journal
 
PPTX
It elective cs366-barizo-shell
ChristianBarizo
 
PPTX
Ch2 Part III-Advanced Sorting algorithms.pptx
Mohammed472103
 
PPT
Shell sorting
TUC
 
PPTX
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
kncetaruna
 
PPT
sorting_part1.ppt
ReehaamMalikArain
 
PPTX
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
VISWANATHAN R V
 
PPT
358 33 powerpoint-slides_14-sorting_chapter-14
sumitbardhan
 
PPTX
Unit vii sorting
Tribhuvan University
 
PPT
Advanced s and s algorithm.ppt
LegesseSamuel
 
PPTX
Sorting Algorithms to arrange data in particular format
itsusamazahid
 
PPTX
DSA-sortijejjejjdjjdjdjjsjsjsjsjsjsjng.pptx
suryatom5775
 
PPTX
Sorting-Algorithms-A-Comprehensive-Guide.pptx
ReemEmad26
 
PPTX
Different Searching and Sorting Methods.pptx
Minakshee Patil
 
PPT
Shell sort
Rajendran
 
PPT
Sorting Techniques
Rafay Farooq
 
Analysis and Design of Algorithms -Sorting Algorithms and analysis
Radhika Talaviya
 
SHELL SORT-2.pptx
CS50Bootcamp
 
Chapter 8 advanced sorting and hashing for print
Abdii Rashid
 
Chapter 6 - Advanced Sorting Algorithms (1).ppt
afendimohammed288
 
Sorting Algorithms
IRJET Journal
 
It elective cs366-barizo-shell
ChristianBarizo
 
Ch2 Part III-Advanced Sorting algorithms.pptx
Mohammed472103
 
Shell sorting
TUC
 
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
kncetaruna
 
sorting_part1.ppt
ReehaamMalikArain
 
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
VISWANATHAN R V
 
358 33 powerpoint-slides_14-sorting_chapter-14
sumitbardhan
 
Unit vii sorting
Tribhuvan University
 
Advanced s and s algorithm.ppt
LegesseSamuel
 
Sorting Algorithms to arrange data in particular format
itsusamazahid
 
DSA-sortijejjejjdjjdjdjjsjsjsjsjsjsjng.pptx
suryatom5775
 
Sorting-Algorithms-A-Comprehensive-Guide.pptx
ReemEmad26
 
Different Searching and Sorting Methods.pptx
Minakshee Patil
 
Shell sort
Rajendran
 
Sorting Techniques
Rafay Farooq
 
Ad

Recently uploaded (20)

PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Ad

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