SlideShare a Scribd company logo
1 of 14
1
 Introduction
 Sorting
 Selection Sort
 Bubble Sort
 Bubble Sorting:- Example
 Sorting and searching are fundamental
operations in computer science.
 Sorting refers to operation of arranging data
in some given order , such as increasing or
decreasing ,with numerical data or with
character data.
 Generally, collections of data are presented
in a sorted manner.
 Let A be a list of n elements A1,A2,……An in
Memory. Sorting A refers to the operation of
rearranging the contents of A so that they
are in increasing in order, so that
A1<A2<A3<…..<An
 Sorting = ordering.
 Sorted = ordered based on a particular way.
 Examples of Sorting:
 Words in a dictionary are sorted (and case
distinctions are ignored).
 Files in a directory are often listed in sorted
order.
 The index of a book is sorted (and case
distinctions are ignored).
 A relatively easy to understand algorithm
 Sorts an array in passes
 Each pass selects the next smallest element
 At the end of the pass, places it where it belongs
 Efficiency is O(n2
), hence called a quadratic
sort
 Performs:
 O(n2
) comparisons
 O(n) exchanges (swaps)
7
 Idea:
 Find the smallest element in the array
 Exchange it with the element in the first position
 Find the second smallest element and exchange it with
the element in the second position
 Continue until the array is sorted
 Disadvantage:
 Running time depends only slightly on the amount of
order in the file
35 65 30 60 20 scan 0-4, smallest
20
swap 35 and 20
20 65 30 60 35 scan 1-4, smallest
30
swap 65 and 30
20 30 65 60 35 scan 2-4, smallest
35
swap 65 and 35
20 30 35 60 65 scan 3-4, smallest
60
swap 60 and 60
20 30 35 60 65 done
1. for fill = 0 to n-2 do // steps 2-6 form a
pass
2. set posMin to fill
3. for next = fill+1 to n-1 do
4. if item at next < item at posMin
5. set posMin to next
6. Exchange item at posMin with one at
fill
 Let A be a list of n numbers. Sorting A refers to the
operation of rearranging the elements of A So they
are in increasing order ,So that,
A[1]<A[2]<A[3]<……….<A[N]
 Example :-
List is- 8,4,19,2,7,13,5,16
After Sorting :-
List is-2,4,5,7,8,13,16,19
 Suppose the following numbers are stored in
an array A:-
53,21,65,27,70,8,99,1.
Pass1-21,53,65,27,70,8,99,1
21,53,65,27,70,8,99,1
21,53,27,65,70,8,99,1
21,53,27,65,70,8,99,1
21,53,27,65,8,70,99,1
21,53,27,65,8,70,99,1
21,53,27,65,8,70,1,99
Pass2- 21,53,27,65,8,70,1,99
21,53,27,65,8,70,1,99
21,27,53,65,8,70,1,99
21,27,53,65,8,70,1,99
21,27,53,8,65,70,1,99
21,27,53,8,65,70,1,99
21,27,53,8,65,1,70,99
Pass3- 21,27,53,8,65,1,70,99
21,27,8,53,65,1,70,99
21,27,8,53,1,65,70,99
Pass4- 21,27,8,53,1,65,70,99
21,8,27,53,1,65,70,99
21,8,27,1,53,65,70,99
Pass5- 21,8,27,1,53,65,70,99
8,21,27,1,53,65,70,99
8,21,1,27,53,65,70,99
Pass6- 8,21,1,27,53,65,70,99
8,1,21,27,53,65,70,99
Pass7- 1,8,21,27,53,65,70,99
SORTED LIST IS:- 1,8,21,27,53,65,70,99
Sorting techniques

More Related Content

What's hot

What's hot (20)

Sorting Algorithm
Sorting AlgorithmSorting Algorithm
Sorting Algorithm
 
Data Structures- Part4 basic sorting algorithms
Data Structures- Part4 basic sorting algorithmsData Structures- Part4 basic sorting algorithms
Data Structures- Part4 basic sorting algorithms
 
Sorting algorithm
Sorting algorithmSorting algorithm
Sorting algorithm
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Sorting
SortingSorting
Sorting
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Sorting
SortingSorting
Sorting
 
Data Structures & Algorithm design using C
Data Structures & Algorithm design using C Data Structures & Algorithm design using C
Data Structures & Algorithm design using C
 
Insertion Sorting
Insertion SortingInsertion Sorting
Insertion Sorting
 
Searching & Sorting Algorithms
Searching & Sorting AlgorithmsSearching & Sorting Algorithms
Searching & Sorting Algorithms
 
Selection sort lab mannual
Selection sort lab mannualSelection sort lab mannual
Selection sort lab mannual
 
