SlideShare a Scribd company logo
1 of 17
Ver. 1.0
Shell Sort
Shell sort algorithm:
Insertion sort is an efficient algorithm only if the list is already
partially sorted and results in an inefficient solution in an
average case.
To overcome this limitation, a computer scientist, D.L. Shell
proposed an improvement over the insertion sort algorithm.
The new algorithm was called shell sort after the name of its
proposer.
Sorting Data by Using Shell Sort
Ver. 1.0
Shell Sort
Shell sort algorithm:
Improves insertion sort by comparing the elements separated
by a distance of several positions to form multiple sublists
Applies insertion sort on each sublist to move the elements
towards their correct positions
Helps an element to take a bigger step towards its correct
position, thereby reducing the number of comparisons
Implementing Shell Sort Algorithm
Ver. 1.0
Shell Sort
To understand the implementation of shell sort algorithm,
consider an unsorted list of numbers stored in an array.
Implementing Shell Sort Algorithm (Contd.)
210 43
70 104030 80arr 20
5 6 7 8 9 10
90 110 75 60 45
Ver. 1.0
Shell Sort
To apply shell sort on this array, you need to:
Select the distance by which the elements in a group will be
separated to form multiple sublists.
Apply insertion sort on each sublist to move the elements
towards their correct positions.
Implementing Shell Sort Algorithm (Contd.)
210 43
70 104030 80arr 20
5 6 7 8 9 10
90 110 75 60 45
Ver. 1.0
Shell Sort
List 1 =
Implementing Shell Sort Algorithm (Contd.)
210 43
arr
5 6 7 8 9 10
Increment = 3
Pass = 1
630 9
70 609010
741 10
30 4511080List 2 =
852
40 7520List 3 =
70 104030 80 20 90 110 75 60 45
Ver. 1.0
Shell Sort
Implementing Shell Sort Algorithm (Contd.)
630 9
70 609010
741 10
30 4511080List 2 =
852
40 7520List 3 =
Apply insertion sort to sort the
three lists
The lists are sorted
10 907060 30 1108045
20 7540
List 1 =
Ver. 1.0
Shell Sort
Implementing Shell Sort Algorithm (Contd.)
210 43
10 602030 45arr 40
5 6 7 8 9 10
70 80 75 90 110
630 9 741 10
30List 2 =
852
75List 3 =
30
75
10 60 70 90 45 80 110
20 40
List 1 =
Ver. 1.0
Shell Sort
Implementing Shell Sort Algorithm (Contd.)
210 43
10 602030 45arr 40
5 6 7 8 9 10
70 80 75 90 110
Increment = 2
Pass = 2List 1 =
420 6
10 704520
531 7
30 804060List 2 =
75 110
8 10
90
9
Ver. 1.0
Shell Sort
Implementing Shell Sort Algorithm (Contd.)
List 1 =
420 6
10 704520
531 7
30 804060List 2 =
75 110
8 10
90
9
Apply insertion sort on each sublist
Ver. 1.0
Shell Sort
Implementing Shell Sort Algorithm (Contd.)
List 1 =
420 6
10 704520
531 7
30 806040List 2 =
75 110
8 10
90
9
The lists are now sorted
Ver. 1.0
Shell Sort
Implementing Shell Sort Algorithm (Contd.)
List 1 =
420 6
10 704520
531 7
30 806040List 2 =
75 110
8 10
90
9
210 43
10 402030 45arr 60
5 6 7 8 9 10
70 80 75 90 110
Ver. 1.0
Shell Sort
Implementing Shell Sort Algorithm (Contd.)
210 43
10 402030 45arr 60
5 6 7 8 9 10
70 80 75 90 110
Increment = 1
Pass = 3
Apply insertion sort to sort the list
Ver. 1.0
Shell Sort
Implementing Shell Sort Algorithm (Contd.)
210 43
10 403020 45arr 60
5 6 7 8 9 10
70 75 80 90 110
Increment = 1
Pass = 3
The list is now sorted
Ver. 1.0
Shell Sort
Which of the following sorting algorithms compares the
elements separated by a distance of several positions to
sort the data? The options are:
1. Insertion sort
2. Selection sort
3. Bubble sort
4. Shell sort
Just a minute
Answer:
4. Shell sort
Ver. 1.0
Shell Sort
In this session, you learned that:
Sorting is a process of arranging data in some pre-defined
order of a key value. The order can be either ascending or
descending.
There are various sorting algorithms that are used to sort data.
Some of them are:
Bubble sort
Selection sort
Insertion sort
Shell sort
Merge sort
Quick sort
Heap sort
Summary
Ver. 1.0
Shell Sort
To select an appropriate algorithm, you need to consider the
following:
Execution time
Storage space
Programming effort
Bubble sort and selection algorithms have a quadratic order of
growth, and are therefore suitable for sorting small lists only.
Insertion sort performs different number of comparisons
depending on the initial ordering of elements. When the
elements are already in the sorted order, insertion sort needs
to make very few comparisons.
Insertion sort is an efficient algorithm than bubble sort and
selection sort if the list that needs to be sorted is nearly sorted.
Summary (Contd.)
Ver. 1.0
Shell Sort
Shell sort improves insertion sort by comparing the elements
separated by a distance of several positions. This helps an
element to take a bigger step towards its correct position,
thereby reducing the number of comparisons.
Summary (Contd.)

