SlideShare a Scribd company logo
1 of 3
Download to read offline
Sorting Arrays
• There are many different algorithms for sorting arrays, some are easier to code and some have a
faster computation time.
• Why sort an array?
– In some cases, especially when searching for elements in an array, it is beneficial to sort your
array in lexicographical order. This could greatly reduce time spent searching through an array as
you will see later.
• The 2 main sorting algorithms for arrays are:
– Selection Sort
– Bubble Sort
Selection Sort
• Consider having an array: {5, 7, 2, 15, 3}
• Step 1 of the selection sort algorithm is to find the smallest value, which is 2.
• Step 2, swap the value with the first position, which would give us: {2, 7, 5, 15, 3}
• Repeating these steps we find that 3 is the next smallest number, when we swap it for the next
position we get: {2, 3, 5, 15, 7}
• We would repeat this until the array is sorted or to be more specific when we reach array.
length -1 at which point if the second last element was smaller than the last we would swap and
the array would be sorted otherwise the array is sorted.
{2, 3, 5, 7, 15}
Bubble Sort
• Bubble sort, also known as exchange sort, is another sorting algorithm that is fairly simple but
very inefficient on large lists.
• The algorithm works as follows:
1. Compare 2 adjacent values (those at indexes 0 and 1)
2. If they are in the wrong order, swap them
3. Continue this with the next two adjacent values (those at indexes 1 and 2) and on through the
rest of the list.
4. Repeat steps 1 through 3 until array is sorted.
This video is a great visual representation of how this algorithm works:
https://www.youtube.com/watch?v=lyZQPjUT5B4
Consider this array: {40, 7, 59, 4, 1}
• Following the steps of the algorithm, after the first step of comparing and swapping the first
two values we have: {7, 40, 59, 4, 1}
• Then we compare and swap the next two values and get:
• Notice that the swap didn't occur in the second comparison. This is because they are already in
the correct order. {7, 40, 59, 4, 1}
• These steps are repeated until finally we get a sorted array: {1, 4, 7, 40, 59}
Sorting arrays

More Related Content

What's hot

Selection Sort - Vipin Ramola
Selection Sort - Vipin RamolaSelection Sort - Vipin Ramola
Selection Sort - Vipin RamolaDipayan Sarkar
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSGokul Hari
 
Statistics and Graphs
Statistics and GraphsStatistics and Graphs
Statistics and Graphssusan70
 
Arrays in c unit iii chapter 1 mrs.sowmya jyothi
Arrays in c unit iii chapter 1 mrs.sowmya jyothiArrays in c unit iii chapter 1 mrs.sowmya jyothi
Arrays in c unit iii chapter 1 mrs.sowmya jyothiSowmya Jyothi
 
Presentation on the topic selection sort
Presentation on the topic selection sortPresentation on the topic selection sort
Presentation on the topic selection sortDistrict Administration
 
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 applicationsyazad dumasia
 
Bubble sort | Data structure |
Bubble sort | Data structure |Bubble sort | Data structure |
Bubble sort | Data structure |MdSaiful14
 
Application of Matrices on Cryptography
Application of Matrices on CryptographyApplication of Matrices on Cryptography
Application of Matrices on CryptographyRam Gupta
 
lecture 9
lecture 9lecture 9
lecture 9sajinsc
 
Excel text functions
Excel text functionsExcel text functions
Excel text functionsKevin McLogan
 
10th algebra-lesson 1- part 1
10th algebra-lesson 1- part 110th algebra-lesson 1- part 1
10th algebra-lesson 1- part 1Amrita Kulthe
 
Daa contents by B.Kirron Reddi
Daa contents by B.Kirron ReddiDaa contents by B.Kirron Reddi
Daa contents by B.Kirron ReddiB.Kirron Reddi
 
Verifying Solutions of a Linear System
Verifying Solutions of a Linear SystemVerifying Solutions of a Linear System
Verifying Solutions of a Linear Systemdmidgette
 
Chapter 14 quick_sort
Chapter 14 quick_sortChapter 14 quick_sort
Chapter 14 quick_sortTerry Yoast
 

What's hot (20)

Fem in matlab
Fem in matlabFem in matlab
Fem in matlab
 
Merge sort js
Merge sort jsMerge sort js
Merge sort js
 
Insertion and Redix Sort
Insertion and Redix SortInsertion and Redix Sort
Insertion and Redix Sort
 
Quick sort
Quick sortQuick sort
Quick sort
 
