SlideShare une entreprise Scribd logo
1  sur  15
GROUP 4
Objectives
Define sorting.
Types of sorting.
Selection Sort
Exchange Sort
Insertion Sort
What is Sorting ?
is the process of placing elements from a collection in some kind
of order.
refers to ordering data in an increasing or decreasing fashion
according to some linear relationship among the data items.
can be done on names, numbers and records. For example, it is
relatively easy to look up the phone number of a friend from a
telephone dictionary because the names in the phone book have
been sorted into alphabetical order.
Types of Sorting
Selection Sort
Exchange Sort
Insertion Sort
SELECTION SORT
In this method, sorting is done by inserting elements into
an existing sorted list. Initially, the sorted list has only one
element. Other elements are gradually added into the list
in the proper position.

In this technique, the first element is selected and
compared with all other elements. If any other element is
less than the first element swapping should take place. By
the end of this comparison, the least element most top
position in the array.
This is known as pass1. In pass II, the second element is
selected and compared with all other elements. Swapping
takes place if any other element is less than selected element.
This process continuous until array is sorted.
EXAMPLE :
9 2 5 7 4 8 on pass 1 look for smallest in 1st to 6th swap 2nd
with first giving
2 9 5 7 4 8 on pass 2 look for smallest in 2nd to 6th swap 5th
with second giving
2 4 5 7 9 8 on pass 3 look for smallest in 3rd to 6th swap 3rd
with third giving
2 4 5 7 9 8 on pass 4 look for smallest in 4th to 6th swap 4th
with fourth giving
2 4 5 7 9 8 on pass 5 look for smallest in 5th to 6th swap 5th
with 6th giving
2 4 5 7 8 9 sorted.
EXCHANGE SORT
The exchange sort is almost similar as the bubble sort. In fact
some people refer to the exchange sort as just a different bubble
sort. The exchange sort compares each element of an array and
swap those elements that are not in their proper position, just like
a bubble sort does. The only difference between the two sorting
algorithms is the manner in which they compare the elements.
The exchange sort compares the first element with each element
of the array, making a swap where is necessary.
EXAMPLE :

9 2 5 4 7 8 compare 1st & 2nd ->
2 9 5 4 7 8 compare 2nd & 3rd ->
2 5 9 4 7 8 compare 3rd & 4th ->
2 5 4 9 7 8 compare 4th & 5th ->
2 5 4 7 9 8 compare 5th & 6th ->
254789
1. Compare the first pair of numbers (positions 0 and 1) and
reverse them if they are not in the correct order.
2. Repeat for the next pair (positions 1 and 2).
3. Continue the process until all pairs have been checked.
4. Repeat steps 1 through 3 for positions 0 through n - 1 to i
(for i = 1, 2, 3, ...) until no pairs remain to be checked.
5. The list is now sorted.
INSERTION SORT
is an efficient algorithm for sorting a small number of
elements. Insertion sort works the same way as one would sort
a bridge or gin rummy hand, i.e. starting with an empty left
hand and the cards face down on the table. One card at a time
is then removed from the table and inserted into the correct
position in the left hand. To find the correct position for a card,
it is compared with each of the cards already in the hand,
from right to left.
12

Insertion Sort
To insert 12, we need to
make room for it by
moving first 36 and then
24.
13

Insertion Sort
14

Insertion Sort
Data Structures and Algorithms

Contenu connexe

Tendances

Tendances (20)

Selection sorting
Selection sortingSelection sorting
Selection sorting
 
Joins in databases
Joins in databases Joins in databases
Joins in databases
 
sorting and its types
sorting and its typessorting and its types
sorting and its types
 
Selection Sort - Vipin Ramola
Selection Sort - Vipin RamolaSelection Sort - Vipin Ramola
Selection Sort - Vipin Ramola
 
merge_sort
merge_sortmerge_sort
merge_sort
 
joins in database
 joins in database joins in database
joins in database
 
FRACTIONS
FRACTIONSFRACTIONS
FRACTIONS
 
Selection sort algorithm presentation, selection sort example using power point
Selection sort algorithm presentation, selection sort example using power point Selection sort algorithm presentation, selection sort example using power point
Selection sort algorithm presentation, selection sort example using power point
 
Joins in dbms and types
Joins in dbms and typesJoins in dbms and types
Joins in dbms and types
 
Types Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql ServerTypes Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql Server
 
Insertion and merge sort
Insertion and merge sortInsertion and merge sort
Insertion and merge sort
 
