SlideShare a Scribd company logo
1 of 18
Sorting and types of
sorting
Introduction
• Sorting refers to arranging aset of data in some
logicalorder
• For ex.Atelephone directory canbe considered
asalist where each record hasthree fields -
name, addressand phone number.
• Beingunique, phone number canwork asakeyto
locate anyrecord in the list.
Introduction
• Sorting is among the most basic problems in
algorithm design.
• Weare given asequence of items, eachassociated
with agiven key value.And the problem is to
rearrange the items sothat they are inan
increasing(or decreasing) order by key.
• Themethods of sorting canbe divided into two
categories:
• Internal Sorting
• ExternalSorting
• Internal Sorting
If all the data that is to be sorted can be adjusted at a
time in main memory, then internal sorting methods
areused
• ExternalSorting
When the data to be sorted can’t be accommodated in
the memory at the sametime and somehasto be kept
in auxiliary memory, then externalsorting methods are
used.
Stable and UnStable Sorting
• If asorting algorithm, after sorting the contents,
does notchange the sequence of similar content
in which they appear, it is called stable sorting.
• If asorting algorithm, after sorting the contents,
changesthe sequence of similar content in which
they appear, it is calledunstable sorting.
Efficiency of Sorting Algorithm
• Thecomplexity of asorting algorithm measures
the running time ofa function in which n number
of items are to be sorted.
• Thechoice of sorting method depends on
efficiency considerations for different problems.
• Treemost important of these considerationsare:
• Thelength of time spent by programmer in coding a
particular sortingprogram
• Amount of machine time necessaryfor running the
program
• Theamount of memory necessaryfor running the
program
Efficiency of Sorting Algorithm
• Various sorting methods are analyzedin the
caseslike – bestcase, worst caseor average
case.
• Most of the sort methods we consider have
requirements thatrange from 0(nlogn) to 0(n2).
• Asort should not be selected only becauseits
sorting time is0(nlogn); the relation of the file
sizen and the other factors affecting the actual
sorting time must beconsidered
Efficiency of Sorting Algorithm
• Determining the time requirement of sorting
technique is toactually run the program and
measure itsefficiency.
• Onceaparticular sorting technique is selected the
need is to makethe program asefficient as
possible.
• Anyimprovement in sorting time
significantly affect theoverall efficiency and
savesagreat deal of computer time.
Efficiency of Sorting Algorithm
• Spaceconstraints are usually lessimportant than
time considerations.
• Thereason for this canbe, asfor most sorting
programs, the amount of spaceneeded is closer
to 0(n) than to0(n2)
• Thesecond reason is that, if more spaceis
required, it canalmost alwaysbe found in
auxiliary storage.
Sorting Algorithms
 Selection Sort
 Bubble Sort
 Insertion Sort
 Shell Sort
 Heap Sort
 Counting Sort
 Radix Sort
 Bucket Sort
 Merge Sort
 Quick Sort
SELECTION SORT
•This sorting algorithm is an in-place
comparison based algorithm .
•In which the list is divided into two parts, the
sorted part at the left end and the unsorted part
at the right end.
• Initially, the sorted part is empty and the
unsorted part is the entire list
SELECTION SORT
•The smallest element is selected from the
unsorted array and swapped with the leftmost
element, and that element becomes a part of
the sorted array.
• This process continues moving unsorted array
boundary by one element to the right.
•Each time selecting an item according to its
ordering and placing it in the correct position in
the sequence.
Algorithm
 Step 1 − Set MIN to location 0 .
 Step 2 − Search the minimum element
in the list.
 Step 3 − Swap with value at location
MIN .
 Step 4 − Increment MIN to point to next
element.
 Step 5 − Repeat until list i0s sorted.
Complexity
 Best case performance О(n^2 )
 Average case performance О(n^2 )
 Worst case performance О(n^2 )
Advantages
 The main advantage of the selection
sort is that it performs well on a small
list.
 No additional temporary storage is
required.
Disadvantages
 The primary disadvantage of the
selection sort is its poor efficiency when
dealing with a huge list of items.
 The selection sort requires n squared
number of steps for sorting n elements.
THANK YOU

More Related Content

What's hot

Presentation on array
Presentation on array Presentation on array
Presentation on array
topu93
 

What's hot (20)

Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
 
Presentation on array
Presentation on array Presentation on array
Presentation on array
 
stack and queue array implementation in java.
stack and queue array implementation in java.stack and queue array implementation in java.
stack and queue array implementation in java.
 
Linked list
Linked listLinked list
Linked list
 
