SlideShare a Scribd company logo
2
Most read
3
Most read
7
Most read
Selection sort
Presented by ASMITA
26/01/18
1
SORTING Algorithm
In computer science, a sorting algorithm is an
algorithm that puts elements of a list in a certain
order.
2
SELECTION SORT
 Selection sorting is conceptually the most simplest sorting
algorithm.
 This algorithm first finds the smallest element in the array
and exchanges it with the element in the first position, then
find the second smallest element and exchange it with the
element in the second position, and continues in this way
until the entire array is sorted.
 Keep doing n-1 times to place all n values in the sorted order.
3
How selection sorting works?
4
5
Selection sort
 input A sequence of n numbers <a1, a2,…..an>
 Output A reordering <a1,a2,….an>of the input sequences
such that a1<a2<a3…..<an
 Idea behind selection sort
Left hand Right hand
9 3 6 4 33
9 3 6 4 3 4
9 3 6 4 3 4 6
9 3 6 4 3 4 6 9
6
Pseudo-code for selection sort
 Selection sort(A) A[1….N]
 For i=1 to A.lenght-1
 {
 MIN=i
 For j=i + 1 to A.lenght
 {
 If (A[j] <A[MIN])
 {
 MIN= j
 }
 } // MIN.elements to its correct position
 Temp = A[i]
 A[i] =A[MIN]
 A[MIN] =temp
 }