More Related Content

What's hot (20)

Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Shellshort ppt
Shellshort pptShellshort ppt
Shellshort ppt
 
Merge Sort
Merge SortMerge Sort
Merge Sort
 
Data Structures - Searching & sorting
Data Structures - Searching & sortingData Structures - Searching & sorting
Data Structures - Searching & sorting
 
Quick sort
Quick sortQuick sort
Quick sort
 
Merge sort
Merge sortMerge sort
Merge sort
 
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHIBCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
 
Selection sort lab mannual
Selection sort lab mannualSelection sort lab mannual
Selection sort lab mannual
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
 
3.3 shell sort
3.3 shell sort3.3 shell sort
3.3 shell sort
 
Quick sort
Quick sortQuick sort
Quick sort
 
Chapter 12 ds
Chapter 12 dsChapter 12 ds
Chapter 12 ds
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Ppt bubble sort
Ppt bubble sortPpt bubble sort
Ppt bubble sort
 
Counting Sort and Radix Sort Algorithms
Counting Sort and Radix Sort AlgorithmsCounting Sort and Radix Sort Algorithms
Counting Sort and Radix Sort Algorithms
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Heaps & priority queues
Heaps & priority queuesHeaps & priority queues
Heaps & priority queues
 

Similar to Shell Sort Algorithm Explained in 40 Steps

Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template LibraryGauravPatil318
 
lecture-k-sorting.ppt
lecture-k-sorting.pptlecture-k-sorting.ppt
lecture-k-sorting.pptSushantRaj25
 
Ssis partitioning and best practices
Ssis partitioning and best practicesSsis partitioning and best practices
Ssis partitioning and best practicesVinod Kumar
 
basics of queues
basics of queuesbasics of queues
basics of queuessirmanohar
 
Advanced s and s algorithm.ppt
Advanced s and s algorithm.pptAdvanced s and s algorithm.ppt
Advanced s and s algorithm.pptLegesseSamuel
 
Chapter 8 advanced sorting and hashing for print
Chapter 8 advanced sorting and hashing for printChapter 8 advanced sorting and hashing for print
Chapter 8 advanced sorting and hashing for printAbdii Rashid
 
React table tutorial use filter (part 2)
React table tutorial use filter (part 2)React table tutorial use filter (part 2)
React table tutorial use filter (part 2)Katy Slemon
 
Gotcha! Ruby things that will come back to bite you.
Gotcha! Ruby things that will come back to bite you.Gotcha! Ruby things that will come back to bite you.
Gotcha! Ruby things that will come back to bite you.David Tollmyr
 
Coding Component (50)Weve provided you with an implementation .docx
Coding Component (50)Weve provided you with an implementation .docxCoding Component (50)Weve provided you with an implementation .docx
Coding Component (50)Weve provided you with an implementation .docxmary772
 
Sorting Techniques for Data Structures.pptx
Sorting Techniques for Data Structures.pptxSorting Techniques for Data Structures.pptx
Sorting Techniques for Data Structures.pptxKalpana Mohan
 
Analysis of Algorithm (Bubblesort and Quicksort)
Analysis of Algorithm (Bubblesort and Quicksort)Analysis of Algorithm (Bubblesort and Quicksort)
Analysis of Algorithm (Bubblesort and Quicksort)Flynce Miguel
 

Similar to Shell Sort Algorithm Explained in 40 Steps (20)

Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template Library
 
lecture-k-sorting.ppt
lecture-k-sorting.pptlecture-k-sorting.ppt
lecture-k-sorting.ppt
 
3.ppt
3.ppt3.ppt
3.ppt
 
Lecture k-sorting
Lecture k-sortingLecture k-sorting
Lecture k-sorting
 
Ssis partitioning and best practices
Ssis partitioning and best practicesSsis partitioning and best practices
Ssis partitioning and best practices
 
Queue
QueueQueue
Queue
 
SHELL SORT-2.pptx
SHELL SORT-2.pptxSHELL SORT-2.pptx
SHELL SORT-2.pptx
 
basics of queues
basics of queuesbasics of queues
basics of queues
 
Advanced s and s algorithm.ppt
Advanced s and s algorithm.pptAdvanced s and s algorithm.ppt
Advanced s and s algorithm.ppt
 