Selection Sort - Vipin Ramola
Selection Sort - Vipin RamolaSelection Sort - Vipin Ramola
Selection Sort - Vipin Ramola
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
System of Linear Equation
System of Linear EquationSystem of Linear Equation
System of Linear Equation
 
Statistics and Graphs
Statistics and GraphsStatistics and Graphs
Statistics and Graphs
 
Arrays in c unit iii chapter 1 mrs.sowmya jyothi
Arrays in c unit iii chapter 1 mrs.sowmya jyothiArrays in c unit iii chapter 1 mrs.sowmya jyothi
Arrays in c unit iii chapter 1 mrs.sowmya jyothi
 
Presentation on the topic selection sort
Presentation on the topic selection sortPresentation on the topic selection sort
Presentation on the topic selection sort
 
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
 
Bubble sort | Data structure |
Bubble sort | Data structure |Bubble sort | Data structure |
Bubble sort | Data structure |
 
Application of Matrices on Cryptography
Application of Matrices on CryptographyApplication of Matrices on Cryptography
Application of Matrices on Cryptography
 
lecture 9
lecture 9lecture 9
lecture 9
 
Determinant
DeterminantDeterminant
Determinant
 
Excel text functions
Excel text functionsExcel text functions
Excel text functions
 
10th algebra-lesson 1- part 1
10th algebra-lesson 1- part 110th algebra-lesson 1- part 1
10th algebra-lesson 1- part 1
 
Daa contents by B.Kirron Reddi
Daa contents by B.Kirron ReddiDaa contents by B.Kirron Reddi
Daa contents by B.Kirron Reddi
 
Verifying Solutions of a Linear System
Verifying Solutions of a Linear SystemVerifying Solutions of a Linear System
Verifying Solutions of a Linear System
 
Chapter 14 quick_sort
Chapter 14 quick_sortChapter 14 quick_sort
Chapter 14 quick_sort
 

Viewers also liked

McDuffie-QMM article, African and Black Diaspora, July 2010
McDuffie-QMM article, African and Black Diaspora, July 2010McDuffie-QMM article, African and Black Diaspora, July 2010
McDuffie-QMM article, African and Black Diaspora, July 2010Erik McDuffie
 
DIRETRIZES DE POLÍTICAS PARA A APRENDIZAGEM MÓVEL
DIRETRIZES DE POLÍTICAS PARA A APRENDIZAGEM MÓVELDIRETRIZES DE POLÍTICAS PARA A APRENDIZAGEM MÓVEL
DIRETRIZES DE POLÍTICAS PARA A APRENDIZAGEM MÓVELNatalie Jenifer
 
Informatica grupo # 5
Informatica grupo # 5Informatica grupo # 5
Informatica grupo # 5Anahí Pérez
 
protein dockinng for ABL1 gene
protein dockinng for ABL1 geneprotein dockinng for ABL1 gene
protein dockinng for ABL1 geneshayezkarim
 
Ascend A5 2pp postcard
Ascend A5 2pp postcardAscend A5 2pp postcard
Ascend A5 2pp postcardKal Sangha
 
Centres Cívics Lloret 2015_16
Centres Cívics Lloret 2015_16 Centres Cívics Lloret 2015_16
Centres Cívics Lloret 2015_16 SOM Lloret
 
this, these, that, those
this, these, that, thosethis, these, that, those
this, these, that, thoseAditya Hernawan
 
Industrial Refrigeration Equipments by Bombay Ammonia Refrigeration Company N...
Industrial Refrigeration Equipments by Bombay Ammonia Refrigeration Company N...Industrial Refrigeration Equipments by Bombay Ammonia Refrigeration Company N...
Industrial Refrigeration Equipments by Bombay Ammonia Refrigeration Company N...IndiaMART InterMESH Limited
 
A10 slide deck: A10 Networks Brings Brawn to Stop Multi-Vector DDoS Disruptio...
A10 slide deck: A10 Networks Brings Brawn to Stop Multi-Vector DDoS Disruptio...A10 slide deck: A10 Networks Brings Brawn to Stop Multi-Vector DDoS Disruptio...
A10 slide deck: A10 Networks Brings Brawn to Stop Multi-Vector DDoS Disruptio...A10 Networks
 
Session 02 – animation particle basics
Session 02 – animation particle basicsSession 02 – animation particle basics
Session 02 – animation particle basicsTrí Bằng
 

Viewers also liked (15)

McDuffie-QMM article, African and Black Diaspora, July 2010
McDuffie-QMM article, African and Black Diaspora, July 2010McDuffie-QMM article, African and Black Diaspora, July 2010
McDuffie-QMM article, African and Black Diaspora, July 2010
 
