SlideShare a Scribd company logo
1 of 19
Sorting
• Arranging the data in a logical order
•
• Ascending order : is a method of arranging numbers from
smallest value to largest value.
• OR
• Descending order: is a method of arranging numbers from
largest value to smallest value.
Realtime applications:
1. While shopping on flipkart or amazon,
you sort items based on your choice, that is,
price low to high or high to low
2. The contact list in your phone is sorted, which means you can
easily access your desired contact from your phone since the
data is arranged in that manner for you. In other words, “it is
sorted”.
Different sorting techniques
• Insertion sort
• Selection sort
• Bubble sort
• Merge sort
• Quick sort
Insertion sort
• Logic: The array is considered into two parts
• Sorted and Unsorted.
• Initially, the sorted array contains zero (0) elements, and the unsorted
array contains n elements.
• Assume the first element (0th index) is sorted.
• Now sorted array contains 1 element, and unsorted contains n-1
elements
• Now consider the first element present in the unsorted and insert it
into the sorted array at the appropriate position (called insert into
position)
• Repeat the process until all the elements present in the array are in
sorted order.
• https://www.youtube.com/watch?v=OGzPmgsI-pQ
• Initial list: [5, 2, 4, 6, 1, 3]
• Start with the second element (2). Compare it with the first element
(5) and swap them since 2 is smaller. Updated list: [2, 5, 4, 6, 1, 3]
• Move to the third element (4) and compare it with the previous
elements (5, 2). Swap 4 with 5 and then with 2 to place it in the
correct position within the sorted portion. Updated list: [2, 4, 5, 6, 1,
3]
• Move to the fourth element (6). It's already greater than the previous
elements, so no swaps are necessary. Updated list: [2, 4, 5, 6, 1, 3]
• Move to the fifth element (1) and compare it with the previous
elements (6, 5, 4, 2). Swap it with each previous element until it
reaches its correct position. Updated list: [1, 2, 4, 5, 6, 3]
• Move to the last element (3) and compare it with the previous
elements (6, 5, 4, 2, 1). Swap it with each previous element until it
reaches its correct position. Updated list: [1, 2, 3, 4, 5, 6]
Selection sort:
• Logic: The array is considered into two parts
• unsorted and sorted
• initially the whole array is unsorted
• Step 1: Select the lowest element present in the array
• Step 2: Bring it into the starting position.
• Step 3: Change the counter for the unsorted array by one.
• Step 4: Repeat until all the elements are sorted.
• https://www.youtube.com/watch?v=xWBP4lzkoyM
• Initial list: [15, 12, 14, 16, 11, 13]
• Start with the first element (15). Assume it as the minimum.
• Scan through the remaining elements (12, 14, 16, 11, 13) and find the
smallest element, which is 11.
• Swap the minimum element (11) with the first element (15). Updated
list: [11, 12, 14, 16, 15, 13]
• Move to the next element (12) in the unsorted portion. Assume it as
the minimum.
• Scan through the remaining elements (14, 16, 15, 13) and find the
smallest element, which is 13.
• Swap the minimum element (13) with the second element (12).
Updated list: [11, 12, 14, 16, 15, 13]
• Repeat steps 4 to 6 until all elements are in their correct sorted
positions.
• Final sorted list: [11, 12, 13, 14, 15, 16]
Bubble sort:
• Bubble sort is a simple sorting algorithm.
• This sorting algorithm is a comparison-based algorithm
• i.e each pair of adjacent elements is compared, and the elements
are swapped if they are not in order.
• This algorithm is not suitable for large data sets.
• https://www.youtube.com/watch?v=nmhjrI-aW5o
•begin BubbleSort(list)
• for all elements of list
• if list[i] > list[i+1]
• swap(list[i], list[i+1])
• end if
• end for
• return list
•end BubbleSort
• 4 7 2 1 10 8 3 5 6 9
Merge sort:
• Merge sort is one of the most efficient sorting algorithms.
• It is based on the divide-and-conquer strategy.
• Merge sort continuously cuts down a list into multiple sub lists until
each has only one item, then merges those sub lists into a sorted list.
Merge sort:
• https://www.youtube.com/watch?v=5Z9dn2WTg9o
Quick sort
• The logic is simple, we start from the leftmost element and keep track
of the index of smaller (or equal) elements as i. While traversing, if we
find a smaller element, we swap the current element with arr[i].
Otherwise, we ignore the current element.
1.4 Sorting.pptx
1.4 Sorting.pptx

More Related Content

Similar to 1.4 Sorting.pptx

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 JYOTHISowmya Jyothi
 
Algo PPT.pdf
Algo PPT.pdfAlgo PPT.pdf
Algo PPT.pdfsheraz7288
 
Lec 03 - Sorting.pptx
Lec 03 - Sorting.pptxLec 03 - Sorting.pptx
Lec 03 - Sorting.pptxDr. Shaukat Wasi
 
data_structure_Chapter two_computer.pptx
data_structure_Chapter two_computer.pptxdata_structure_Chapter two_computer.pptx
data_structure_Chapter two_computer.pptxMohammed472103
 
