SlideShare a Scribd company logo
4
#Example:
Given array: 34 8 64 51 32 21
sorted comparison item unsorted
comparison time
0 1 2 3 4 5
Most read
5
*pass 1: compare 1st position with minimum item
After pass1
*pass2: compare 2nd position with next minimum item
After pass2
34 8 64 51 21
8
34 64 51 218
34 64 51 21
8 21 64 51 34
Most read
7
*Algorithm:
Algorithm SELECTION(A,N)
Step1 : Repeat steps 2 and 3 for k=1,2,….N-1;
Step2 : Call MIN(A,K,N,LOC).
Step3: [Interchange A[k] and A[LOC].]
Set TEMP:=A[k],
A[k]:=A[LOC] and
A[LOC]:=TEMP.
[End of step 1 loop]
Step4:Exit.
Most read
Selection sort algorithm presentation, selection sort example using power point
#Presentation submitted to:
Sohrab Hossain, Assistant professor of CSE
FSET,USTC
#Presentation submitted by:
Md Abdul Kuddus
Department of CSE
ID:15010102
Batch:25th
#Presentation Name:
Write a program to sort the element of
an array using selection sort.
#What is selection sort??
 Repeatedly searches for the largest value in a section of the
data
 Moves that value into its correct position in a sorted
section of the list
 Uses the Find Largest algorithm
#Example:
Given array: 34 8 64 51 32 21
sorted comparison item unsorted
comparison time
0 1 2 3 4 5
*pass 1: compare 1st position with minimum item
After pass1
*pass2: compare 2nd position with next minimum item
After pass2
34 8 64 51 21
8
34 64 51 218
34 64 51 21
8 21 64 51 34
*pass3: compare 3rd position with next minimum item
After pass3
*pass4: compare 4th position with next minimum item
After pass4
Array is sorted
8 21 64 51 34
8 21 34 51 64
8 21 34 51 64
8 21 34 51 64
*Algorithm:
Algorithm SELECTION(A,N)
Step1 : Repeat steps 2 and 3 for k=1,2,….N-1;
Step2 : Call MIN(A,K,N,LOC).
Step3: [Interchange A[k] and A[LOC].]
Set TEMP:=A[k],
A[k]:=A[LOC] and
A[LOC]:=TEMP.
[End of step 1 loop]
Step4:Exit.
#source code:
#include <stdio.h>
int *selectionSort(int A[],int n)
{
int j ,k ,temp;
for (k= 0; k < n; k++)
{
for(j = k+1; j < n; j++)
{
if(A[k] > A[j])
{
temp = A[k];
A[k] = A[j];
A[j] = temp;
}
}
}
return A;
}
int main()
{
int A[1000],k,n;
printf("Enter the number of element you want to Sort : ");
scanf("%d",&n);
printf("Enter Elements in the list : ");
for(k = 0; k < n; k++)
{
scanf("%d",&A[k]);
}
int *sortArray = selectionSort(A,n);
printf("Sorted list : ");
for(k = 0; k < n; k++ )
{
printf("%dt",sortArray[k]);
}
}
#Time efficiency
 Comparisons: n(n-1)/2
 Exchanges: n (swapping largest into place)
 Overall: (n2), best and worst cases
#Space efficiency
 Space for the input sequence, plus a constant number of local
variables
Selection sort algorithm presentation, selection sort example using power point

More Related Content

What's hot (20)

SORTING techniques.pptx
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptx
Dr.Shweta
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
DurgaDeviCbit
 
Insertion Sorting
Insertion SortingInsertion Sorting
Insertion Sorting
FarihaHabib123
 
Quick sort
Quick sortQuick sort
Quick sort
Jehat Hassan
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
MAHALAKSHMI P
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
anooppjoseph
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data Structures
SHAKOOR AB
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
Vineeta Garg
 
Stack
StackStack
Stack
Seema Sharma
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
Meghaj Mallick
 