Insertion sort
Insertion sort Insertion sort
Insertion sort
 
Bubble sort
Bubble sortBubble sort
Bubble sort
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data Structures
 
Hash table
Hash tableHash table
Hash table
 
Ppt bubble sort
Ppt bubble sortPpt bubble sort
Ppt bubble sort
 
Sorting
SortingSorting
Sorting
 
Data structure and its types.
Data structure and its types.Data structure and its types.
Data structure and its types.
 
Linked list
Linked listLinked list
Linked list
 
Bubble sort | Data structure |
Bubble sort | Data structure |Bubble sort | Data structure |
Bubble sort | Data structure |
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Circular queue
Circular queueCircular queue
Circular queue
 
Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional
 
Quick Sort
Quick SortQuick Sort
Quick Sort
 
Linked list
Linked list Linked list
Linked list
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Priority queue in DSA
Priority queue in DSAPriority queue in DSA
Priority queue in DSA
 

Similar to Sorting And Type of Sorting

Unit II_Searching and Sorting Algorithms.ppt
Unit II_Searching and Sorting Algorithms.pptUnit II_Searching and Sorting Algorithms.ppt
Unit II_Searching and Sorting Algorithms.ppt
HODElex
 
Data Structure & Algorithms - Operations
Data Structure & Algorithms - OperationsData Structure & Algorithms - Operations
Data Structure & Algorithms - Operations
babuk110
 
DS PPT - ( 1 )SORTING lgoritham techniques with bast example
DS PPT - ( 1 )SORTING lgoritham techniques with bast exampleDS PPT - ( 1 )SORTING lgoritham techniques with bast example
DS PPT - ( 1 )SORTING lgoritham techniques with bast example
Vivek487417
 

Similar to Sorting And Type of Sorting (20)

Unit II_Searching and Sorting Algorithms.ppt
Unit II_Searching and Sorting Algorithms.pptUnit II_Searching and Sorting Algorithms.ppt
Unit II_Searching and Sorting Algorithms.ppt
 
Data structures and algorithms Module-1.pdf
Data structures and algorithms Module-1.pdfData structures and algorithms Module-1.pdf
Data structures and algorithms Module-1.pdf
 
Sorting
SortingSorting
Sorting
 
Sorting
SortingSorting
Sorting
 
CPP12 - Algorithms
CPP12 - AlgorithmsCPP12 - Algorithms
CPP12 - Algorithms
 
Data Structure & Algorithms - Operations
Data Structure & Algorithms - OperationsData Structure & Algorithms - Operations
Data Structure & Algorithms - Operations
 
Search and Sort algorithms. Bubble, Insertion, Selection.
Search and Sort algorithms. Bubble, Insertion, Selection.Search and Sort algorithms. Bubble, Insertion, Selection.
Search and Sort algorithms. Bubble, Insertion, Selection.
 
sorting-160810203705.pptx
sorting-160810203705.pptxsorting-160810203705.pptx
sorting-160810203705.pptx
 
Obstructive jaundice is a medical condition characterized by the yellowing of...
Obstructive jaundice is a medical condition characterized by the yellowing of...Obstructive jaundice is a medical condition characterized by the yellowing of...
Obstructive jaundice is a medical condition characterized by the yellowing of...
 
Basic concepts of data structures and algorithms
Basic concepts of data structures and algorithmsBasic concepts of data structures and algorithms
Basic concepts of data structures and algorithms
 
DS PPT - ( 1 )SORTING lgoritham techniques with bast example
DS PPT - ( 1 )SORTING lgoritham techniques with bast exampleDS PPT - ( 1 )SORTING lgoritham techniques with bast example
DS PPT - ( 1 )SORTING lgoritham techniques with bast example
 
data_structure_Chapter two_computer.pptx
data_structure_Chapter two_computer.pptxdata_structure_Chapter two_computer.pptx
data_structure_Chapter two_computer.pptx
 
Algorithm analysis (All in one)
Algorithm analysis (All in one)Algorithm analysis (All in one)
Algorithm analysis (All in one)
 
A Comparative Study of Sorting and Searching Algorithms
A Comparative Study of Sorting and Searching AlgorithmsA Comparative Study of Sorting and Searching Algorithms
A Comparative Study of Sorting and Searching Algorithms
 
Data Structures 6
Data Structures 6Data Structures 6
Data Structures 6
 
Unit 1 abstract data types
Unit 1 abstract data typesUnit 1 abstract data types
Unit 1 abstract data types
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
 
