Sorting
Selection Sort
Umarfarooqworld@gmail.com
Selection Sort
0 1 2 3 4
int arr[5]={2,4,1,9,7};
Selection Sort
0 1 2 3 4
int arr[5]={2,4,1,9,7};
2 4 1 9 7
Selection Sort
0 1 2 3 4
int arr[5]={2,4,1,9,7};
2 4 1 9 7
int p,i,j,temp;
temp
Selection Sort
0 1 2 3 4
int arr[5]={2,4,1,9,7};
2 4 1 9 7
int p,i,j,temp;
for(i=0;i<5;i++)
temp
Selection Sort
0 1 2 3 4
int arr[5]={2,4,1,9,7};
2 4 1 9 7
int p,i,j,temp;
for(i=0;i<5;i++)
{
temp
Selection Sort
0 1 2 3 4
int arr[5]={2,4,1,9,7};
2 4 1 9 7
int p,i,j,temp;
for(i=0;i<5;i++)
{
p=i;
temp
Selection Sort
0 1 2 3 4
int arr[5]={2,4,1,9,7};
2 4 1 9 7
int p,i,j,temp;
for(i=0;i<5;i++)
{
p=i; P=0
temp
p=0
Selection Sort
0 1 2 3 4
int arr[5]={2,4,1,9,7};
2 4 1 9 7
int p,i,j,temp;
for(i=0;i<5;i++)
{
p=i;
p=0
for(j=i+1;j<5;j++) j-=1
temp
Selection Sort
0 1 2 3 4
int arr[5]={2,4,1,9,7};
2 4 1 9 7
int p,i,j,temp;
for(i=0;i<5;i++)
{
p=i;
p=0
for(j=i+1;j<5;j++)
if(arr[p]>arr[j])
temp
Selection Sort
0 1 2 3 4
int arr[5]={2,4,1,9,7};
2 4 1 9 7
int p,i,j,temp;
for(i=0;i<5;i++)
{
p=i;
p=0
for(j=i+1;j<5;j++)
if(arr[p]>arr[j]) false
p=j;
temp
Selection Sort
0 1 2 3 4
int arr[5]={2,4,1,9,7};
2 4 1 9 7
int p,i,j,temp;
for(i=0;i<5;i++)
{
p=i;
p=0
for(j=i+1;j<5;j++)
if(arr[p]>arr[j])
J=2
p=j;
temp
Selection Sort
0 1 2 3 4
int arr[5]={2,4,1,9,7};
2 4 1 9 7
int p,i,j,temp;
for(i=0;i<5;i++)
{
p=i;
p=0
for(j=i+1;j<5;j++)
if(arr[p]>arr[j]) true
p=j;
temp
Selection Sort
0 1 2 3 4
int arr[5]={2,4,1,9,7};
2 4 1 9 7
int p,i,j,temp;
for(i=0;i<5;i++)
{
p=i;
p=2
for(j=i+1;j<5;j++)
if(arr[p]>arr[j])
P=2
p=j;
temp
Selection Sort
0 1 2 3 4
int arr[5]={2,4,1,9,7};
2 4 1 9 7
int p,i,j,temp;
for(i=0;i<5;i++)
{
p=i;
p=2
for(j=i+1;j<5;j++)
if(arr[p]>arr[j])
J=3
p=j;
temp
Selection Sort
0 1 2 3 4
int arr[5]={2,4,1,9,7};
2 4 1 9 7
int p,i,j,temp;
for(i=0;i<5;i++)
{
p=i;
p=2
for(j=i+1;j<5;j++)
if(arr[p]>arr[j]) false
p=j;
temp
Selection Sort
0 1 2 3 4
int arr[5]={2,4,1,9,7};
2 4 1 9 7
int p,i,j,temp;
for(i=0;i<5;i++)
{
p=i;
p=2
for(j=i+1;j<5;j++)
if(arr[p]>arr[j])
J=4
p=j;
temp
Selection Sort
0 1 2 3 4
int arr[5]={2,4,1,9,7};
2 4 1 9 7
int p,i,j,temp;
for(i=0;i<5;i++)
{
p=i;
p=2
for(j=i+1;j<5;j++)
if(arr[p]>arr[j]) false
p=j;
temp
Selection Sort
0 1 2 3 4
int arr[5]={2,4,1,9,7};
2 4 1 9 7
int p,i,j,temp;
for(i=0;i<5;i++)
{
p=i;
p=2
for(j=i+1;j<5;j++)
if(arr[p]>arr[j])
J=5
p=j;
temp
Selection Sort
0 1 2 3 4
int arr[5]={2,4,1,9,7};
2 4 1 9 7
int p,i,j,temp;
for(i=0;i<5;i++)
{
p=i;
p=2
for(j=i+1;j<5;j++)
if(arr[p]>arr[j])
Temp=1
p=j;
temp=arr[p];
temp
Selection Sort
0 1 2 3 4
int arr[5]={2,4,1,9,7};
2 4 9 7
int p,i,j,temp;
for(i=0;i<5;i++)
{
p=i;
p=2
for(j=i+1;j<5;j++)
if(arr[p]>arr[j])
Arr[p]=2
p=j;
temp=arr[p];
temp
arr[p]=arr[i];
1
Selection Sort
0 1 2 3 4
int arr[5]={2,4,1,9,7};
4 9 7
int p,i,j,temp;
for(i=0;i<5;i++)
{
p=i;
p=2
for(j=i+1;j<5;j++)
if(arr[p]>arr[j])
p=j;
temp=arr[p];
temp
arr[p]=arr[i];
1
2
arr[i]=temp; Arr[i]=1
Selection Sort
0 1 2 3 4
int arr[5]={2,4,1,9,7};
4 9 7
int p,i,j,temp;
for(i=0;i<5;i++)
{
p=i;
p=2
for(j=i+1;j<5;j++)
if(arr[p]>arr[j])
p=j;
temp=arr[p];
temp
arr[p]=arr[i];
1 2
arr[i]=temp;
Next iteration
}

More Related Content

DOCX
ejercicios matematica
PDF
Bab 7 kls xi
PDF
Introducción al modelado de sistemas dinámicos
DOCX
PDF
PDF
Revista enfoque 157ab
PDF
03 mg ejemplo02
PDF
Enteros 1
ejercicios matematica
Bab 7 kls xi
Introducción al modelado de sistemas dinámicos
Revista enfoque 157ab
03 mg ejemplo02
Enteros 1

More from Umar Farooq (10)

PDF
Ado.Net Architecture
DOCX
Linq in C#
PDF
Creating Windows-based Applications Part-I
PDF
Building .NET-based Applications with C#
PDF
Week 9 IUB c#
PDF
Matrix
PDF
Polymorphism, Abstarct Class and Interface in C#
PDF
Array and Collections in c#
PDF
C# (This keyword, Properties, Inheritance, Base Keyword)
PDF
Software process model
Ado.Net Architecture
Linq in C#
Creating Windows-based Applications Part-I
Building .NET-based Applications with C#
Week 9 IUB c#
Matrix
Polymorphism, Abstarct Class and Interface in C#
Array and Collections in c#
C# (This keyword, Properties, Inheritance, Base Keyword)
Software process model
Ad

Recently uploaded (8)

PPTX
Presentation on chemistry class 11 and class 12
PDF
15 AUG 2025 PS 15 AUG 2025 PS 15 AUG 2025 PS
PDF
Materi seni rupa untuk sekolah dasar materi tentang seni rupa
PDF
فورمولر عمومی مضمون فزیک برای همه انجنیران
PDF
Cold positive punishment of the student سزادانی ئەرێنی ساردی قوتابی.pdf
PDF
levelling full chapter with examples and questions
PDF
5.PDFsxcc c fvfvfv fvfvwCCDSDcvvcrdcfrwcwecwdcfwe
PPTX
Madison dsfnsd dslsf sada;sdmas;ds;dls.pptx
Presentation on chemistry class 11 and class 12
15 AUG 2025 PS 15 AUG 2025 PS 15 AUG 2025 PS
Materi seni rupa untuk sekolah dasar materi tentang seni rupa
فورمولر عمومی مضمون فزیک برای همه انجنیران
Cold positive punishment of the student سزادانی ئەرێنی ساردی قوتابی.pdf
levelling full chapter with examples and questions
5.PDFsxcc c fvfvfv fvfvwCCDSDcvvcrdcfrwcwecwdcfwe
Madison dsfnsd dslsf sada;sdmas;ds;dls.pptx
Ad

Selection Sort

  • 2. Selection Sort 0 1 2 3 4 int arr[5]={2,4,1,9,7};
  • 3. Selection Sort 0 1 2 3 4 int arr[5]={2,4,1,9,7}; 2 4 1 9 7
  • 4. Selection Sort 0 1 2 3 4 int arr[5]={2,4,1,9,7}; 2 4 1 9 7 int p,i,j,temp; temp
  • 5. Selection Sort 0 1 2 3 4 int arr[5]={2,4,1,9,7}; 2 4 1 9 7 int p,i,j,temp; for(i=0;i<5;i++) temp
  • 6. Selection Sort 0 1 2 3 4 int arr[5]={2,4,1,9,7}; 2 4 1 9 7 int p,i,j,temp; for(i=0;i<5;i++) { temp
  • 7. Selection Sort 0 1 2 3 4 int arr[5]={2,4,1,9,7}; 2 4 1 9 7 int p,i,j,temp; for(i=0;i<5;i++) { p=i; temp
  • 8. Selection Sort 0 1 2 3 4 int arr[5]={2,4,1,9,7}; 2 4 1 9 7 int p,i,j,temp; for(i=0;i<5;i++) { p=i; P=0 temp p=0
  • 9. Selection Sort 0 1 2 3 4 int arr[5]={2,4,1,9,7}; 2 4 1 9 7 int p,i,j,temp; for(i=0;i<5;i++) { p=i; p=0 for(j=i+1;j<5;j++) j-=1 temp
  • 10. Selection Sort 0 1 2 3 4 int arr[5]={2,4,1,9,7}; 2 4 1 9 7 int p,i,j,temp; for(i=0;i<5;i++) { p=i; p=0 for(j=i+1;j<5;j++) if(arr[p]>arr[j]) temp
  • 11. Selection Sort 0 1 2 3 4 int arr[5]={2,4,1,9,7}; 2 4 1 9 7 int p,i,j,temp; for(i=0;i<5;i++) { p=i; p=0 for(j=i+1;j<5;j++) if(arr[p]>arr[j]) false p=j; temp
  • 12. Selection Sort 0 1 2 3 4 int arr[5]={2,4,1,9,7}; 2 4 1 9 7 int p,i,j,temp; for(i=0;i<5;i++) { p=i; p=0 for(j=i+1;j<5;j++) if(arr[p]>arr[j]) J=2 p=j; temp
  • 13. Selection Sort 0 1 2 3 4 int arr[5]={2,4,1,9,7}; 2 4 1 9 7 int p,i,j,temp; for(i=0;i<5;i++) { p=i; p=0 for(j=i+1;j<5;j++) if(arr[p]>arr[j]) true p=j; temp
  • 14. Selection Sort 0 1 2 3 4 int arr[5]={2,4,1,9,7}; 2 4 1 9 7 int p,i,j,temp; for(i=0;i<5;i++) { p=i; p=2 for(j=i+1;j<5;j++) if(arr[p]>arr[j]) P=2 p=j; temp
  • 15. Selection Sort 0 1 2 3 4 int arr[5]={2,4,1,9,7}; 2 4 1 9 7 int p,i,j,temp; for(i=0;i<5;i++) { p=i; p=2 for(j=i+1;j<5;j++) if(arr[p]>arr[j]) J=3 p=j; temp
  • 16. Selection Sort 0 1 2 3 4 int arr[5]={2,4,1,9,7}; 2 4 1 9 7 int p,i,j,temp; for(i=0;i<5;i++) { p=i; p=2 for(j=i+1;j<5;j++) if(arr[p]>arr[j]) false p=j; temp
  • 17. Selection Sort 0 1 2 3 4 int arr[5]={2,4,1,9,7}; 2 4 1 9 7 int p,i,j,temp; for(i=0;i<5;i++) { p=i; p=2 for(j=i+1;j<5;j++) if(arr[p]>arr[j]) J=4 p=j; temp
  • 18. Selection Sort 0 1 2 3 4 int arr[5]={2,4,1,9,7}; 2 4 1 9 7 int p,i,j,temp; for(i=0;i<5;i++) { p=i; p=2 for(j=i+1;j<5;j++) if(arr[p]>arr[j]) false p=j; temp
  • 19. Selection Sort 0 1 2 3 4 int arr[5]={2,4,1,9,7}; 2 4 1 9 7 int p,i,j,temp; for(i=0;i<5;i++) { p=i; p=2 for(j=i+1;j<5;j++) if(arr[p]>arr[j]) J=5 p=j; temp
  • 20. Selection Sort 0 1 2 3 4 int arr[5]={2,4,1,9,7}; 2 4 1 9 7 int p,i,j,temp; for(i=0;i<5;i++) { p=i; p=2 for(j=i+1;j<5;j++) if(arr[p]>arr[j]) Temp=1 p=j; temp=arr[p]; temp
  • 21. Selection Sort 0 1 2 3 4 int arr[5]={2,4,1,9,7}; 2 4 9 7 int p,i,j,temp; for(i=0;i<5;i++) { p=i; p=2 for(j=i+1;j<5;j++) if(arr[p]>arr[j]) Arr[p]=2 p=j; temp=arr[p]; temp arr[p]=arr[i]; 1
  • 22. Selection Sort 0 1 2 3 4 int arr[5]={2,4,1,9,7}; 4 9 7 int p,i,j,temp; for(i=0;i<5;i++) { p=i; p=2 for(j=i+1;j<5;j++) if(arr[p]>arr[j]) p=j; temp=arr[p]; temp arr[p]=arr[i]; 1 2 arr[i]=temp; Arr[i]=1
  • 23. Selection Sort 0 1 2 3 4 int arr[5]={2,4,1,9,7}; 4 9 7 int p,i,j,temp; for(i=0;i<5;i++) { p=i; p=2 for(j=i+1;j<5;j++) if(arr[p]>arr[j]) p=j; temp=arr[p]; temp arr[p]=arr[i]; 1 2 arr[i]=temp; Next iteration }