SlideShare a Scribd company logo
3
Most read
4
Most read
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

PPTX
Shell sort in Data Structure Using C
PPT
Queue Data Structure
PPTX
Hashing Technique In Data Structures
PPTX
Bucket sort- A Noncomparision Algorithm
PPT
Indexing Data Structure
PPTX
Hash table
PPTX
Searching
Shell sort in Data Structure Using C
Queue Data Structure
Hashing Technique In Data Structures
Bucket sort- A Noncomparision Algorithm
Indexing Data Structure
Hash table
Searching

What's hot (20)

PDF
Array linear data_structure_2 (1)
PPTX
My lectures circular queue
PPT
Data Structures - Searching & sorting
PPT
Data structure lecture 5
PPTX
Ppt on Linked list,stack,queue
PPT
Stack a Data Structure
PPT
Heap sort
PPT
Data Structure and Algorithms Binary Search Tree
PPTX
Linked list in Data Structure and Algorithm
PPTX
Quick Sort
PDF
linked lists in data structures
PPTX
Data structure & its types
PPTX
Merge sort algorithm power point presentation
PPTX
Analysis of Algorithm (Bubblesort and Quicksort)
PPT
3.9 external sorting
PDF
Searching and Sorting Techniques in Data Structure
PPT
Shell sort
PPT
Linked lists
PPTX
linked list in data structure
PPTX
Priority queue in DSA
Array linear data_structure_2 (1)
My lectures circular queue
Data Structures - Searching & sorting
Data structure lecture 5
Ppt on Linked list,stack,queue
Stack a Data Structure
Heap sort
Data Structure and Algorithms Binary Search Tree
Linked list in Data Structure and Algorithm
Quick Sort
linked lists in data structures
Data structure & its types
Merge sort algorithm power point presentation
Analysis of Algorithm (Bubblesort and Quicksort)
3.9 external sorting
Searching and Sorting Techniques in Data Structure
Shell sort
Linked lists
linked list in data structure
Priority queue in DSA
Ad

Similar to Shell sort (20)

PPTX
It elective cs366-barizo-shell
PPTX
Shellshort ppt
PPTX
SHELL SORT-2.pptx
PPT
Sorting Techniques
PPT
Shell sorting
 
PPTX
Lecture 1 sorting insertion & shell sort
PPT
sorting_part1.ppt
PPTX
Shell sort by group .pptx kkjskanjkkanank
PPT
Is sort andy-le
PPT
Shell sort
PPTX
Analysis and Design of Algorithms -Sorting Algorithms and analysis
PPTX
Radix and Shell sort
PPTX
Sorting Techniques for Data Structures.pptx
PPT
3.3 shell sort
PPT
Chapter 6 - Advanced Sorting Algorithms (1).ppt
PPTX
sorting algorithm graphical method
PPTX
DSA-sortijejjejjdjjdjdjjsjsjsjsjsjsjng.pptx
PPTX
It elective-4-buendia lagua
PPTX
Shell Sort and Selection Sort Algorithm
PPTX
shell and merge sort
 
It elective cs366-barizo-shell
Shellshort ppt
SHELL SORT-2.pptx
Sorting Techniques
Shell sorting
 
Lecture 1 sorting insertion & shell sort
sorting_part1.ppt
Shell sort by group .pptx kkjskanjkkanank
Is sort andy-le
Shell sort
Analysis and Design of Algorithms -Sorting Algorithms and analysis
Radix and Shell sort
Sorting Techniques for Data Structures.pptx
3.3 shell sort
Chapter 6 - Advanced Sorting Algorithms (1).ppt
sorting algorithm graphical method
DSA-sortijejjejjdjjdjdjjsjsjsjsjsjsjng.pptx
It elective-4-buendia lagua
Shell Sort and Selection Sort Algorithm
shell and merge sort
 
Ad

More from M Vishnuvardhan Reddy (20)

PPTX
Python Sets_Dictionary.pptx
PPTX
Lists_tuples.pptx
PPTX
Python Control Structures.pptx
PPTX
Python Strings.pptx
PPTX
Python Basics.pptx
PPTX
Python Operators.pptx
PPTX
Python Datatypes.pptx
PPTX
DataScience.pptx
PPT
PPT
Cascading Style Sheets
PPT
Java Threads
PPT
Java Streams
PPT
Scanner class
PPT
Polymorphism
PPT
PPT
Java applets
PPT
Exception handling
PPT
Control structures
PPT
Constructors
PPT
Classes&objects
Python Sets_Dictionary.pptx
Lists_tuples.pptx
Python Control Structures.pptx
Python Strings.pptx
Python Basics.pptx
Python Operators.pptx
Python Datatypes.pptx
DataScience.pptx
Cascading Style Sheets
Java Threads
Java Streams
Scanner class
Polymorphism
Java applets
Exception handling
Control structures
Constructors
Classes&objects

Recently uploaded (20)

PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
PPTX
Trending Python Topics for Data Visualization in 2025
DOCX
How to Use SharePoint as an ISO-Compliant Document Management System
PDF
How Tridens DevSecOps Ensures Compliance, Security, and Agility
PPTX
Computer Software and OS of computer science of grade 11.pptx
PPTX
Weekly report ppt - harsh dattuprasad patel.pptx
PDF
Digital Systems & Binary Numbers (comprehensive )
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PPTX
Advanced SystemCare Ultimate Crack + Portable (2025)
PDF
Salesforce Agentforce AI Implementation.pdf
PDF
Complete Guide to Website Development in Malaysia for SMEs
PDF
Autodesk AutoCAD Crack Free Download 2025
PDF
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PPTX
Monitoring Stack: Grafana, Loki & Promtail
PDF
Topaz Photo AI Crack New Download (Latest 2025)
PDF
Cost to Outsource Software Development in 2025
PDF
STL Containers in C++ : Sequence Container : Vector
PDF
Time Tracking Features That Teams and Organizations Actually Need
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
Trending Python Topics for Data Visualization in 2025
How to Use SharePoint as an ISO-Compliant Document Management System
How Tridens DevSecOps Ensures Compliance, Security, and Agility
Computer Software and OS of computer science of grade 11.pptx
Weekly report ppt - harsh dattuprasad patel.pptx
Digital Systems & Binary Numbers (comprehensive )
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Advanced SystemCare Ultimate Crack + Portable (2025)
Salesforce Agentforce AI Implementation.pdf
Complete Guide to Website Development in Malaysia for SMEs
Autodesk AutoCAD Crack Free Download 2025
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
Monitoring Stack: Grafana, Loki & Promtail
Topaz Photo AI Crack New Download (Latest 2025)
Cost to Outsource Software Development in 2025
STL Containers in C++ : Sequence Container : Vector
Time Tracking Features That Teams and Organizations Actually Need
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency

Shell sort

  • 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

  • #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: Ask students to answer this question and then come to the given example.
  • #15: 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.