DIRETRIZES DE POLÍTICAS PARA A APRENDIZAGEM MÓVEL
DIRETRIZES DE POLÍTICAS PARA A APRENDIZAGEM MÓVELDIRETRIZES DE POLÍTICAS PARA A APRENDIZAGEM MÓVEL
DIRETRIZES DE POLÍTICAS PARA A APRENDIZAGEM MÓVEL
 
Informatica grupo # 5
Informatica grupo # 5Informatica grupo # 5
Informatica grupo # 5
 
protein dockinng for ABL1 gene
protein dockinng for ABL1 geneprotein dockinng for ABL1 gene
protein dockinng for ABL1 gene
 
Presentatie jobbeurs
Presentatie jobbeursPresentatie jobbeurs
Presentatie jobbeurs
 
the little mermaid
the little mermaidthe little mermaid
the little mermaid
 
Наукові записки СумДПУ імені А.С. Макаренка. Серія географічні науки
Наукові записки СумДПУ імені А.С. Макаренка. Серія географічні наукиНаукові записки СумДПУ імені А.С. Макаренка. Серія географічні науки
Наукові записки СумДПУ імені А.С. Макаренка. Серія географічні науки
 
Ascend A5 2pp postcard
Ascend A5 2pp postcardAscend A5 2pp postcard
Ascend A5 2pp postcard
 
9 nguyen tac xay dung phan hoi
9 nguyen tac xay dung phan hoi9 nguyen tac xay dung phan hoi
9 nguyen tac xay dung phan hoi
 
Centres Cívics Lloret 2015_16
Centres Cívics Lloret 2015_16 Centres Cívics Lloret 2015_16
Centres Cívics Lloret 2015_16
 
Guía de redondeo
Guía de redondeoGuía de redondeo
Guía de redondeo
 
this, these, that, those
this, these, that, thosethis, these, that, those
this, these, that, those
 
Industrial Refrigeration Equipments by Bombay Ammonia Refrigeration Company N...
Industrial Refrigeration Equipments by Bombay Ammonia Refrigeration Company N...Industrial Refrigeration Equipments by Bombay Ammonia Refrigeration Company N...
Industrial Refrigeration Equipments by Bombay Ammonia Refrigeration Company N...
 
A10 slide deck: A10 Networks Brings Brawn to Stop Multi-Vector DDoS Disruptio...
A10 slide deck: A10 Networks Brings Brawn to Stop Multi-Vector DDoS Disruptio...A10 slide deck: A10 Networks Brings Brawn to Stop Multi-Vector DDoS Disruptio...
A10 slide deck: A10 Networks Brings Brawn to Stop Multi-Vector DDoS Disruptio...
 
Session 02 – animation particle basics
Session 02 – animation particle basicsSession 02 – animation particle basics
Session 02 – animation particle basics
 

Similar to Sorting arrays

sorting-160810203705.pptx
sorting-160810203705.pptxsorting-160810203705.pptx
sorting-160810203705.pptxAnSHiKa187943
 
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 exampleVivek487417
 
Sorting-algorithmbhddcbjkmbgjkuygbjkkius.pdf
Sorting-algorithmbhddcbjkmbgjkuygbjkkius.pdfSorting-algorithmbhddcbjkmbgjkuygbjkkius.pdf
Sorting-algorithmbhddcbjkmbgjkuygbjkkius.pdfArjunSingh81957
 
Class13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdfClass13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdfAkashSingh625550
 
Sorting types and Algorithms
Sorting types and AlgorithmsSorting types and Algorithms
Sorting types and AlgorithmsAli Khan
 
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 hashing concepts
Sorting and hashing conceptsSorting and hashing concepts
Sorting and hashing conceptsLJ Projects
 
Sorting and hashing concepts
Sorting and hashing conceptsSorting and hashing concepts
Sorting and hashing conceptsLJ Projects
 
SORTING techniques.pptx
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptxDr.Shweta
 
Lecture 11.2 : sorting
Lecture 11.2 :  sortingLecture 11.2 :  sorting
Lecture 11.2 : sortingVivek Bhargav
 
Radix and Merge Sort
Radix and Merge SortRadix and Merge Sort
Radix and Merge SortGelo Maribbay
 
Analysis of Algorithm (Bubblesort and Quicksort)
Analysis of Algorithm (Bubblesort and Quicksort)Analysis of Algorithm (Bubblesort and Quicksort)
Analysis of Algorithm (Bubblesort and Quicksort)Flynce Miguel
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting AlgorithmsPranay Neema
 