Merge sort analysis and its real time applications
Merge sort analysis and its real time applicationsMerge sort analysis and its real time applications
Merge sort analysis and its real time applications
 
Sorting algorithums > Data Structures & Algorithums
Sorting algorithums  > Data Structures & AlgorithumsSorting algorithums  > Data Structures & Algorithums
Sorting algorithums > Data Structures & Algorithums
 
3.9 external sorting
3.9 external sorting3.9 external sorting
3.9 external sorting
 
Sorting
SortingSorting
Sorting
 
Lecture 3 data structures & algorithms - sorting techniques - http://techiem...
Lecture 3  data structures & algorithms - sorting techniques - http://techiem...Lecture 3  data structures & algorithms - sorting techniques - http://techiem...
Lecture 3 data structures & algorithms - sorting techniques - http://techiem...
 
Sorting
SortingSorting
Sorting
 
Sorting
SortingSorting
Sorting
 
Analisys of Selection Sort and Bubble Sort
Analisys of Selection Sort and Bubble SortAnalisys of Selection Sort and Bubble Sort
Analisys of Selection Sort and Bubble Sort
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 

Similar to Sorting techniques

Similar to Sorting techniques (20)

Unit vii sorting
Unit   vii sorting Unit   vii sorting
Unit vii sorting
 
Sorting
SortingSorting
Sorting
 
Chapter 4 ds
Chapter 4 dsChapter 4 ds
Chapter 4 ds
 
Sorting
SortingSorting
Sorting
 
searching in data structure.pptx
searching in data structure.pptxsearching in data structure.pptx
searching in data structure.pptx
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Unit6 C
Unit6 C Unit6 C
Unit6 C
 
COMPUTER PROGRAMMING UNIT 1 Lecture 5
COMPUTER PROGRAMMING UNIT 1 Lecture 5COMPUTER PROGRAMMING UNIT 1 Lecture 5
COMPUTER PROGRAMMING UNIT 1 Lecture 5
 
Sorting
SortingSorting
Sorting
 
Sorting and Searching Techniques
Sorting and Searching TechniquesSorting and Searching Techniques
Sorting and Searching Techniques
 
Selection sort
Selection sortSelection sort
Selection sort
 
Lecture 13 data structures and algorithms
Lecture 13 data structures and algorithmsLecture 13 data structures and algorithms
Lecture 13 data structures and algorithms
 
Counting sort(Non Comparison Sort)
Counting sort(Non Comparison Sort)Counting sort(Non Comparison Sort)
Counting sort(Non Comparison Sort)
 
Counting Sort Lowerbound
Counting Sort LowerboundCounting Sort Lowerbound
Counting Sort Lowerbound
 
Data Structure (MC501)
Data Structure (MC501)Data Structure (MC501)
Data Structure (MC501)
 
lecture 10
lecture 10lecture 10
lecture 10
 
Sorting2
Sorting2Sorting2
Sorting2
 
Lec 03 - Sorting.pptx
Lec 03 - Sorting.pptxLec 03 - Sorting.pptx
Lec 03 - Sorting.pptx
 
Sorting
SortingSorting
Sorting
 
Address calculation-sort
Address calculation-sortAddress calculation-sort
Address calculation-sort
 

More from Lovely Professional University

The HyperText Markup Language or HTML is the standard markup language
The HyperText Markup Language or HTML is the standard markup languageThe HyperText Markup Language or HTML is the standard markup language
The HyperText Markup Language or HTML is the standard markup languageLovely Professional University
 

More from Lovely Professional University (20)

The HyperText Markup Language or HTML is the standard markup language
The HyperText Markup Language or HTML is the standard markup languageThe HyperText Markup Language or HTML is the standard markup language
The HyperText Markup Language or HTML is the standard markup language
 
Working with JSON
Working with JSONWorking with JSON
Working with JSON
 
Yargs Module
Yargs ModuleYargs Module
Yargs Module
 
NODEMON Module
NODEMON ModuleNODEMON Module
NODEMON Module
 
Getting Input from User
Getting Input from UserGetting Input from User
Getting Input from User
 
fs Module.pptx
fs Module.pptxfs Module.pptx
fs Module.pptx
 
Transaction Processing in DBMS.pptx
Transaction Processing in DBMS.pptxTransaction Processing in DBMS.pptx
Transaction Processing in DBMS.pptx
 
web_server_browser.ppt
web_server_browser.pptweb_server_browser.ppt
web_server_browser.ppt
 
Web Server.pptx
Web Server.pptxWeb Server.pptx
Web Server.pptx
 
Number System.pptx
Number System.pptxNumber System.pptx
Number System.pptx
 
Programming Language.ppt
Programming Language.pptProgramming Language.ppt
Programming Language.ppt
 