Ppt bubble sort
Ppt bubble sortPpt bubble sort
Ppt bubble sort
prabhakar jalasutram
 
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...
Umesh Kumar
 
Insertion sort bubble sort selection sort
Insertion sort bubble sort  selection sortInsertion sort bubble sort  selection sort
Insertion sort bubble sort selection sort
Ummar Hayat
 
Searching and sorting
Searching  and sortingSearching  and sorting
Searching and sorting
PoojithaBollikonda
 
Insertion sort algorithm power point presentation
Insertion  sort algorithm power point presentation Insertion  sort algorithm power point presentation
Insertion sort algorithm power point presentation
University of Science and Technology Chitttagong
 
Insertion sort
Insertion sort Insertion sort
Insertion sort
Monalisa Patel
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Balwant Gorad
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
Trupti Agrawal
 
Data Types - Premetive and Non Premetive
Data Types - Premetive and Non Premetive Data Types - Premetive and Non Premetive
Data Types - Premetive and Non Premetive
Raj Naik
 
Data structures
Data structuresData structures
Data structures
Sneha Chopra
 
SORTING techniques.pptx
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptx
Dr.Shweta
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
DurgaDeviCbit
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
MAHALAKSHMI P
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
anooppjoseph
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data Structures
SHAKOOR AB
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
Meghaj Mallick
 
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...
Umesh Kumar
 
Insertion sort bubble sort selection sort
Insertion sort bubble sort  selection sortInsertion sort bubble sort  selection sort
Insertion sort bubble sort selection sort
Ummar Hayat
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Balwant Gorad
 
Data Types - Premetive and Non Premetive
Data Types - Premetive and Non Premetive Data Types - Premetive and Non Premetive
Data Types - Premetive and Non Premetive
Raj Naik
 

Similar to Selection sort algorithm presentation, selection sort example using power point (20)

Data structure using c module 3
Data structure using c module 3Data structure using c module 3
Data structure using c module 3
smruti sarangi
 
DSA-sortijejjejjdjjdjdjjsjsjsjsjsjsjng.pptx
DSA-sortijejjejjdjjdjdjjsjsjsjsjsjsjng.pptxDSA-sortijejjejjdjjdjdjjsjsjsjsjsjsjng.pptx
DSA-sortijejjejjdjjdjdjjsjsjsjsjsjsjng.pptx
suryatom5775
 
Searching_Sorting.pptx
Searching_Sorting.pptxSearching_Sorting.pptx
Searching_Sorting.pptx
21BD1A058RSahithi
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
Delowar Hossain
 
Chapter 3 - Elementary Searching and Sorting Algorithms.ppt
Chapter 3 - Elementary Searching and Sorting Algorithms.pptChapter 3 - Elementary Searching and Sorting Algorithms.ppt
Chapter 3 - Elementary Searching and Sorting Algorithms.ppt
AbdisaAwel
 
CHAP 3 ALGORITHM for infomatique ingenieure .ppt
CHAP 3 ALGORITHM for infomatique ingenieure .pptCHAP 3 ALGORITHM for infomatique ingenieure .ppt
CHAP 3 ALGORITHM for infomatique ingenieure .ppt
FarahHarrathi1
 
Unit III Version I.pptx
Unit III Version I.pptxUnit III Version I.pptx
Unit III Version I.pptx
ssuserd602fd
 
lecture-k-sorting.ppt
lecture-k-sorting.pptlecture-k-sorting.ppt
lecture-k-sorting.ppt
SushantRaj25
 
3.ppt
3.ppt3.ppt
3.ppt
ganeshyadav184128
 
Lecture k-sorting
Lecture k-sortingLecture k-sorting
Lecture k-sorting
Vijayaraj Raj
 
Sorting and Searching Techniques
Sorting and Searching TechniquesSorting and Searching Techniques
Sorting and Searching Techniques
Prof Ansari
 