sorting and searching.pptx
sorting and searching.pptxsorting and searching.pptx
sorting and searching.pptxParagAhir1
 
sorting-160810203705.pptx
sorting-160810203705.pptxsorting-160810203705.pptx
sorting-160810203705.pptxVarchasvaTiwari2
 
Data structures
Data structuresData structures
Data structuresSneha Chopra
 
DS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxDS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxprakashvs7
 
Data Structures_ Sorting & Searching
Data Structures_ Sorting & SearchingData Structures_ Sorting & Searching
Data Structures_ Sorting & SearchingThenmozhiK5
 
Data structure and algorithms
Data structure and algorithmsData structure and algorithms
Data structure and algorithmstechnologygyan
 
Data operatons & searching and sorting algorithms
Data operatons & searching and sorting algorithmsData operatons & searching and sorting algorithms
Data operatons & searching and sorting algorithmsAnushdika Jeganathan
 
Analysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysisAnalysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysisRadhika Talaviya
 
sorting-160810203705.pptx
sorting-160810203705.pptxsorting-160810203705.pptx
sorting-160810203705.pptxAnSHiKa187943
 
MODULE 5-Searching and-sorting
MODULE 5-Searching and-sortingMODULE 5-Searching and-sorting
MODULE 5-Searching and-sortingnikshaikh786
 
Sorting in python
Sorting in python Sorting in python
Sorting in python Simplilearn
 
searching in data structure.pptx
searching in data structure.pptxsearching in data structure.pptx
searching in data structure.pptxchouguleamruta24
 

Similar to 1.4 Sorting.pptx (20)

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
 
Sorting
SortingSorting
Sorting
 
Algo PPT.pdf
Algo PPT.pdfAlgo PPT.pdf
Algo PPT.pdf
 
Lec 03 - Sorting.pptx
Lec 03 - Sorting.pptxLec 03 - Sorting.pptx
Lec 03 - Sorting.pptx
 
data_structure_Chapter two_computer.pptx
data_structure_Chapter two_computer.pptxdata_structure_Chapter two_computer.pptx
data_structure_Chapter two_computer.pptx
 
sorting and searching.pptx
sorting and searching.pptxsorting and searching.pptx
sorting and searching.pptx
 
Lecture_Oct26.pptx
Lecture_Oct26.pptxLecture_Oct26.pptx
Lecture_Oct26.pptx
 
sorting-160810203705.pptx
sorting-160810203705.pptxsorting-160810203705.pptx
sorting-160810203705.pptx
 
Data structures
Data structuresData structures
Data structures
 
DS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxDS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptx
 
Data Structures_ Sorting & Searching
Data Structures_ Sorting & SearchingData Structures_ Sorting & Searching
Data Structures_ Sorting & Searching
 
Unit v data structure-converted
Unit  v data structure-convertedUnit  v data structure-converted
Unit v data structure-converted
 
Data structure and algorithms
Data structure and algorithmsData structure and algorithms
Data structure and algorithms
 
Data operatons & searching and sorting algorithms
Data operatons & searching and sorting algorithmsData operatons & searching and sorting algorithms
Data operatons & searching and sorting algorithms
 
Analysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysisAnalysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysis
 
sorting-160810203705.pptx
sorting-160810203705.pptxsorting-160810203705.pptx
sorting-160810203705.pptx
 
MODULE 5-Searching and-sorting
MODULE 5-Searching and-sortingMODULE 5-Searching and-sorting
MODULE 5-Searching and-sorting
 
Sorting
SortingSorting
Sorting
 
Sorting in python
Sorting in python Sorting in python
Sorting in python
 
searching in data structure.pptx
searching in data structure.pptxsearching in data structure.pptx
searching in data structure.pptx
 

More from Sujan527908

vastu tajmahal.pptx
vastu tajmahal.pptxvastu tajmahal.pptx
vastu tajmahal.pptxSujan527908
 
Operating system.pptx
Operating system.pptxOperating system.pptx
Operating system.pptxSujan527908
 
buildingby-laws-170216060116 ppt.pptx
buildingby-laws-170216060116 ppt.pptxbuildingby-laws-170216060116 ppt.pptx
buildingby-laws-170216060116 ppt.pptxSujan527908
 
2.4 Deletion of a node from single linked list.pptx
2.4 Deletion of a node from single linked list.pptx2.4 Deletion of a node from single linked list.pptx
2.4 Deletion of a node from single linked list.pptxSujan527908
 
silence.pptx
silence.pptxsilence.pptx
silence.pptxSujan527908
 
Stepper Motor .pptx
Stepper Motor .pptxStepper Motor .pptx
Stepper Motor .pptxSujan527908
 
freindhsipppt-191019124250.pptx
freindhsipppt-191019124250.pptxfreindhsipppt-191019124250.pptx
freindhsipppt-191019124250.pptxSujan527908
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptxSujan527908
 

More from Sujan527908 (8)

vastu tajmahal.pptx
vastu tajmahal.pptxvastu tajmahal.pptx
vastu tajmahal.pptx
 
Operating system.pptx
Operating system.pptxOperating system.pptx
Operating system.pptx
 