SORTING techniques.pptx
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptx
 
Algorithms and Data Structures
Algorithms and Data StructuresAlgorithms and Data Structures
Algorithms and Data Structures
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
 

Recently uploaded

Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
Kamal Acharya
 

Recently uploaded (20)

Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
 
fitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptfitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .ppt
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Signal Processing and Linear System Analysis
Signal Processing and Linear System AnalysisSignal Processing and Linear System Analysis
Signal Processing and Linear System Analysis
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Electromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxElectromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptx
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 

Sorting And Type of Sorting

  • 1. Sorting and types of sorting
  • 2. Introduction • Sorting refers to arranging aset of data in some logicalorder • For ex.Atelephone directory canbe considered asalist where each record hasthree fields - name, addressand phone number. • Beingunique, phone number canwork asakeyto locate anyrecord in the list.
  • 3. Introduction • Sorting is among the most basic problems in algorithm design. • Weare given asequence of items, eachassociated with agiven key value.And the problem is to rearrange the items sothat they are inan increasing(or decreasing) order by key. • Themethods of sorting canbe divided into two categories: • Internal Sorting • ExternalSorting
  • 4. • Internal Sorting If all the data that is to be sorted can be adjusted at a time in main memory, then internal sorting methods areused • ExternalSorting When the data to be sorted can’t be accommodated in the memory at the sametime and somehasto be kept in auxiliary memory, then externalsorting methods are used.
  • 5. Stable and UnStable Sorting • If asorting algorithm, after sorting the contents, does notchange the sequence of similar content in which they appear, it is called stable sorting. • If asorting algorithm, after sorting the contents, changesthe sequence of similar content in which they appear, it is calledunstable sorting.
  • 6. Efficiency of Sorting Algorithm • Thecomplexity of asorting algorithm measures the running time ofa function in which n number of items are to be sorted. • Thechoice of sorting method depends on efficiency considerations for different problems. • Treemost important of these considerationsare: • Thelength of time spent by programmer in coding a particular sortingprogram • Amount of machine time necessaryfor running the program • Theamount of memory necessaryfor running the program
  • 7. Efficiency of Sorting Algorithm • Various sorting methods are analyzedin the caseslike – bestcase, worst caseor average case. • Most of the sort methods we consider have requirements thatrange from 0(nlogn) to 0(n2). • Asort should not be selected only becauseits sorting time is0(nlogn); the relation of the file sizen and the other factors affecting the actual sorting time must beconsidered
  • 8. Efficiency of Sorting Algorithm • Determining the time requirement of sorting technique is toactually run the program and measure itsefficiency. • Onceaparticular sorting technique is selected the need is to makethe program asefficient as possible. • Anyimprovement in sorting time significantly affect theoverall efficiency and savesagreat deal of computer time.
  • 9. Efficiency of Sorting Algorithm • Spaceconstraints are usually lessimportant than time considerations. • Thereason for this canbe, asfor most sorting programs, the amount of spaceneeded is closer to 0(n) than to0(n2) • Thesecond reason is that, if more spaceis required, it canalmost alwaysbe found in auxiliary storage.
  • 10. Sorting Algorithms  Selection Sort  Bubble Sort  Insertion Sort  Shell Sort  Heap Sort  Counting Sort  Radix Sort  Bucket Sort  Merge Sort  Quick Sort
  • 11. SELECTION SORT •This sorting algorithm is an in-place comparison based algorithm . •In which the list is divided into two parts, the sorted part at the left end and the unsorted part at the right end. • Initially, the sorted part is empty and the unsorted part is the entire list
  • 12. SELECTION SORT •The smallest element is selected from the unsorted array and swapped with the leftmost element, and that element becomes a part of the sorted array. • This process continues moving unsorted array boundary by one element to the right. •Each time selecting an item according to its ordering and placing it in the correct position in the sequence.
  • 13.
  • 14. Algorithm  Step 1 − Set MIN to location 0 .  Step 2 − Search the minimum element in the list.  Step 3 − Swap with value at location MIN .  Step 4 − Increment MIN to point to next element.  Step 5 − Repeat until list i0s sorted.
  • 15. Complexity  Best case performance О(n^2 )  Average case performance О(n^2 )  Worst case performance О(n^2 )
  • 16. Advantages  The main advantage of the selection sort is that it performs well on a small list.  No additional temporary storage is required.
  • 17. Disadvantages  The primary disadvantage of the selection sort is its poor efficiency when dealing with a huge list of items.  The selection sort requires n squared number of steps for sorting n elements.