Similar to Sorting arrays (20)

sorting-160810203705.pptx
sorting-160810203705.pptxsorting-160810203705.pptx
sorting-160810203705.pptx
 
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
 
Sorting-algorithmbhddcbjkmbgjkuygbjkkius.pdf
Sorting-algorithmbhddcbjkmbgjkuygbjkkius.pdfSorting-algorithmbhddcbjkmbgjkuygbjkkius.pdf
Sorting-algorithmbhddcbjkmbgjkuygbjkkius.pdf
 
Class13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdfClass13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdf
 
Sorting types and Algorithms
Sorting types and AlgorithmsSorting types and Algorithms
Sorting types and Algorithms
 
day 13.pptx
day 13.pptxday 13.pptx
day 13.pptx
 
Sorting
SortingSorting
Sorting
 
16 mergesort
16 mergesort16 mergesort
16 mergesort
 
Algo PPT.pdf
Algo PPT.pdfAlgo PPT.pdf
Algo PPT.pdf
 
Sorting
SortingSorting
Sorting
 
data_structure_Chapter two_computer.pptx
data_structure_Chapter two_computer.pptxdata_structure_Chapter two_computer.pptx
data_structure_Chapter two_computer.pptx
 
sorting-160810203705.pptx
sorting-160810203705.pptxsorting-160810203705.pptx
sorting-160810203705.pptx
 
Sorting and hashing concepts
Sorting and hashing conceptsSorting and hashing concepts
Sorting and hashing concepts
 
Sorting and hashing concepts
Sorting and hashing conceptsSorting and hashing concepts
Sorting and hashing concepts
 
SORTING techniques.pptx
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptx
 
Lecture 11.2 : sorting
Lecture 11.2 :  sortingLecture 11.2 :  sorting
Lecture 11.2 : sorting
 
Radix and Merge Sort
Radix and Merge SortRadix and Merge Sort
Radix and Merge Sort
 
Analysis of Algorithm (Bubblesort and Quicksort)
Analysis of Algorithm (Bubblesort and Quicksort)Analysis of Algorithm (Bubblesort and Quicksort)
Analysis of Algorithm (Bubblesort and Quicksort)
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
presentation.pptx
 presentation.pptx presentation.pptx
presentation.pptx
 

Recently uploaded

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
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
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
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
 
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
 
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
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
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
 

Recently uploaded (20)

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
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
 
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🔝
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
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
 
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
 
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
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
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
 
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
 

Sorting arrays

  • 1. Sorting Arrays • There are many different algorithms for sorting arrays, some are easier to code and some have a faster computation time. • Why sort an array? – In some cases, especially when searching for elements in an array, it is beneficial to sort your array in lexicographical order. This could greatly reduce time spent searching through an array as you will see later. • The 2 main sorting algorithms for arrays are: – Selection Sort – Bubble Sort Selection Sort • Consider having an array: {5, 7, 2, 15, 3} • Step 1 of the selection sort algorithm is to find the smallest value, which is 2. • Step 2, swap the value with the first position, which would give us: {2, 7, 5, 15, 3} • Repeating these steps we find that 3 is the next smallest number, when we swap it for the next position we get: {2, 3, 5, 15, 7} • We would repeat this until the array is sorted or to be more specific when we reach array. length -1 at which point if the second last element was smaller than the last we would swap and the array would be sorted otherwise the array is sorted. {2, 3, 5, 7, 15}
  • 2. Bubble Sort • Bubble sort, also known as exchange sort, is another sorting algorithm that is fairly simple but very inefficient on large lists. • The algorithm works as follows: 1. Compare 2 adjacent values (those at indexes 0 and 1) 2. If they are in the wrong order, swap them 3. Continue this with the next two adjacent values (those at indexes 1 and 2) and on through the rest of the list. 4. Repeat steps 1 through 3 until array is sorted. This video is a great visual representation of how this algorithm works: https://www.youtube.com/watch?v=lyZQPjUT5B4 Consider this array: {40, 7, 59, 4, 1} • Following the steps of the algorithm, after the first step of comparing and swapping the first two values we have: {7, 40, 59, 4, 1} • Then we compare and swap the next two values and get: • Notice that the swap didn't occur in the second comparison. This is because they are already in the correct order. {7, 40, 59, 4, 1} • These steps are repeated until finally we get a sorted array: {1, 4, 7, 40, 59}