buildingby-laws-170216060116 ppt.pptx
buildingby-laws-170216060116 ppt.pptxbuildingby-laws-170216060116 ppt.pptx
buildingby-laws-170216060116 ppt.pptx
 
2.4 Deletion of a node from single linked list.pptx
2.4 Deletion of a node from single linked list.pptx2.4 Deletion of a node from single linked list.pptx
2.4 Deletion of a node from single linked list.pptx
 
silence.pptx
silence.pptxsilence.pptx
silence.pptx
 
Stepper Motor .pptx
Stepper Motor .pptxStepper Motor .pptx
Stepper Motor .pptx
 
freindhsipppt-191019124250.pptx
freindhsipppt-191019124250.pptxfreindhsipppt-191019124250.pptx
freindhsipppt-191019124250.pptx
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 

Recently uploaded

Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 

Recently uploaded (20)

Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 

1.4 Sorting.pptx

  • 2. • Arranging the data in a logical order • • Ascending order : is a method of arranging numbers from smallest value to largest value. • OR • Descending order: is a method of arranging numbers from largest value to smallest value.
  • 3. Realtime applications: 1. While shopping on flipkart or amazon, you sort items based on your choice, that is, price low to high or high to low 2. The contact list in your phone is sorted, which means you can easily access your desired contact from your phone since the data is arranged in that manner for you. In other words, “it is sorted”.
  • 4. Different sorting techniques • Insertion sort • Selection sort • Bubble sort • Merge sort • Quick sort
  • 5. Insertion sort • Logic: The array is considered into two parts • Sorted and Unsorted. • Initially, the sorted array contains zero (0) elements, and the unsorted array contains n elements. • Assume the first element (0th index) is sorted. • Now sorted array contains 1 element, and unsorted contains n-1 elements • Now consider the first element present in the unsorted and insert it into the sorted array at the appropriate position (called insert into position) • Repeat the process until all the elements present in the array are in sorted order. • https://www.youtube.com/watch?v=OGzPmgsI-pQ
  • 6. • Initial list: [5, 2, 4, 6, 1, 3] • Start with the second element (2). Compare it with the first element (5) and swap them since 2 is smaller. Updated list: [2, 5, 4, 6, 1, 3] • Move to the third element (4) and compare it with the previous elements (5, 2). Swap 4 with 5 and then with 2 to place it in the correct position within the sorted portion. Updated list: [2, 4, 5, 6, 1, 3] • Move to the fourth element (6). It's already greater than the previous elements, so no swaps are necessary. Updated list: [2, 4, 5, 6, 1, 3] • Move to the fifth element (1) and compare it with the previous elements (6, 5, 4, 2). Swap it with each previous element until it reaches its correct position. Updated list: [1, 2, 4, 5, 6, 3] • Move to the last element (3) and compare it with the previous elements (6, 5, 4, 2, 1). Swap it with each previous element until it reaches its correct position. Updated list: [1, 2, 3, 4, 5, 6]
  • 7. Selection sort: • Logic: The array is considered into two parts • unsorted and sorted • initially the whole array is unsorted • Step 1: Select the lowest element present in the array • Step 2: Bring it into the starting position. • Step 3: Change the counter for the unsorted array by one. • Step 4: Repeat until all the elements are sorted. • https://www.youtube.com/watch?v=xWBP4lzkoyM
  • 8. • Initial list: [15, 12, 14, 16, 11, 13] • Start with the first element (15). Assume it as the minimum. • Scan through the remaining elements (12, 14, 16, 11, 13) and find the smallest element, which is 11. • Swap the minimum element (11) with the first element (15). Updated list: [11, 12, 14, 16, 15, 13] • Move to the next element (12) in the unsorted portion. Assume it as the minimum. • Scan through the remaining elements (14, 16, 15, 13) and find the smallest element, which is 13. • Swap the minimum element (13) with the second element (12). Updated list: [11, 12, 14, 16, 15, 13] • Repeat steps 4 to 6 until all elements are in their correct sorted positions. • Final sorted list: [11, 12, 13, 14, 15, 16]
  • 9. Bubble sort: • Bubble sort is a simple sorting algorithm. • This sorting algorithm is a comparison-based algorithm • i.e each pair of adjacent elements is compared, and the elements are swapped if they are not in order. • This algorithm is not suitable for large data sets. • https://www.youtube.com/watch?v=nmhjrI-aW5o
  • 10.
  • 11. •begin BubbleSort(list) • for all elements of list • if list[i] > list[i+1] • swap(list[i], list[i+1]) • end if • end for • return list •end BubbleSort
  • 12. • 4 7 2 1 10 8 3 5 6 9
  • 13. Merge sort: • Merge sort is one of the most efficient sorting algorithms. • It is based on the divide-and-conquer strategy. • Merge sort continuously cuts down a list into multiple sub lists until each has only one item, then merges those sub lists into a sorted list.
  • 14.
  • 15.
  • 17. Quick sort • The logic is simple, we start from the leftmost element and keep track of the index of smaller (or equal) elements as i. While traversing, if we find a smaller element, we swap the current element with arr[i]. Otherwise, we ignore the current element.