Any Which Array But Loose
Any Which Array But LooseAny Which Array But Loose
Any Which Array But Loose
 
Chapter 8 advanced sorting and hashing for print
Chapter 8 advanced sorting and hashing for printChapter 8 advanced sorting and hashing for print
Chapter 8 advanced sorting and hashing for print
 
Lab6
Lab6Lab6
Lab6
 
Technical
TechnicalTechnical
Technical
 
React table tutorial use filter (part 2)
React table tutorial use filter (part 2)React table tutorial use filter (part 2)
React table tutorial use filter (part 2)
 
Gotcha! Ruby things that will come back to bite you.
Gotcha! Ruby things that will come back to bite you.Gotcha! Ruby things that will come back to bite you.
Gotcha! Ruby things that will come back to bite you.
 
Coding Component (50)Weve provided you with an implementation .docx
Coding Component (50)Weve provided you with an implementation .docxCoding Component (50)Weve provided you with an implementation .docx
Coding Component (50)Weve provided you with an implementation .docx
 
Sorting Techniques for Data Structures.pptx
Sorting Techniques for Data Structures.pptxSorting Techniques for Data Structures.pptx
Sorting Techniques for Data Structures.pptx
 
Analysis of Algorithm (Bubblesort and Quicksort)
Analysis of Algorithm (Bubblesort and Quicksort)Analysis of Algorithm (Bubblesort and Quicksort)
Analysis of Algorithm (Bubblesort and Quicksort)
 
Python for Beginners(v3)
Python for Beginners(v3)Python for Beginners(v3)
Python for Beginners(v3)
 
Lab 6
Lab 6Lab 6
Lab 6
 

More from M Vishnuvardhan Reddy (20)

Python Sets_Dictionary.pptx
Python Sets_Dictionary.pptxPython Sets_Dictionary.pptx
Python Sets_Dictionary.pptx
 
Lists_tuples.pptx
Lists_tuples.pptxLists_tuples.pptx
Lists_tuples.pptx
 
Python Control Structures.pptx
Python Control Structures.pptxPython Control Structures.pptx
Python Control Structures.pptx
 
Python Strings.pptx
Python Strings.pptxPython Strings.pptx
Python Strings.pptx
 
Python Basics.pptx
Python Basics.pptxPython Basics.pptx
Python Basics.pptx
 
Python Operators.pptx
Python Operators.pptxPython Operators.pptx
Python Operators.pptx
 
Python Datatypes.pptx
Python Datatypes.pptxPython Datatypes.pptx
Python Datatypes.pptx
 
DataScience.pptx
DataScience.pptxDataScience.pptx
DataScience.pptx
 
Html forms
Html formsHtml forms
Html forms
 
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
 
Java Threads
Java ThreadsJava Threads
Java Threads
 
Java Streams
Java StreamsJava Streams
Java Streams
 
Scanner class
Scanner classScanner class
Scanner class
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Java intro
Java introJava intro
Java intro
 
Java applets
Java appletsJava applets
Java applets
 
Exception handling
Exception handling Exception handling
Exception handling
 
Control structures
Control structuresControl structures
Control structures
 
Constructors
ConstructorsConstructors
Constructors
 
Classes&objects
Classes&objectsClasses&objects
Classes&objects
 

Recently uploaded

What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 

Recently uploaded (20)

What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 