Relational algebra
Relational algebraRelational algebra
Relational algebra
 
Math chapter 3 fractional exponent
Math chapter 3 fractional exponentMath chapter 3 fractional exponent
Math chapter 3 fractional exponent
 
Wednesdayweek7student
Wednesdayweek7studentWednesdayweek7student
Wednesdayweek7student
 
Join
JoinJoin
Join
 
Matrix
MatrixMatrix
Matrix
 
Unit v data structure-converted
Unit  v data structure-convertedUnit  v data structure-converted
Unit v data structure-converted
 
Sorting method data structure
Sorting method data structureSorting method data structure
Sorting method data structure
 
Sql joins inner join self join outer joins
Sql joins inner join self join outer joinsSql joins inner join self join outer joins
Sql joins inner join self join outer joins
 
Searching in c language
Searching in c languageSearching in c language
Searching in c language
 

En vedette (9)

Sorting insertion-sort
Sorting   insertion-sortSorting   insertion-sort
Sorting insertion-sort
 
Lecture 11.2 : sorting
Lecture 11.2 :  sortingLecture 11.2 :  sorting
Lecture 11.2 : sorting
 
Sorting Seminar Presentation by Ashin Guha Majumder
Sorting Seminar Presentation by Ashin Guha MajumderSorting Seminar Presentation by Ashin Guha Majumder
Sorting Seminar Presentation by Ashin Guha Majumder
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
lecture 9
lecture 9lecture 9
lecture 9
 
Sorting (introduction)
 Sorting (introduction) Sorting (introduction)
Sorting (introduction)
 
asymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysisasymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysis
 
Sorting Things Out: An Introduction to Card Sorting
Sorting Things Out: An Introduction to Card SortingSorting Things Out: An Introduction to Card Sorting
Sorting Things Out: An Introduction to Card Sorting
 
Insertion Sort
Insertion SortInsertion Sort
Insertion Sort
 

Similaire à 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
Vivek487417
 
Sorting algorithums > Data Structures & Algorithums
Sorting algorithums  > Data Structures & AlgorithumsSorting algorithums  > Data Structures & Algorithums
Sorting algorithums > Data Structures & Algorithums
Ain-ul-Moiz Khawaja
 
DS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxDS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptx
prakashvs7
 
Searching Sorting
Searching SortingSearching Sorting
Searching Sorting
guest2cb109
 

Similaire à Data Structures and Algorithms (20)

Sorting Data structure And Algorithm.pptx
Sorting Data structure And Algorithm.pptxSorting Data structure And Algorithm.pptx
Sorting Data structure And Algorithm.pptx
 
Selection Sort and Insertion Sort
Selection Sort and Insertion SortSelection Sort and Insertion Sort
Selection Sort and Insertion Sort
 
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
 
advanced searching and sorting.pdf
advanced searching and sorting.pdfadvanced searching and sorting.pdf
advanced searching and sorting.pdf
 
Searching & Sorting Algorithms
Searching & Sorting AlgorithmsSearching & Sorting Algorithms
Searching & Sorting Algorithms
 
Data structure using c module 3
Data structure using c module 3Data structure using c module 3
Data structure using c module 3
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
Sorting algorithm
Sorting algorithmSorting algorithm
Sorting algorithm
 
Selection-sort-in-algorithm and complexity.pptx
Selection-sort-in-algorithm and complexity.pptxSelection-sort-in-algorithm and complexity.pptx
Selection-sort-in-algorithm and complexity.pptx
 
MODULE 5-Searching and-sorting
MODULE 5-Searching and-sortingMODULE 5-Searching and-sorting
MODULE 5-Searching and-sorting
 
Sorting algorithums > Data Structures & Algorithums
Sorting algorithums  > Data Structures & AlgorithumsSorting algorithums  > Data Structures & Algorithums
Sorting algorithums > Data Structures & Algorithums
 
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...
 
Data Structures_ Sorting & Searching
Data Structures_ Sorting & SearchingData Structures_ Sorting & Searching
Data Structures_ Sorting & Searching
 
DS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxDS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptx
 
366 it elective 4 (analysis of algoritm)
366 it elective 4 (analysis of algoritm)366 it elective 4 (analysis of algoritm)
366 it elective 4 (analysis of algoritm)
 
Searching Sorting
Searching SortingSearching Sorting
Searching Sorting
 
sorting and searching.pptx
sorting and searching.pptxsorting and searching.pptx
sorting and searching.pptx
 