lecture to proide studeny with F-k-sorting.ppt
lecture to proide studeny with F-k-sorting.pptlecture to proide studeny with F-k-sorting.ppt
lecture to proide studeny with F-k-sorting.ppt
indranilbanerji25109
 
advanced searching and sorting.pdf
advanced searching and sorting.pdfadvanced searching and sorting.pdf
advanced searching and sorting.pdf
haramaya university
 
Data Structures_ Sorting & Searching
Data Structures_ Sorting & SearchingData Structures_ Sorting & Searching
Data Structures_ Sorting & Searching
ThenmozhiK5
 
DS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxDS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptx
prakashvs7
 
Chapter3.pptx
Chapter3.pptxChapter3.pptx
Chapter3.pptx
ASMAALWADEE2
 
Searching and sorting Techniques in Data structures
Searching and sorting Techniques in Data structuresSearching and sorting Techniques in Data structures
Searching and sorting Techniques in Data structures
PRIANKA R
 
Sorting and hashing concepts
Sorting and hashing conceptsSorting and hashing concepts
Sorting and hashing concepts
LJ Projects
 
Sorting and hashing concepts
Sorting and hashing conceptsSorting and hashing concepts
Sorting and hashing concepts
LJ Projects
 
Address calculation-sort
Address calculation-sortAddress calculation-sort
Address calculation-sort
Vasim Pathan
 
Data structure using c module 3
Data structure using c module 3Data structure using c module 3
Data structure using c module 3
smruti sarangi
 
DSA-sortijejjejjdjjdjdjjsjsjsjsjsjsjng.pptx
DSA-sortijejjejjdjjdjdjjsjsjsjsjsjsjng.pptxDSA-sortijejjejjdjjdjdjjsjsjsjsjsjsjng.pptx
DSA-sortijejjejjdjjdjdjjsjsjsjsjsjsjng.pptx
suryatom5775
 
Chapter 3 - Elementary Searching and Sorting Algorithms.ppt
Chapter 3 - Elementary Searching and Sorting Algorithms.pptChapter 3 - Elementary Searching and Sorting Algorithms.ppt
Chapter 3 - Elementary Searching and Sorting Algorithms.ppt
AbdisaAwel
 
CHAP 3 ALGORITHM for infomatique ingenieure .ppt
CHAP 3 ALGORITHM for infomatique ingenieure .pptCHAP 3 ALGORITHM for infomatique ingenieure .ppt
CHAP 3 ALGORITHM for infomatique ingenieure .ppt
FarahHarrathi1
 
Unit III Version I.pptx
Unit III Version I.pptxUnit III Version I.pptx
Unit III Version I.pptx
ssuserd602fd
 
lecture-k-sorting.ppt
lecture-k-sorting.pptlecture-k-sorting.ppt
lecture-k-sorting.ppt
SushantRaj25
 
Sorting and Searching Techniques
Sorting and Searching TechniquesSorting and Searching Techniques
Sorting and Searching Techniques
Prof Ansari
 
lecture to proide studeny with F-k-sorting.ppt
lecture to proide studeny with F-k-sorting.pptlecture to proide studeny with F-k-sorting.ppt
lecture to proide studeny with F-k-sorting.ppt
indranilbanerji25109
 
advanced searching and sorting.pdf
advanced searching and sorting.pdfadvanced searching and sorting.pdf
advanced searching and sorting.pdf
haramaya university
 
Data Structures_ Sorting & Searching
Data Structures_ Sorting & SearchingData Structures_ Sorting & Searching
Data Structures_ Sorting & Searching
ThenmozhiK5
 
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 and sorting Techniques in Data structures
Searching and sorting Techniques in Data structuresSearching and sorting Techniques in Data structures
Searching and sorting Techniques in Data structures
PRIANKA R
 
Sorting and hashing concepts
Sorting and hashing conceptsSorting and hashing concepts
Sorting and hashing concepts
LJ Projects
 
Sorting and hashing concepts
Sorting and hashing conceptsSorting and hashing concepts
Sorting and hashing concepts
LJ Projects
 