Shell Sort Algorithm Explained in 40 Steps

  • 1. Ver. 1.0 Shell Sort Shell sort algorithm: Insertion sort is an efficient algorithm only if the list is already partially sorted and results in an inefficient solution in an average case. To overcome this limitation, a computer scientist, D.L. Shell proposed an improvement over the insertion sort algorithm. The new algorithm was called shell sort after the name of its proposer. Sorting Data by Using Shell Sort
  • 2. Ver. 1.0 Shell Sort Shell sort algorithm: Improves insertion sort by comparing the elements separated by a distance of several positions to form multiple sublists Applies insertion sort on each sublist to move the elements towards their correct positions Helps an element to take a bigger step towards its correct position, thereby reducing the number of comparisons Implementing Shell Sort Algorithm
  • 3. Ver. 1.0 Shell Sort To understand the implementation of shell sort algorithm, consider an unsorted list of numbers stored in an array. Implementing Shell Sort Algorithm (Contd.) 210 43 70 104030 80arr 20 5 6 7 8 9 10 90 110 75 60 45
  • 4. Ver. 1.0 Shell Sort To apply shell sort on this array, you need to: Select the distance by which the elements in a group will be separated to form multiple sublists. Apply insertion sort on each sublist to move the elements towards their correct positions. Implementing Shell Sort Algorithm (Contd.) 210 43 70 104030 80arr 20 5 6 7 8 9 10 90 110 75 60 45
  • 5. Ver. 1.0 Shell Sort List 1 = Implementing Shell Sort Algorithm (Contd.) 210 43 arr 5 6 7 8 9 10 Increment = 3 Pass = 1 630 9 70 609010 741 10 30 4511080List 2 = 852 40 7520List 3 = 70 104030 80 20 90 110 75 60 45
  • 6. Ver. 1.0 Shell Sort Implementing Shell Sort Algorithm (Contd.) 630 9 70 609010 741 10 30 4511080List 2 = 852 40 7520List 3 = Apply insertion sort to sort the three lists The lists are sorted 10 907060 30 1108045 20 7540 List 1 =
  • 7. Ver. 1.0 Shell Sort Implementing Shell Sort Algorithm (Contd.) 210 43 10 602030 45arr 40 5 6 7 8 9 10 70 80 75 90 110 630 9 741 10 30List 2 = 852 75List 3 = 30 75 10 60 70 90 45 80 110 20 40 List 1 =
  • 8. Ver. 1.0 Shell Sort Implementing Shell Sort Algorithm (Contd.) 210 43 10 602030 45arr 40 5 6 7 8 9 10 70 80 75 90 110 Increment = 2 Pass = 2List 1 = 420 6 10 704520 531 7 30 804060List 2 = 75 110 8 10 90 9
  • 9. Ver. 1.0 Shell Sort Implementing Shell Sort Algorithm (Contd.) List 1 = 420 6 10 704520 531 7 30 804060List 2 = 75 110 8 10 90 9 Apply insertion sort on each sublist
  • 10. Ver. 1.0 Shell Sort Implementing Shell Sort Algorithm (Contd.) List 1 = 420 6 10 704520 531 7 30 806040List 2 = 75 110 8 10 90 9 The lists are now sorted
  • 11. Ver. 1.0 Shell Sort Implementing Shell Sort Algorithm (Contd.) List 1 = 420 6 10 704520 531 7 30 806040List 2 = 75 110 8 10 90 9 210 43 10 402030 45arr 60 5 6 7 8 9 10 70 80 75 90 110
  • 12. Ver. 1.0 Shell Sort Implementing Shell Sort Algorithm (Contd.) 210 43 10 402030 45arr 60 5 6 7 8 9 10 70 80 75 90 110 Increment = 1 Pass = 3 Apply insertion sort to sort the list
  • 13. Ver. 1.0 Shell Sort Implementing Shell Sort Algorithm (Contd.) 210 43 10 403020 45arr 60 5 6 7 8 9 10 70 75 80 90 110 Increment = 1 Pass = 3 The list is now sorted
  • 14. Ver. 1.0 Shell Sort Which of the following sorting algorithms compares the elements separated by a distance of several positions to sort the data? The options are: 1. Insertion sort 2. Selection sort 3. Bubble sort 4. Shell sort Just a minute Answer: 4. Shell sort
  • 15. Ver. 1.0 Shell Sort In this session, you learned that: Sorting is a process of arranging data in some pre-defined order of a key value. The order can be either ascending or descending. There are various sorting algorithms that are used to sort data. Some of them are: Bubble sort Selection sort Insertion sort Shell sort Merge sort Quick sort Heap sort Summary
  • 16. Ver. 1.0 Shell Sort To select an appropriate algorithm, you need to consider the following: Execution time Storage space Programming effort Bubble sort and selection algorithms have a quadratic order of growth, and are therefore suitable for sorting small lists only. Insertion sort performs different number of comparisons depending on the initial ordering of elements. When the elements are already in the sorted order, insertion sort needs to make very few comparisons. Insertion sort is an efficient algorithm than bubble sort and selection sort if the list that needs to be sorted is nearly sorted. Summary (Contd.)
  • 17. Ver. 1.0 Shell Sort Shell sort improves insertion sort by comparing the elements separated by a distance of several positions. This helps an element to take a bigger step towards its correct position, thereby reducing the number of comparisons. Summary (Contd.)

Editor's Notes

  1. Ask students to answer this question and then come to the given example.
  2. Ask students to answer this question and then come to the given example.
  3. Ask students to answer this question and then come to the given example.
  4. Ask students to answer this question and then come to the given example.
  5. Ask students to answer this question and then come to the given example.
  6. Ask students to answer this question and then come to the given example.
  7. Ask students to answer this question and then come to the given example.
  8. Ask students to answer this question and then come to the given example.
  9. Ask students to answer this question and then come to the given example.
  10. Ask students to answer this question and then come to the given example.
  11. Ask students to answer this question and then come to the given example.
  12. Ask students to answer this question and then come to the given example.
  13. Ask students to answer this question and then come to the given example.
  14. In this slide you need to show the calculation to determine the sum of an arithmetic progression for bubble sort algorithm. Refer to student guide.