Sorting
SortingSorting
Sorting
 
Sorting
SortingSorting
Sorting
 
SORTING techniques.pptx
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptx
 

Dernier

Financial Accounting IFRS, 3rd Edition-dikompresi.pdf
Financial Accounting IFRS, 3rd Edition-dikompresi.pdfFinancial Accounting IFRS, 3rd Edition-dikompresi.pdf
Financial Accounting IFRS, 3rd Edition-dikompresi.pdf
MinawBelay
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 

Dernier (20)

ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptx
 
Financial Accounting IFRS, 3rd Edition-dikompresi.pdf
Financial Accounting IFRS, 3rd Edition-dikompresi.pdfFinancial Accounting IFRS, 3rd Edition-dikompresi.pdf
Financial Accounting IFRS, 3rd Edition-dikompresi.pdf
 
Software testing for project report .pdf
Software testing for project report .pdfSoftware testing for project report .pdf
Software testing for project report .pdf
 
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING II
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING IIII BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING II
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING II
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024
 
An Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxAn Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptx
 
....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf
 
Word Stress rules esl .pptx
Word Stress rules esl               .pptxWord Stress rules esl               .pptx
Word Stress rules esl .pptx
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 

Data Structures and Algorithms

  • 2. Objectives Define sorting. Types of sorting. Selection Sort Exchange Sort Insertion Sort
  • 3. What is Sorting ? is the process of placing elements from a collection in some kind of order. refers to ordering data in an increasing or decreasing fashion according to some linear relationship among the data items. can be done on names, numbers and records. For example, it is relatively easy to look up the phone number of a friend from a telephone dictionary because the names in the phone book have been sorted into alphabetical order.
  • 4. Types of Sorting Selection Sort Exchange Sort Insertion Sort
  • 5. SELECTION SORT In this method, sorting is done by inserting elements into an existing sorted list. Initially, the sorted list has only one element. Other elements are gradually added into the list in the proper position. In this technique, the first element is selected and compared with all other elements. If any other element is less than the first element swapping should take place. By the end of this comparison, the least element most top position in the array.
  • 6. This is known as pass1. In pass II, the second element is selected and compared with all other elements. Swapping takes place if any other element is less than selected element. This process continuous until array is sorted.
  • 7. EXAMPLE : 9 2 5 7 4 8 on pass 1 look for smallest in 1st to 6th swap 2nd with first giving 2 9 5 7 4 8 on pass 2 look for smallest in 2nd to 6th swap 5th with second giving 2 4 5 7 9 8 on pass 3 look for smallest in 3rd to 6th swap 3rd with third giving 2 4 5 7 9 8 on pass 4 look for smallest in 4th to 6th swap 4th with fourth giving 2 4 5 7 9 8 on pass 5 look for smallest in 5th to 6th swap 5th with 6th giving 2 4 5 7 8 9 sorted.
  • 8. EXCHANGE SORT The exchange sort is almost similar as the bubble sort. In fact some people refer to the exchange sort as just a different bubble sort. The exchange sort compares each element of an array and swap those elements that are not in their proper position, just like a bubble sort does. The only difference between the two sorting algorithms is the manner in which they compare the elements. The exchange sort compares the first element with each element of the array, making a swap where is necessary.
  • 9. EXAMPLE : 9 2 5 4 7 8 compare 1st & 2nd -> 2 9 5 4 7 8 compare 2nd & 3rd -> 2 5 9 4 7 8 compare 3rd & 4th -> 2 5 4 9 7 8 compare 4th & 5th -> 2 5 4 7 9 8 compare 5th & 6th -> 254789
  • 10. 1. Compare the first pair of numbers (positions 0 and 1) and reverse them if they are not in the correct order. 2. Repeat for the next pair (positions 1 and 2). 3. Continue the process until all pairs have been checked. 4. Repeat steps 1 through 3 for positions 0 through n - 1 to i (for i = 1, 2, 3, ...) until no pairs remain to be checked. 5. The list is now sorted.
  • 11. INSERTION SORT is an efficient algorithm for sorting a small number of elements. Insertion sort works the same way as one would sort a bridge or gin rummy hand, i.e. starting with an empty left hand and the cards face down on the table. One card at a time is then removed from the table and inserted into the correct position in the left hand. To find the correct position for a card, it is compared with each of the cards already in the hand, from right to left.
  • 12. 12 Insertion Sort To insert 12, we need to make room for it by moving first 36 and then 24.