Address calculation-sort
Address calculation-sortAddress calculation-sort
Address calculation-sort
Vasim Pathan
 
Ad

Recently uploaded (20)

Engineering Mechanics Introduction and its Application
Engineering Mechanics Introduction and its ApplicationEngineering Mechanics Introduction and its Application
Engineering Mechanics Introduction and its Application
Sakthivel M
 
Flow Chart Proses Bisnis prosscesss.docx
Flow Chart Proses Bisnis prosscesss.docxFlow Chart Proses Bisnis prosscesss.docx
Flow Chart Proses Bisnis prosscesss.docx
rifka575530
 
Great power lithium iron phosphate cells
Great power lithium iron phosphate cellsGreat power lithium iron phosphate cells
Great power lithium iron phosphate cells
salmankhan835951
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdfRearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
最新版美国圣莫尼卡学院毕业证(SMC毕业证书)原版定制
最新版美国圣莫尼卡学院毕业证(SMC毕业证书)原版定制最新版美国圣莫尼卡学院毕业证(SMC毕业证书)原版定制
最新版美国圣莫尼卡学院毕业证(SMC毕业证书)原版定制
Taqyea
 
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
SharinAbGhani1
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
djiceramil
 
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journeyRigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Yannis
 
chemistry investigatory project for class 12
chemistry investigatory project for class 12chemistry investigatory project for class 12
chemistry investigatory project for class 12
Susis10
 
Water demand - Types , variations and WDS
Water demand - Types , variations and WDSWater demand - Types , variations and WDS
Water demand - Types , variations and WDS
dhanashree78
 
社内勉強会資料_Chain of Thought .
社内勉強会資料_Chain of Thought                           .社内勉強会資料_Chain of Thought                           .
社内勉強会資料_Chain of Thought .
NABLAS株式会社
 
SEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair KitSEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair Kit
projectultramechanix
 
TEA2016AAT 160 W TV application design example
TEA2016AAT 160 W TV application design exampleTEA2016AAT 160 W TV application design example
TEA2016AAT 160 W TV application design example
ssuser1be9ce
 
operationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagementoperationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagement
SNIGDHAAPPANABHOTLA
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
djiceramil
 
IntroSlides-June-GDG-Cloud-Munich community [email protected]
IntroSlides-June-GDG-Cloud-Munich community gathering@Netlight.pdfIntroSlides-June-GDG-Cloud-Munich community gathering@Netlight.pdf
IntroSlides-June-GDG-Cloud-Munich community [email protected]
Luiz Carneiro
 
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
Journal of Soft Computing in Civil Engineering
 
grade 9 science q1 quiz.pptx science quiz
grade 9 science q1 quiz.pptx science quizgrade 9 science q1 quiz.pptx science quiz
grade 9 science q1 quiz.pptx science quiz
norfapangolima
 
22PCOAM16 _ML_Unit 3 Notes & Question bank
22PCOAM16 _ML_Unit 3 Notes & Question bank22PCOAM16 _ML_Unit 3 Notes & Question bank
22PCOAM16 _ML_Unit 3 Notes & Question bank
Guru Nanak Technical Institutions
 
Engineering Mechanics Introduction and its Application
Engineering Mechanics Introduction and its ApplicationEngineering Mechanics Introduction and its Application
Engineering Mechanics Introduction and its Application
Sakthivel M
 
Flow Chart Proses Bisnis prosscesss.docx
Flow Chart Proses Bisnis prosscesss.docxFlow Chart Proses Bisnis prosscesss.docx
Flow Chart Proses Bisnis prosscesss.docx
rifka575530
 