Information System.pptx
Information System.pptxInformation System.pptx
Information System.pptx
 
Applications of Computer Science in Pharmacy-1.pptx
Applications of Computer Science in Pharmacy-1.pptxApplications of Computer Science in Pharmacy-1.pptx
Applications of Computer Science in Pharmacy-1.pptx
 
Application of Computers in Pharmacy.pptx
Application of Computers in Pharmacy.pptxApplication of Computers in Pharmacy.pptx
Application of Computers in Pharmacy.pptx
 
Deploying your app.pptx
Deploying your app.pptxDeploying your app.pptx
Deploying your app.pptx
 
Setting up github and ssh keys.ppt
Setting up github and ssh keys.pptSetting up github and ssh keys.ppt
Setting up github and ssh keys.ppt
 
Adding a New Feature and Deploying.ppt
Adding a New Feature and Deploying.pptAdding a New Feature and Deploying.ppt
Adding a New Feature and Deploying.ppt
 
Requiring your own files.pptx
Requiring your own files.pptxRequiring your own files.pptx
Requiring your own files.pptx
 
Unit-2 Getting Input from User.pptx
Unit-2 Getting Input from User.pptxUnit-2 Getting Input from User.pptx
Unit-2 Getting Input from User.pptx
 
Yargs Module.pptx
Yargs Module.pptxYargs Module.pptx
Yargs Module.pptx
 

Recently uploaded

complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 

Recently uploaded (20)

complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 

Sorting techniques

  • 1. 1
  • 2.  Introduction  Sorting  Selection Sort  Bubble Sort  Bubble Sorting:- Example
  • 3.  Sorting and searching are fundamental operations in computer science.  Sorting refers to operation of arranging data in some given order , such as increasing or decreasing ,with numerical data or with character data.  Generally, collections of data are presented in a sorted manner.
  • 4.  Let A be a list of n elements A1,A2,……An in Memory. Sorting A refers to the operation of rearranging the contents of A so that they are in increasing in order, so that A1<A2<A3<…..<An
  • 5.  Sorting = ordering.  Sorted = ordered based on a particular way.  Examples of Sorting:  Words in a dictionary are sorted (and case distinctions are ignored).  Files in a directory are often listed in sorted order.  The index of a book is sorted (and case distinctions are ignored).
  • 6.  A relatively easy to understand algorithm  Sorts an array in passes  Each pass selects the next smallest element  At the end of the pass, places it where it belongs  Efficiency is O(n2 ), hence called a quadratic sort  Performs:  O(n2 ) comparisons  O(n) exchanges (swaps)
  • 7. 7  Idea:  Find the smallest element in the array  Exchange it with the element in the first position  Find the second smallest element and exchange it with the element in the second position  Continue until the array is sorted  Disadvantage:  Running time depends only slightly on the amount of order in the file
  • 8. 35 65 30 60 20 scan 0-4, smallest 20 swap 35 and 20 20 65 30 60 35 scan 1-4, smallest 30 swap 65 and 30 20 30 65 60 35 scan 2-4, smallest 35 swap 65 and 35 20 30 35 60 65 scan 3-4, smallest 60 swap 60 and 60 20 30 35 60 65 done
  • 9. 1. for fill = 0 to n-2 do // steps 2-6 form a pass 2. set posMin to fill 3. for next = fill+1 to n-1 do 4. if item at next < item at posMin 5. set posMin to next 6. Exchange item at posMin with one at fill
  • 10.  Let A be a list of n numbers. Sorting A refers to the operation of rearranging the elements of A So they are in increasing order ,So that, A[1]<A[2]<A[3]<……….<A[N]  Example :- List is- 8,4,19,2,7,13,5,16 After Sorting :- List is-2,4,5,7,8,13,16,19
  • 11.  Suppose the following numbers are stored in an array A:- 53,21,65,27,70,8,99,1. Pass1-21,53,65,27,70,8,99,1 21,53,65,27,70,8,99,1 21,53,27,65,70,8,99,1 21,53,27,65,70,8,99,1 21,53,27,65,8,70,99,1 21,53,27,65,8,70,99,1 21,53,27,65,8,70,1,99
  • 13. Pass4- 21,27,8,53,1,65,70,99 21,8,27,53,1,65,70,99 21,8,27,1,53,65,70,99 Pass5- 21,8,27,1,53,65,70,99 8,21,27,1,53,65,70,99 8,21,1,27,53,65,70,99 Pass6- 8,21,1,27,53,65,70,99 8,1,21,27,53,65,70,99 Pass7- 1,8,21,27,53,65,70,99 SORTED LIST IS:- 1,8,21,27,53,65,70,99