6 3 1 2
1 2 3 4
i =1 j=2
MIN
1
7
Selection sort
8
 For i=1 to A.lenght-1
 {
 MIN=I
 For j=i + 1 to A.lenght
 {
 If (A[j] <A[MIN])
 {
 MIN= j
 }
6 3 1 2
1 2 3 4
i =1 j=2
MIN
1
6 3 1 2
1 2 3 4
i=1 j=3
MIN
2
6 3 1 2
1 2 3 4
i =1 j=4
MIN
3
If (A[j] <A[MIN]) If (A[j] <A[MIN])
3<6 1<3
9
 For i=1 to A.lenght-1
 {
 MIN=i
 For j=i + 1 to A.lenght
 {
 If (A[j] <A[MIN])
 {
 MIN= j
 }
1 2 3 4
i =2 j=3
MIN
2
1 2 3 4
i =2 j=3
MIN
2
1 2 3 4
i =2 j=5
MIN
4
If (A[j] <A[MIN]) If (A[j] <A[MIN])
6<3 2<3
1 3 6 2 1 3 6 21 3 6 2
10
 For i=1 to A.lenght-1
 {
 MIN=i
 For j=i + 1 to A.lenght
 {
 If (A[j] <A[MIN])
 {
 MIN= j
 }
1 2 3 4
i =3 j=4
MIN
3
1 2 3 4
i =3 j=5
MIN
4
1 2 3 4
MIN
4
If (A[j] <A[MIN])
3<6
1 2 6 3 1 2 3 61 2 6 3
11
Time complexity of selection sort
 Selection sort(A) A[1….N] cost times
 For i=1 to A.lenght-1 c1 n
 {
 MIN=I c2 n-1
 For j=i + 1 to A.lenght
 {
 If (A[j] <A[MIN])
 { c3 n+n-1+…..1 // 2 n=n
 MIN= j = n(n+1)/2 3 n=n-1
 } 4 n=n-2
 } n-1 n=1
 Temp = A[i] c4 n-1
 A[i] =A[MIN] c5 n-1
 A[MIN] =temp c6 n-1
 }
12
Total time
13
As in insertion sort 14
15
For example 16
17
18
19
20

More Related Content

What's hot (20)

PPTX
Merge sort and quick sort
Shakila Mahjabin
 
PPT
Breadth first search
Sazzad Hossain
 
PPTX
Presentation on the topic selection sort
District Administration
 
PPTX
Sorting algorithms
Trupti Agrawal
 
PPTX
HEAP SORT .pptx
Fazlullah28
 
PPT
Breadth first search and depth first search
Hossain Md Shakhawat
 
PPT
Data Structure and Algorithms Linked List
ManishPrajapati78
 
PDF
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
PPTX
Selection sort
Jay Patel
 
PPTX
Unit 4 queue
Dabbal Singh Mahara
 
PPTX
Sorting
Ashim Lamichhane
 
PPTX
Marge Sort
Ankit92Chitnavis
 
PPT
Selection sort
amna izzat
 
PPTX
NumPy
AbhijeetAnand88
 
PPTX
Applications of data structures
Wipro
 
PPTX
Queues
Ashim Lamichhane
 
PPTX
Asymptotic Notation and Data Structures
Amrinder Arora
 
PDF
Numeric Data types in Python
jyostna bodapati
 
PPT
Application of dfs
Hossain Md Shakhawat
 
Merge sort and quick sort
Shakila Mahjabin
 
Breadth first search
Sazzad Hossain
 
Presentation on the topic selection sort
District Administration
 
Sorting algorithms
Trupti Agrawal
 
HEAP SORT .pptx
Fazlullah28
 
Breadth first search and depth first search
Hossain Md Shakhawat
 
Data Structure and Algorithms Linked List
ManishPrajapati78
 
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
Selection sort
Jay Patel
 
Unit 4 queue
Dabbal Singh Mahara
 
Marge Sort
Ankit92Chitnavis
 
Selection sort
amna izzat
 
Applications of data structures
Wipro
 
Asymptotic Notation and Data Structures
Amrinder Arora
 
Numeric Data types in Python
jyostna bodapati
 
Application of dfs
Hossain Md Shakhawat
 

Similar to Selection sort(sorting algorithm in data structure) and its time complexity (20)

PPT
Data Structure (MC501)
Kamal Singh Lodhi
 
PPTX
Data Structure and algorithms for software
ManishShukla712917
 
PDF
Analisys of Selection Sort and Bubble Sort
Humano Terricola
 
PPTX
Sorting pnk
pinakspatel
 
PPTX
Selection sort 1
asmhemu
 
PPTX
AJisthewewrtyuiojhghfdfsgvhjhklopi87ytrytfghjk
PradipTadme
 
PPT
Unit 7 sorting
kalyanineve
 
PPTX
Searching and Sorting algorithms and working
RitikaLohiya2
 
PPTX
Introduction to Algorithms
pppepito86
 
PPTX
Selectionsort
Deepika Pahuja
 
PPTX
sorting and searching.pptx
ParagAhir1
 
PPTX
Sorting Algorithms
Afaq Mansoor Khan
 
PPTX
Selection-sort-in-algorithm and complexity.pptx
ArjayBalberan1
 
PDF
Selection Sort with Improved Asymptotic Time Bounds
theijes
 
PPTX
sorting-160810203705.pptx
AnSHiKa187943
 
PPSX
Sorting and searching
kalyanineve
 
PPTX
Sorting techniques
JayeshGadhave1
 
PPTX
Sorting Algorithms to arrange data in particular format
itsusamazahid
 
PPTX
Unit vii sorting
Tribhuvan University
 
DOCX
Selection sort lab mannual
maamir farooq
 
Data Structure (MC501)
Kamal Singh Lodhi
 
Data Structure and algorithms for software
ManishShukla712917
 
Analisys of Selection Sort and Bubble Sort
Humano Terricola
 
Sorting pnk
pinakspatel
 
Selection sort 1
asmhemu
 
AJisthewewrtyuiojhghfdfsgvhjhklopi87ytrytfghjk
PradipTadme
 
Unit 7 sorting
kalyanineve
 
Searching and Sorting algorithms and working
RitikaLohiya2
 
Introduction to Algorithms
pppepito86
 
Selectionsort
Deepika Pahuja
 
sorting and searching.pptx
ParagAhir1
 
Sorting Algorithms
Afaq Mansoor Khan
 
Selection-sort-in-algorithm and complexity.pptx
ArjayBalberan1
 
Selection Sort with Improved Asymptotic Time Bounds
theijes
 
sorting-160810203705.pptx
AnSHiKa187943
 
Sorting and searching
kalyanineve
 
Sorting techniques
JayeshGadhave1
 
Sorting Algorithms to arrange data in particular format
itsusamazahid
 
Unit vii sorting
Tribhuvan University
 
Selection sort lab mannual
maamir farooq
 
Ad

More from Computer_ at_home (7)

PPTX
Association for computing machinery
Computer_ at_home
 
PPT
Diffie-hellman algorithm
Computer_ at_home
 
PPTX
Ip addresses
Computer_ at_home
 
PPTX
Project scheduling and tracking
Computer_ at_home
 
PPTX
Project scheduling and tracking
Computer_ at_home
 
PPTX
Message passing ( in computer science)
Computer_ at_home
 
PPT
Flag registers (assembly language) with types and examples
Computer_ at_home
 
Association for computing machinery
Computer_ at_home
 
Diffie-hellman algorithm
Computer_ at_home
 
Ip addresses
Computer_ at_home
 
Project scheduling and tracking
Computer_ at_home
 
Project scheduling and tracking
Computer_ at_home
 
Message passing ( in computer science)
Computer_ at_home
 
Flag registers (assembly language) with types and examples
Computer_ at_home
 
Ad

Recently uploaded (20)

PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
community health nursing question paper 2.pdf
Prince kumar
 
Dimensions of Societal Planning in Commonism
StefanMz
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 

Selection sort(sorting algorithm in data structure) and its time complexity

  • 1. Selection sort Presented by ASMITA 26/01/18 1
  • 2. SORTING Algorithm In computer science, a sorting algorithm is an algorithm that puts elements of a list in a certain order. 2
  • 3. SELECTION SORT  Selection sorting is conceptually the most simplest sorting algorithm.  This algorithm first finds the smallest element in the array and exchanges it with the element in the first position, then find the second smallest element and exchange it with the element in the second position, and continues in this way until the entire array is sorted.  Keep doing n-1 times to place all n values in the sorted order. 3
  • 5. 5
  • 6. Selection sort  input A sequence of n numbers <a1, a2,…..an>  Output A reordering <a1,a2,….an>of the input sequences such that a1<a2<a3…..<an  Idea behind selection sort Left hand Right hand 9 3 6 4 33 9 3 6 4 3 4 9 3 6 4 3 4 6 9 3 6 4 3 4 6 9 6
  • 7. Pseudo-code for selection sort  Selection sort(A) A[1….N]  For i=1 to A.lenght-1  {  MIN=i  For j=i + 1 to A.lenght  {  If (A[j] <A[MIN])  {  MIN= j  }  } // MIN.elements to its correct position  Temp = A[i]  A[i] =A[MIN]  A[MIN] =temp  } 6 3 1 2 1 2 3 4 i =1 j=2 MIN 1 7
  • 9.  For i=1 to A.lenght-1  {  MIN=I  For j=i + 1 to A.lenght  {  If (A[j] <A[MIN])  {  MIN= j  } 6 3 1 2 1 2 3 4 i =1 j=2 MIN 1 6 3 1 2 1 2 3 4 i=1 j=3 MIN 2 6 3 1 2 1 2 3 4 i =1 j=4 MIN 3 If (A[j] <A[MIN]) If (A[j] <A[MIN]) 3<6 1<3 9
  • 10.  For i=1 to A.lenght-1  {  MIN=i  For j=i + 1 to A.lenght  {  If (A[j] <A[MIN])  {  MIN= j  } 1 2 3 4 i =2 j=3 MIN 2 1 2 3 4 i =2 j=3 MIN 2 1 2 3 4 i =2 j=5 MIN 4 If (A[j] <A[MIN]) If (A[j] <A[MIN]) 6<3 2<3 1 3 6 2 1 3 6 21 3 6 2 10
  • 11.  For i=1 to A.lenght-1  {  MIN=i  For j=i + 1 to A.lenght  {  If (A[j] <A[MIN])  {  MIN= j  } 1 2 3 4 i =3 j=4 MIN 3 1 2 3 4 i =3 j=5 MIN 4 1 2 3 4 MIN 4 If (A[j] <A[MIN]) 3<6 1 2 6 3 1 2 3 61 2 6 3 11
  • 12. Time complexity of selection sort  Selection sort(A) A[1….N] cost times  For i=1 to A.lenght-1 c1 n  {  MIN=I c2 n-1  For j=i + 1 to A.lenght  {  If (A[j] <A[MIN])  { c3 n+n-1+…..1 // 2 n=n  MIN= j = n(n+1)/2 3 n=n-1  } 4 n=n-2  } n-1 n=1  Temp = A[i] c4 n-1  A[i] =A[MIN] c5 n-1  A[MIN] =temp c6 n-1  } 12
  • 14. As in insertion sort 14
  • 15. 15
  • 17. 17
  • 18. 18
  • 19. 19
  • 20. 20