Great power lithium iron phosphate cells
Great power lithium iron phosphate cellsGreat power lithium iron phosphate cells
Great power lithium iron phosphate cells
salmankhan835951
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdfRearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
最新版美国圣莫尼卡学院毕业证(SMC毕业证书)原版定制
最新版美国圣莫尼卡学院毕业证(SMC毕业证书)原版定制最新版美国圣莫尼卡学院毕业证(SMC毕业证书)原版定制
最新版美国圣莫尼卡学院毕业证(SMC毕业证书)原版定制
Taqyea
 
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
SharinAbGhani1
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
djiceramil
 
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journeyRigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Yannis
 
chemistry investigatory project for class 12
chemistry investigatory project for class 12chemistry investigatory project for class 12
chemistry investigatory project for class 12
Susis10
 
Water demand - Types , variations and WDS
Water demand - Types , variations and WDSWater demand - Types , variations and WDS
Water demand - Types , variations and WDS
dhanashree78
 
社内勉強会資料_Chain of Thought .
社内勉強会資料_Chain of Thought                           .社内勉強会資料_Chain of Thought                           .
社内勉強会資料_Chain of Thought .
NABLAS株式会社
 
SEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair KitSEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair Kit
projectultramechanix
 
TEA2016AAT 160 W TV application design example
TEA2016AAT 160 W TV application design exampleTEA2016AAT 160 W TV application design example
TEA2016AAT 160 W TV application design example
ssuser1be9ce
 
operationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagementoperationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagement
SNIGDHAAPPANABHOTLA
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
djiceramil
 
grade 9 science q1 quiz.pptx science quiz
grade 9 science q1 quiz.pptx science quizgrade 9 science q1 quiz.pptx science quiz
grade 9 science q1 quiz.pptx science quiz
norfapangolima
 
Ad

Selection sort algorithm presentation, selection sort example using power point

  • 2. #Presentation submitted to: Sohrab Hossain, Assistant professor of CSE FSET,USTC #Presentation submitted by: Md Abdul Kuddus Department of CSE ID:15010102 Batch:25th
  • 3. #Presentation Name: Write a program to sort the element of an array using selection sort. #What is selection sort??  Repeatedly searches for the largest value in a section of the data  Moves that value into its correct position in a sorted section of the list  Uses the Find Largest algorithm
  • 4. #Example: Given array: 34 8 64 51 32 21 sorted comparison item unsorted comparison time 0 1 2 3 4 5
  • 5. *pass 1: compare 1st position with minimum item After pass1 *pass2: compare 2nd position with next minimum item After pass2 34 8 64 51 21 8 34 64 51 218 34 64 51 21 8 21 64 51 34
  • 6. *pass3: compare 3rd position with next minimum item After pass3 *pass4: compare 4th position with next minimum item After pass4 Array is sorted 8 21 64 51 34 8 21 34 51 64 8 21 34 51 64 8 21 34 51 64
  • 7. *Algorithm: Algorithm SELECTION(A,N) Step1 : Repeat steps 2 and 3 for k=1,2,….N-1; Step2 : Call MIN(A,K,N,LOC). Step3: [Interchange A[k] and A[LOC].] Set TEMP:=A[k], A[k]:=A[LOC] and A[LOC]:=TEMP. [End of step 1 loop] Step4:Exit.
  • 8. #source code: #include <stdio.h> int *selectionSort(int A[],int n) { int j ,k ,temp; for (k= 0; k < n; k++) { for(j = k+1; j < n; j++) { if(A[k] > A[j]) { temp = A[k]; A[k] = A[j]; A[j] = temp; } } } return A; }
  • 9. int main() { int A[1000],k,n; printf("Enter the number of element you want to Sort : "); scanf("%d",&n); printf("Enter Elements in the list : "); for(k = 0; k < n; k++) { scanf("%d",&A[k]); } int *sortArray = selectionSort(A,n); printf("Sorted list : "); for(k = 0; k < n; k++ ) { printf("%dt",sortArray[k]); } }
  • 10. #Time efficiency  Comparisons: n(n-1)/2  Exchanges: n (swapping largest into place)  Overall: (n2), best and worst cases #Space efficiency  Space for the input sequence, plus a constant number of local variables