SlideShare a Scribd company logo
1 of 39
LIST IN PYTHON
SELECTION SORT
CLASS: XII
COMPUTER SCIENCE(083)
PART-6
WHAT IS SELECTION SORT?
The Selection sort is based on the idea of finding the minimum or maximum
element in an unsorted array and then putting it in its correct position in a sorted
LIST
How Selection Sort Works?
Step 1: Select the first element of the list and set the first element as minimum
Step 2: Compare minimum with the next element. If the next element is smaller than
minimum, assign the next element as minimum. This process goes on until the last
element.
Step 3: After each iteration, minimum is placed in the front of the unsorted list.
Step 4: Step 1 to 3 are repeated until all the elements are placed at their correct
positions.
How Selection Sort Works?
0 1 2 3 4
20 12 10 15 2
Let Us Understand With The Help Of Example:
no=
These are unsorted number and we need to sort them with the help of selection sort
20 12 10 15 2
Step 1: initialize the list with numbers as shown below:
no=[20,12,10,15,2]
Step 2: Declare variable K and store the
length of list.
no=[20,12,10,15,2]
K=len(no)
0 1 2 3 4
20 12 10 15 2
no=
K=5
Step 4: Start the outer loop x from 0 to K-1
for x in range(0,K):
x=0 k
Step 5: Start the inner loop y from 0 to K-1
Step 5: before starting inner loop store minimum =x the index number
min=x
for y in range(x+1,k):
y=x+1=0+1=1
Step 2: Declare variable K and store the length of list.
no=[20,12,10,15,2]
K=len(no)
0 1 2 3 4
20 12 10 15 2
no=
K=5
Step 4: Start the outer loop x from 0 to K-1
for x in range(0,K):
x=0 k
Step 5: Start the inner loop y from 0 to K-1
Step 5: before starting inner loop store minimum =x the index number
min=x
for y in range(0+1,k):
Step 6: Start if condition inside inner loop to check no[min] value is greater than no[y] or
not.
if no[min]> no[y]:
Step 7: if condition TRUE than overwrite the minimum value with y
min=y
Step 2: Declare variable K and store the length of list.
no=[20,12,10,15,2]
K=len(no)
0 1 2 3 4
20 12 10 15 2
no=
K=5
Step 4: Start the outer loop x from 0 to K-1
for x in range(0,K):
x=0 k
Step 5: Start the inner loop y from 0 to K-1
Step 5: before starting inner loop store minimum =x the index number
min=x
for y in range(0+1,k):
Step 6: Start if condition inside inner loop to check no[min] value is greater than no[y] or not.
if no[min]> no[y]:
Step 7: if condition TRUE than overwrite the minimum value with y
min=y
Step 8:Every time when inner loop finished swapping starts before outer loop move to next step
tmp=no[min]
no[min]=no[x]
no[x]=tmp
Step 2: Declare variable K and store the length of list.
no=[20,12,10,15,2]
K=len(no) 0 1 2 3 4
20 12 10 15 2
no=
K=5
Step 4: Start the outer loop x from 0 to K-1
for x in range(0,K):
x=0 k
Step 5: Start the inner loop y from 0 to K-1
Step 5: before starting inner loop store minimum =x the index number
min=x
for y in range(0+1,k):
Step 6: Start if condition inside inner loop to check no[min] value is greater than no[y] or not.
if no[min]> no[y]:
Step 7: if condition TRUE than overwrite the minimum value with y
min=y
Step 8:Every time when inner loop finished swapping starts before outer loop move to next step
tmp=no[min]
no[min]=no[x]
no[x]=tmp
Step 9: Display the final result
print(no)
no=[10,19,5,4,12,3]
K=len(no)
for x in range(0,K):
min = x
for y in range(x + 1, K):
if no[min]> no[y]:
min = y
temp= no[min];
no[min] = no[x]
no[x]=temp
print("Pass: ",x+1,"=",no)
print("Final List:",no)
SELECTION SORT FULL CODE:
Inner loop
Outer loop
Outer loop
10 19 5 4 12 3
PASS 1 started x=0
Unsorted Value
Y=x+1=1 K
X=0
Inner loop
Outer loop
min=0
SELECTION SORT:
no=[10,19,5,4,12,3]
K=len(no)
for x in range(0,K):
min = x
for y in range(x + 1, K):
if no[min]> no[y]:
min = y
temp= no[min];
no[min] = no[x]
no[x]=temp
print("Pass: ",x+1,"=",no)
print("Final List:",no)
10 19 5 4 12 3no=
0 1 2 3 4 5
x=0 min=x
K
Outer loop [this is pass 1]
Inner loop start where y starts from x+1 to K
y=1 10 19 5 4 12 3 min=0x=0
y=1
K=6(less than 6)
if 10>19 FALSE min value remain same
min=0
SELECTION SORT:
no=[10,19,5,4,12,3]
K=len(no)
for x in range(0,K):
min = x
for y in range(x + 1, K):
if no[min]> no[y]:
min = y
temp= no[min];
no[min] = no[x]
no[x]=temp
print("Pass: ",x+1,"=",no)
print("Final List:",no)
10 19 5 4 12 3no=
0 1 2 3 4 5
x=0 min=x
K
Outer loop [this is pass 1]
y=1
y=2
10 19 5 4 12 3
min=0x=0
y=2
K=6(less than 6)
if 10>5 TRUE min value change to 2
min=0
10 19 5 4 12 3
SELECTION SORT:
no=[10,19,5,4,12,3]
K=len(no)
for x in range(0,K):
min = x
for y in range(x + 1, K):
if no[min]> no[y]:
min = y
temp= no[min];
no[min] = no[x]
no[x]=temp
print("Pass: ",x+1,"=",no)
print("Final List:",no)
10 19 5 4 12 3no=
0 1 2 3 4 5
x=0 min=x
K
Outer loop [this is pass 1]
y=1
y=2
y=3
10 19 5 4 12 3
min=2x=0
K=6(less than 6)
if 5>4 TRUE min value change to 3
10 19 5 4 12 3
y=3min=2
10 19 5 4 12 3
SELECTION SORT:
no=[10,19,5,4,12,3]
K=len(no)
for x in range(0,K):
min = x
for y in range(x + 1, K):
if no[min]> no[y]:
min = y
temp= no[min];
no[min] = no[x]
no[x]=temp
print("Pass: ",x+1,"=",no)
print("Final List:",no)
10 19 5 4 12 3no=
0 1 2 3 4 5
x=0 min=x
K
Outer loop [this is pass 1]
y=1
y=2
y=3
y=4
10 19 5 4 12 3
min=3x=0
K=6(less than 6)
if 4>12 FALSE min value remain 3
10 19 5 4 12 3
y=4min=3
10 19 5 4 12 3
10 19 5 4 12 3
SELECTION SORT:
no=[10,19,5,4,12,3]
K=len(no)
for x in range(0,K):
min = x
for y in range(x + 1, K):
if no[min]> no[y]:
min = y
temp= no[min];
no[min] = no[x]
no[x]=temp
print("Pass: ",x+1,"=",no)
print("Final List:",no)
10 19 5 4 12 3no=
0 1 2 3 4 5
x=0 min=x
K
Outer loop [this is pass 1]
y=1
y=2
y=3
y=4
y=5
10 19 5 4 12 3
min=3x=0
K=6(less than 6)
if 4>3 TRUE min value change to 5
10 19 5 4 12 3
y=5min=3
10 19 5 4 12 3
10 19 5 4 12 3
10 19 5 4 12 3
SELECTION SORT:
no=[10,19,5,4,12,3]
K=len(no)
for x in range(0,K):
min = x
for y in range(x + 1, K):
if no[min]> no[y]:
min = y
temp= no[min];
no[min] = no[x]
no[x]=temp
print("Pass: ",x+1,"=",no)
print("Final List:",no)
10 19 5 4 12 3no=
0 1 2 3 4 5
x=0 min=x
K
Outer loop [this is pass 1]
y=1
y=2
y=3
y=4
y=5
10 19 5 4 12 3
min=5x=0
Now Swapping start
tmp= 3 temp=no[min]
10 19 5 4 12 3
min=5
10 19 5 4 12 3
10 19 5 4 12 3
10 19 5 4 12 3
x=0
swap
Inner loop finish
no[min]=no[x]no[5]= 10
no[0]= 3 no[x]=temp1019 5 4 123
Pass 1 Final value:
1019 5 4 123
PASS 1 FINAL VALUE:
Sorted Value
Unsorted Value
1019 5 4 123
PASS 2 STARTS Where X=1
Sorted Value
Y=x+1=1+1=2 K
X=1
Inner loop
Outer loop
min=1
SELECTION SORT:
no=[10,19,5,4,12,3]
K=len(no)
for x in range(0,K):
min = x
for y in range(x + 1, K):
if no[min]> no[y]:
min = y
temp= no[min];
no[min] = no[x]
no[x]=temp
print("Pass: ",x+1,"=",no)
print("Final List:",no)
3 19 5 4 12 10no=
0 1 2 3 4 5
x=1 min=x
K
Outer loop [this is pass 2]
Inner loop start where y starts from x+1 to K
y=2 3 19 5 4 12 10 min=1x=1
y=2
K=6(less than 6)
if 19>5 TRUE min value Change 2
min=1
SELECTION SORT:
no=[10,19,5,4,12,3]
K=len(no)
for x in range(0,K):
min = x
for y in range(x + 1, K):
if no[min]> no[y]:
min = y
temp= no[min];
no[min] = no[x]
no[x]=temp
print("Pass: ",x+1,"=",no)
print("Final List:",no)
3 19 5 4 12 10no=
0 1 2 3 4 5
x=0 min=x
K
Outer loop [this is pass 1]
y=2
y=3
3 19 5 4 12 10
min=2x=1
y=3
K=6(less than 6)
If 5>4 TRUE min value change to 3
min=2
3 19 5 4 12 10
SELECTION SORT:
no=[10,19,5,4,12,3]
K=len(no)
for x in range(0,K):
min = x
for y in range(x + 1, K):
if no[min]> no[y]:
min = y
temp= no[min];
no[min] = no[x]
no[x]=temp
print("Pass: ",x+1,"=",no)
print("Final List:",no)
3 19 5 4 12 10no=
0 1 2 3 4 5
x=0 min=x
K
Outer loop [this is pass 1]
y=2
y=3
y=4
3 19 5 4 12 10
min=3x=1
K=6(less than 6)
if 4>12 FALSE min value remain same
3 19 5 4 12 10
y=4min=3
3 19 5 4 12 10
SELECTION SORT:
no=[10,19,5,4,12,3]
K=len(no)
for x in range(0,K):
min = x
for y in range(x + 1, K):
if no[min]> no[y]:
min = y
temp= no[min];
no[min] = no[x]
no[x]=temp
print("Pass: ",x+1,"=",no)
print("Final List:",no)
3 19 5 4 12 10no=
0 1 2 3 4 5
x=0 min=x
K
Outer loop [this is pass 1]
y=2
y=3
y=4
y=5
3 19 5 4 12 10
min=3x=1
K=6(less than 6)
If 4>10 FALSE min value remain same
3 19 5 4 12 10
y=5min=3
3 19 5 4 12 10
3 19 5 4 12 10
SELECTION SORT:
no=[10,19,5,4,12,3]
K=len(no)
for x in range(0,K):
min = x
for y in range(x + 1, K):
if no[min]> no[y]:
min = y
temp= no[min];
no[min] = no[x]
no[x]=temp
print("Pass: ",x+1,"=",no)
print("Final List:",no)
3 19 5 4 12 10no=
0 1 2 3 4 5
x=0 min=x
K
Outer loop [this is pass 1]
y=2
y=3
y=4
y=5
3 19 5 4 12 10
min=3x=1
Now Swapping start
tmp= 4 temp=no[min]
3 19 5 4 12 10
min=3
3 19 5 4 12 10
3 19 5 4 12 10
x=1
swap
Inner loop finish
no[min]=no[x]no[3]= 19
no[1]= 4 no[x]=temp101954 123
Pass 2 Final value:
101954 123
PASS 2 FINAL VALUE:
Unsorted Value
Sorted Value
101954 123
PASS 3 STARTS Where X=2
Sorted Value
Y=x+1=3 K
X=2
Inner loop
Outer loop
SELECTION SORT:
no=[10,19,5,4,12,3]
K=len(no)
for x in range(0,K):
min = x
for y in range(x + 1, K):
if no[min]> no[y]:
min = y
temp= no[min];
no[min] = no[x]
no[x]=temp
print("Pass: ",x+1,"=",no)
print("Final List:",no)
3 1954 12 10no=
0 1 2 3 4 5
x=2 min=x
K
Outer loop [this is pass 3]
Inner loop start where y starts from x+1 to K
y=3 3 1954 12 10 min=2x=2
y=3
K=6(less than 6)
If 5>19 FALSE min value remain same
min=2
SELECTION SORT:
no=[10,19,5,4,12,3]
K=len(no)
for x in range(0,K):
min = x
for y in range(x + 1, K):
if no[min]> no[y]:
min = y
temp= no[min];
no[min] = no[x]
no[x]=temp
print("Pass: ",x+1,"=",no)
print("Final List:",no)
3 1954 12 10no=
0 1 2 3 4 5
x=0 min=x
K
Outer loop [this is pass 3]
y=3
y=4
3 1954 12 10
min=2x=2
y=4
K=6(less than 6)
If 5>12 FALSE min value remain same
min=2
3 1954 12 10
SELECTION SORT:
no=[10,19,5,4,12,3]
K=len(no)
for x in range(0,K):
min = x
for y in range(x + 1, K):
if no[min]> no[y]:
min = y
temp= no[min];
no[min] = no[x]
no[x]=temp
print("Pass: ",x+1,"=",no)
print("Final List:",no)
3 1954 12 10no=
0 1 2 3 4 5
x=0 min=x
K
Outer loop [this is pass 3]
y=3
y=4
y=5
3 1954 12 10
min=2x=2
K=6(less than 6)
If 5>10 FALSE min value remain same
3 1954 12 10
y=5min=2
3 1954 12 10
SELECTION SORT:
no=[10,19,5,4,12,3]
K=len(no)
for x in range(0,K):
min = x
for y in range(x + 1, K):
if no[min]> no[y]:
min = y
temp= no[min];
no[min] = no[x]
no[x]=temp
print("Pass: ",x+1,"=",no)
print("Final List:",no)
3 1954 12 10no=
0 1 2 3 4 5
x=0 min=x
K
Outer loop [this is pass 3]
y=3
y=4
y=5
min=2x=2
Now Swapping start
tmp= 5 temp=no[min]
3 1954 12 10
min=2
3 1954 12 10
3 1954 12 10
x=2swap
Inner loop finish
no[min]=no[x]no[2]= 5
no[2]= 5 no[x]=temp101954 123
Pass 3 Final value:
101954 123
PASS 3 FINAL VALUE:
Unsorted Value
Sorted Value
101954 123
PASS 4 STARTS Where X=3
Sorted Value
Y=x+1=4 K
X=3
Inner loop
Outer loop
SELECTION SORT:
no=[10,19,5,4,12,3]
K=len(no)
for x in range(0,K):
min = x
for y in range(x + 1, K):
if no[min]> no[y]:
min = y
temp= no[min];
no[min] = no[x]
no[x]=temp
print("Pass: ",x+1,"=",no)
print("Final List:",no)
3 1954 12 10no=
0 1 2 3 4 5
x=3 min=x
K
Outer loop [this is pass 4]
Inner loop start where y starts from x+1 to K
y=4 3 1954 12 10 min=3x=3
y=4
K=6(less than 6)
If 19>12 TRUE min value change to 4
min=3
SELECTION SORT:
no=[10,19,5,4,12,3]
K=len(no)
for x in range(0,K):
min = x
for y in range(x + 1, K):
if no[min]> no[y]:
min = y
temp= no[min];
no[min] = no[x]
no[x]=temp
print("Pass: ",x+1,"=",no)
print("Final List:",no)
3 1954 12 10no=
0 1 2 3 4 5
x=3 min=x
K
Outer loop [this is pass 4]
y=4
y=5
3 1954 12 10
min=4x=3
y=5
K=6(less than 6)
If 12>10 TRUE min value change to 5
min=4
3 1954 12 10
SELECTION SORT:
no=[10,19,5,4,12,3]
K=len(no)
for x in range(0,K):
min = x
for y in range(x + 1, K):
if no[min]> no[y]:
min = y
temp= no[min];
no[min] = no[x]
no[x]=temp
print("Pass: ",x+1,"=",no)
print("Final List:",no)
3 1954 12 10no=
0 1 2 3 4 5
x=3 min=x
K
Outer loop [this is pass 4]
y=4
y=5
min=5
x=3
Now Swapping start
tmp= 10 temp=no[min]
min=5
3 1954 12 10
3 1954 12 10
x=3
swap
Inner loop finish
no[min]=no[x]no[5]= 19
no[3]= 10 no[x]=temp191054 123
Pass 4 Final value:
10 1954 123
PASS 4 FINAL VALUE:
Unsorted Value
Sorted Value
10 1954 123
PASS 5 STARTS Where X=4
Sorted Value
Y=x+1=5
K
x=4
Inner loop
Outer loop
SELECTION SORT:
no=[10,19,5,4,12,3]
K=len(no)
for x in range(0,K):
min = x
for y in range(x + 1, K):
if no[min]> no[y]:
min = y
temp= no[min];
no[min] = no[x]
no[x]=temp
print("Pass: ",x+1,"=",no)
print("Final List:",no)
3 1054 12 19no=
0 1 2 3 4 5
x=4 min=x
K
Outer loop [this is pass 5]
Inner loop start where y starts from x+1 to K
y=5 3 1054 12 19 min=4x=4
y=5
K=6(less than 6)
If 12>19 FALSE min value remain same
min=4
SELECTION SORT:
no=[10,19,5,4,12,3]
K=len(no)
for x in range(0,K):
min = x
for y in range(x + 1, K):
if no[min]> no[y]:
min = y
temp= no[min];
no[min] = no[x]
no[x]=temp
print("Pass: ",x+1,"=",no)
print("Final List:",no)
3 1054 12 19no=
0 1 2 3 4 5
x=3 min=x
K
Outer loop [this is pass 4]
y=5
min=4
x=4
Now Swapping start
tmp= 12 temp=no[min]
min=4
3 1054 12 19
x=4
swap
Inner loop finish
no[min]=no[x]no[4]= 12
no[4]= 12 no[x]=temp191054 123
Pass 5 Final value:
10 1954 123
PASS 5 FINAL VALUE:
Unsorted Value
Sorted Value
10 1954 123
FINAL RESULT OF SELECTION SORT:
Sorted Value

More Related Content

What's hot (20)

Divide and conquer surfing lower bounds
Divide and conquer  surfing lower boundsDivide and conquer  surfing lower bounds
Divide and conquer surfing lower bounds
 
the two phase method - operations research
the two phase method - operations researchthe two phase method - operations research
the two phase method - operations research
 
Two phase method lpp
Two phase method lppTwo phase method lpp
Two phase method lpp
 
Operations Research - The Dual Simplex Method
Operations Research - The Dual Simplex MethodOperations Research - The Dual Simplex Method
Operations Research - The Dual Simplex Method
 
Ch02
Ch02Ch02
Ch02
 
Lpp simplex method
Lpp simplex methodLpp simplex method
Lpp simplex method
 
Operations Research - The Two Phase Method
Operations Research - The Two Phase MethodOperations Research - The Two Phase Method
Operations Research - The Two Phase Method
 
LINEAR PROGRAMMING
LINEAR PROGRAMMINGLINEAR PROGRAMMING
LINEAR PROGRAMMING
 
C2 st lecture 4 handout
C2 st lecture 4 handoutC2 st lecture 4 handout
C2 st lecture 4 handout
 
Lec16
Lec16Lec16
Lec16
 
Differentiation jan 21, 2014
Differentiation jan 21, 2014Differentiation jan 21, 2014
Differentiation jan 21, 2014
 
Big-M Method Presentation
Big-M Method PresentationBig-M Method Presentation
Big-M Method Presentation
 
C2 st lecture 3 handout
C2 st lecture 3 handoutC2 st lecture 3 handout
C2 st lecture 3 handout
 
Simplex Method
Simplex MethodSimplex Method
Simplex Method
 
Linear programming ppt
Linear programming pptLinear programming ppt
Linear programming ppt
 
Simplex two phase
Simplex two phaseSimplex two phase
Simplex two phase
 
Differentiation
DifferentiationDifferentiation
Differentiation
 
Two Phase Method- Linear Programming
Two Phase Method- Linear ProgrammingTwo Phase Method- Linear Programming
Two Phase Method- Linear Programming
 
Testsol
TestsolTestsol
Testsol
 
Chapter 6 base_number
Chapter 6 base_numberChapter 6 base_number
Chapter 6 base_number
 

Similar to LIST IN PYTHON[SELECTION SORT]

LIST IN PYTHON[BUBBLE SORT]
LIST IN PYTHON[BUBBLE SORT]LIST IN PYTHON[BUBBLE SORT]
LIST IN PYTHON[BUBBLE SORT]vikram mahendra
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03Krish_ver2
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03Krish_ver2
 
OpenOpt の線形計画で圧縮センシング
OpenOpt の線形計画で圧縮センシングOpenOpt の線形計画で圧縮センシング
OpenOpt の線形計画で圧縮センシングToshihiro Kamishima
 
Solucionario_de_Chapra_y_Canale_Quinta_E.pdf
Solucionario_de_Chapra_y_Canale_Quinta_E.pdfSolucionario_de_Chapra_y_Canale_Quinta_E.pdf
Solucionario_de_Chapra_y_Canale_Quinta_E.pdfJeancarlosPatalasanc
 
module2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdfmodule2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdfShiwani Gupta
 
Unit III Version I.pptx
Unit III Version I.pptxUnit III Version I.pptx
Unit III Version I.pptxssuserd602fd
 
Mathematical Modelling of Electro-Mechanical System in Matlab
Mathematical Modelling of Electro-Mechanical System in MatlabMathematical Modelling of Electro-Mechanical System in Matlab
Mathematical Modelling of Electro-Mechanical System in MatlabCOMSATS Abbottabad
 
Solutions manual for fundamentals of business math canadian 3rd edition by je...
Solutions manual for fundamentals of business math canadian 3rd edition by je...Solutions manual for fundamentals of business math canadian 3rd edition by je...
Solutions manual for fundamentals of business math canadian 3rd edition by je...Pollockker
 

Similar to LIST IN PYTHON[SELECTION SORT] (20)

LIST IN PYTHON[BUBBLE SORT]
LIST IN PYTHON[BUBBLE SORT]LIST IN PYTHON[BUBBLE SORT]
LIST IN PYTHON[BUBBLE SORT]
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
 
Time complexity
Time complexityTime complexity
Time complexity
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
Palm ch1
Palm ch1Palm ch1
Palm ch1
 
ملخص البرمجة المرئية - الوحدة الخامسة
ملخص البرمجة المرئية - الوحدة الخامسةملخص البرمجة المرئية - الوحدة الخامسة
ملخص البرمجة المرئية - الوحدة الخامسة
 
OpenOpt の線形計画で圧縮センシング
OpenOpt の線形計画で圧縮センシングOpenOpt の線形計画で圧縮センシング
OpenOpt の線形計画で圧縮センシング
 
Solucionario_de_Chapra_y_Canale_Quinta_E.pdf
Solucionario_de_Chapra_y_Canale_Quinta_E.pdfSolucionario_de_Chapra_y_Canale_Quinta_E.pdf
Solucionario_de_Chapra_y_Canale_Quinta_E.pdf
 
Daa unit iv - problems
Daa   unit  iv - problemsDaa   unit  iv - problems
Daa unit iv - problems
 
Gilat_ch03.pdf
Gilat_ch03.pdfGilat_ch03.pdf
Gilat_ch03.pdf
 
Recursion
RecursionRecursion
Recursion
 
module2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdfmodule2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdf
 
Unit III Version I.pptx
Unit III Version I.pptxUnit III Version I.pptx
Unit III Version I.pptx
 
Soft Heaps
Soft HeapsSoft Heaps
Soft Heaps
 
Mathematical Modelling of Electro-Mechanical System in Matlab
Mathematical Modelling of Electro-Mechanical System in MatlabMathematical Modelling of Electro-Mechanical System in Matlab
Mathematical Modelling of Electro-Mechanical System in Matlab
 
Solutions manual for fundamentals of business math canadian 3rd edition by je...
Solutions manual for fundamentals of business math canadian 3rd edition by je...Solutions manual for fundamentals of business math canadian 3rd edition by je...
Solutions manual for fundamentals of business math canadian 3rd edition by je...
 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
 
Unit 7 sorting
Unit 7   sortingUnit 7   sorting
Unit 7 sorting
 
Big O Notation.ppt
Big O Notation.pptBig O Notation.ppt
Big O Notation.ppt
 

More from vikram mahendra

Python Project On Cosmetic Shop system
Python Project On Cosmetic Shop systemPython Project On Cosmetic Shop system
Python Project On Cosmetic Shop systemvikram mahendra
 
Python Project on Computer Shop
Python Project on Computer ShopPython Project on Computer Shop
Python Project on Computer Shopvikram mahendra
 
PYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEMPYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEMvikram mahendra
 
BOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in PythonBOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in Pythonvikram mahendra
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONFLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONvikram mahendra
 
FLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHONFLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHONvikram mahendra
 
FLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHONFLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHONvikram mahendra
 
OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1vikram mahendra
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2vikram mahendra
 
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2vikram mahendra
 
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]vikram mahendra
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONvikram mahendra
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]vikram mahendra
 
INTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHONINTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHONvikram mahendra
 

More from vikram mahendra (20)

Communication skill
Communication skillCommunication skill
Communication skill
 
Python Project On Cosmetic Shop system
Python Project On Cosmetic Shop systemPython Project On Cosmetic Shop system
Python Project On Cosmetic Shop system
 
Python Project on Computer Shop
Python Project on Computer ShopPython Project on Computer Shop
Python Project on Computer Shop
 
PYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEMPYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEM
 
BOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in PythonBOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in Python
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONFLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHON
 
FLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHONFLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHON
 
FLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHONFLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHON
 
OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2
 
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2
 
DATA TYPE IN PYTHON
DATA TYPE IN PYTHONDATA TYPE IN PYTHON
DATA TYPE IN PYTHON
 
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHON
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
 
INTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHONINTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHON
 
Python Introduction
Python IntroductionPython Introduction
Python Introduction
 
GREEN SKILL[PART-2]
GREEN SKILL[PART-2]GREEN SKILL[PART-2]
GREEN SKILL[PART-2]
 
GREEN SKILLS[PART-1]
GREEN SKILLS[PART-1]GREEN SKILLS[PART-1]
GREEN SKILLS[PART-1]
 
Dictionary in python
Dictionary in pythonDictionary in python
Dictionary in python
 

Recently uploaded

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
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
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
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
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 

Recently uploaded (20)

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
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
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
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
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 

LIST IN PYTHON[SELECTION SORT]

  • 1. LIST IN PYTHON SELECTION SORT CLASS: XII COMPUTER SCIENCE(083) PART-6
  • 2. WHAT IS SELECTION SORT? The Selection sort is based on the idea of finding the minimum or maximum element in an unsorted array and then putting it in its correct position in a sorted LIST How Selection Sort Works? Step 1: Select the first element of the list and set the first element as minimum Step 2: Compare minimum with the next element. If the next element is smaller than minimum, assign the next element as minimum. This process goes on until the last element. Step 3: After each iteration, minimum is placed in the front of the unsorted list. Step 4: Step 1 to 3 are repeated until all the elements are placed at their correct positions.
  • 3. How Selection Sort Works? 0 1 2 3 4 20 12 10 15 2 Let Us Understand With The Help Of Example: no= These are unsorted number and we need to sort them with the help of selection sort 20 12 10 15 2 Step 1: initialize the list with numbers as shown below: no=[20,12,10,15,2]
  • 4. Step 2: Declare variable K and store the length of list. no=[20,12,10,15,2] K=len(no) 0 1 2 3 4 20 12 10 15 2 no= K=5 Step 4: Start the outer loop x from 0 to K-1 for x in range(0,K): x=0 k Step 5: Start the inner loop y from 0 to K-1 Step 5: before starting inner loop store minimum =x the index number min=x for y in range(x+1,k): y=x+1=0+1=1
  • 5. Step 2: Declare variable K and store the length of list. no=[20,12,10,15,2] K=len(no) 0 1 2 3 4 20 12 10 15 2 no= K=5 Step 4: Start the outer loop x from 0 to K-1 for x in range(0,K): x=0 k Step 5: Start the inner loop y from 0 to K-1 Step 5: before starting inner loop store minimum =x the index number min=x for y in range(0+1,k): Step 6: Start if condition inside inner loop to check no[min] value is greater than no[y] or not. if no[min]> no[y]: Step 7: if condition TRUE than overwrite the minimum value with y min=y
  • 6. Step 2: Declare variable K and store the length of list. no=[20,12,10,15,2] K=len(no) 0 1 2 3 4 20 12 10 15 2 no= K=5 Step 4: Start the outer loop x from 0 to K-1 for x in range(0,K): x=0 k Step 5: Start the inner loop y from 0 to K-1 Step 5: before starting inner loop store minimum =x the index number min=x for y in range(0+1,k): Step 6: Start if condition inside inner loop to check no[min] value is greater than no[y] or not. if no[min]> no[y]: Step 7: if condition TRUE than overwrite the minimum value with y min=y Step 8:Every time when inner loop finished swapping starts before outer loop move to next step tmp=no[min] no[min]=no[x] no[x]=tmp
  • 7. Step 2: Declare variable K and store the length of list. no=[20,12,10,15,2] K=len(no) 0 1 2 3 4 20 12 10 15 2 no= K=5 Step 4: Start the outer loop x from 0 to K-1 for x in range(0,K): x=0 k Step 5: Start the inner loop y from 0 to K-1 Step 5: before starting inner loop store minimum =x the index number min=x for y in range(0+1,k): Step 6: Start if condition inside inner loop to check no[min] value is greater than no[y] or not. if no[min]> no[y]: Step 7: if condition TRUE than overwrite the minimum value with y min=y Step 8:Every time when inner loop finished swapping starts before outer loop move to next step tmp=no[min] no[min]=no[x] no[x]=tmp Step 9: Display the final result print(no)
  • 8. no=[10,19,5,4,12,3] K=len(no) for x in range(0,K): min = x for y in range(x + 1, K): if no[min]> no[y]: min = y temp= no[min]; no[min] = no[x] no[x]=temp print("Pass: ",x+1,"=",no) print("Final List:",no) SELECTION SORT FULL CODE: Inner loop Outer loop Outer loop
  • 9. 10 19 5 4 12 3 PASS 1 started x=0 Unsorted Value Y=x+1=1 K X=0 Inner loop Outer loop min=0
  • 10. SELECTION SORT: no=[10,19,5,4,12,3] K=len(no) for x in range(0,K): min = x for y in range(x + 1, K): if no[min]> no[y]: min = y temp= no[min]; no[min] = no[x] no[x]=temp print("Pass: ",x+1,"=",no) print("Final List:",no) 10 19 5 4 12 3no= 0 1 2 3 4 5 x=0 min=x K Outer loop [this is pass 1] Inner loop start where y starts from x+1 to K y=1 10 19 5 4 12 3 min=0x=0 y=1 K=6(less than 6) if 10>19 FALSE min value remain same min=0
  • 11. SELECTION SORT: no=[10,19,5,4,12,3] K=len(no) for x in range(0,K): min = x for y in range(x + 1, K): if no[min]> no[y]: min = y temp= no[min]; no[min] = no[x] no[x]=temp print("Pass: ",x+1,"=",no) print("Final List:",no) 10 19 5 4 12 3no= 0 1 2 3 4 5 x=0 min=x K Outer loop [this is pass 1] y=1 y=2 10 19 5 4 12 3 min=0x=0 y=2 K=6(less than 6) if 10>5 TRUE min value change to 2 min=0 10 19 5 4 12 3
  • 12. SELECTION SORT: no=[10,19,5,4,12,3] K=len(no) for x in range(0,K): min = x for y in range(x + 1, K): if no[min]> no[y]: min = y temp= no[min]; no[min] = no[x] no[x]=temp print("Pass: ",x+1,"=",no) print("Final List:",no) 10 19 5 4 12 3no= 0 1 2 3 4 5 x=0 min=x K Outer loop [this is pass 1] y=1 y=2 y=3 10 19 5 4 12 3 min=2x=0 K=6(less than 6) if 5>4 TRUE min value change to 3 10 19 5 4 12 3 y=3min=2 10 19 5 4 12 3
  • 13. SELECTION SORT: no=[10,19,5,4,12,3] K=len(no) for x in range(0,K): min = x for y in range(x + 1, K): if no[min]> no[y]: min = y temp= no[min]; no[min] = no[x] no[x]=temp print("Pass: ",x+1,"=",no) print("Final List:",no) 10 19 5 4 12 3no= 0 1 2 3 4 5 x=0 min=x K Outer loop [this is pass 1] y=1 y=2 y=3 y=4 10 19 5 4 12 3 min=3x=0 K=6(less than 6) if 4>12 FALSE min value remain 3 10 19 5 4 12 3 y=4min=3 10 19 5 4 12 3 10 19 5 4 12 3
  • 14. SELECTION SORT: no=[10,19,5,4,12,3] K=len(no) for x in range(0,K): min = x for y in range(x + 1, K): if no[min]> no[y]: min = y temp= no[min]; no[min] = no[x] no[x]=temp print("Pass: ",x+1,"=",no) print("Final List:",no) 10 19 5 4 12 3no= 0 1 2 3 4 5 x=0 min=x K Outer loop [this is pass 1] y=1 y=2 y=3 y=4 y=5 10 19 5 4 12 3 min=3x=0 K=6(less than 6) if 4>3 TRUE min value change to 5 10 19 5 4 12 3 y=5min=3 10 19 5 4 12 3 10 19 5 4 12 3 10 19 5 4 12 3
  • 15. SELECTION SORT: no=[10,19,5,4,12,3] K=len(no) for x in range(0,K): min = x for y in range(x + 1, K): if no[min]> no[y]: min = y temp= no[min]; no[min] = no[x] no[x]=temp print("Pass: ",x+1,"=",no) print("Final List:",no) 10 19 5 4 12 3no= 0 1 2 3 4 5 x=0 min=x K Outer loop [this is pass 1] y=1 y=2 y=3 y=4 y=5 10 19 5 4 12 3 min=5x=0 Now Swapping start tmp= 3 temp=no[min] 10 19 5 4 12 3 min=5 10 19 5 4 12 3 10 19 5 4 12 3 10 19 5 4 12 3 x=0 swap Inner loop finish no[min]=no[x]no[5]= 10 no[0]= 3 no[x]=temp1019 5 4 123 Pass 1 Final value:
  • 16. 1019 5 4 123 PASS 1 FINAL VALUE: Sorted Value Unsorted Value
  • 17. 1019 5 4 123 PASS 2 STARTS Where X=1 Sorted Value Y=x+1=1+1=2 K X=1 Inner loop Outer loop min=1
  • 18. SELECTION SORT: no=[10,19,5,4,12,3] K=len(no) for x in range(0,K): min = x for y in range(x + 1, K): if no[min]> no[y]: min = y temp= no[min]; no[min] = no[x] no[x]=temp print("Pass: ",x+1,"=",no) print("Final List:",no) 3 19 5 4 12 10no= 0 1 2 3 4 5 x=1 min=x K Outer loop [this is pass 2] Inner loop start where y starts from x+1 to K y=2 3 19 5 4 12 10 min=1x=1 y=2 K=6(less than 6) if 19>5 TRUE min value Change 2 min=1
  • 19. SELECTION SORT: no=[10,19,5,4,12,3] K=len(no) for x in range(0,K): min = x for y in range(x + 1, K): if no[min]> no[y]: min = y temp= no[min]; no[min] = no[x] no[x]=temp print("Pass: ",x+1,"=",no) print("Final List:",no) 3 19 5 4 12 10no= 0 1 2 3 4 5 x=0 min=x K Outer loop [this is pass 1] y=2 y=3 3 19 5 4 12 10 min=2x=1 y=3 K=6(less than 6) If 5>4 TRUE min value change to 3 min=2 3 19 5 4 12 10
  • 20. SELECTION SORT: no=[10,19,5,4,12,3] K=len(no) for x in range(0,K): min = x for y in range(x + 1, K): if no[min]> no[y]: min = y temp= no[min]; no[min] = no[x] no[x]=temp print("Pass: ",x+1,"=",no) print("Final List:",no) 3 19 5 4 12 10no= 0 1 2 3 4 5 x=0 min=x K Outer loop [this is pass 1] y=2 y=3 y=4 3 19 5 4 12 10 min=3x=1 K=6(less than 6) if 4>12 FALSE min value remain same 3 19 5 4 12 10 y=4min=3 3 19 5 4 12 10
  • 21. SELECTION SORT: no=[10,19,5,4,12,3] K=len(no) for x in range(0,K): min = x for y in range(x + 1, K): if no[min]> no[y]: min = y temp= no[min]; no[min] = no[x] no[x]=temp print("Pass: ",x+1,"=",no) print("Final List:",no) 3 19 5 4 12 10no= 0 1 2 3 4 5 x=0 min=x K Outer loop [this is pass 1] y=2 y=3 y=4 y=5 3 19 5 4 12 10 min=3x=1 K=6(less than 6) If 4>10 FALSE min value remain same 3 19 5 4 12 10 y=5min=3 3 19 5 4 12 10 3 19 5 4 12 10
  • 22. SELECTION SORT: no=[10,19,5,4,12,3] K=len(no) for x in range(0,K): min = x for y in range(x + 1, K): if no[min]> no[y]: min = y temp= no[min]; no[min] = no[x] no[x]=temp print("Pass: ",x+1,"=",no) print("Final List:",no) 3 19 5 4 12 10no= 0 1 2 3 4 5 x=0 min=x K Outer loop [this is pass 1] y=2 y=3 y=4 y=5 3 19 5 4 12 10 min=3x=1 Now Swapping start tmp= 4 temp=no[min] 3 19 5 4 12 10 min=3 3 19 5 4 12 10 3 19 5 4 12 10 x=1 swap Inner loop finish no[min]=no[x]no[3]= 19 no[1]= 4 no[x]=temp101954 123 Pass 2 Final value:
  • 23. 101954 123 PASS 2 FINAL VALUE: Unsorted Value Sorted Value
  • 24. 101954 123 PASS 3 STARTS Where X=2 Sorted Value Y=x+1=3 K X=2 Inner loop Outer loop
  • 25. SELECTION SORT: no=[10,19,5,4,12,3] K=len(no) for x in range(0,K): min = x for y in range(x + 1, K): if no[min]> no[y]: min = y temp= no[min]; no[min] = no[x] no[x]=temp print("Pass: ",x+1,"=",no) print("Final List:",no) 3 1954 12 10no= 0 1 2 3 4 5 x=2 min=x K Outer loop [this is pass 3] Inner loop start where y starts from x+1 to K y=3 3 1954 12 10 min=2x=2 y=3 K=6(less than 6) If 5>19 FALSE min value remain same min=2
  • 26. SELECTION SORT: no=[10,19,5,4,12,3] K=len(no) for x in range(0,K): min = x for y in range(x + 1, K): if no[min]> no[y]: min = y temp= no[min]; no[min] = no[x] no[x]=temp print("Pass: ",x+1,"=",no) print("Final List:",no) 3 1954 12 10no= 0 1 2 3 4 5 x=0 min=x K Outer loop [this is pass 3] y=3 y=4 3 1954 12 10 min=2x=2 y=4 K=6(less than 6) If 5>12 FALSE min value remain same min=2 3 1954 12 10
  • 27. SELECTION SORT: no=[10,19,5,4,12,3] K=len(no) for x in range(0,K): min = x for y in range(x + 1, K): if no[min]> no[y]: min = y temp= no[min]; no[min] = no[x] no[x]=temp print("Pass: ",x+1,"=",no) print("Final List:",no) 3 1954 12 10no= 0 1 2 3 4 5 x=0 min=x K Outer loop [this is pass 3] y=3 y=4 y=5 3 1954 12 10 min=2x=2 K=6(less than 6) If 5>10 FALSE min value remain same 3 1954 12 10 y=5min=2 3 1954 12 10
  • 28. SELECTION SORT: no=[10,19,5,4,12,3] K=len(no) for x in range(0,K): min = x for y in range(x + 1, K): if no[min]> no[y]: min = y temp= no[min]; no[min] = no[x] no[x]=temp print("Pass: ",x+1,"=",no) print("Final List:",no) 3 1954 12 10no= 0 1 2 3 4 5 x=0 min=x K Outer loop [this is pass 3] y=3 y=4 y=5 min=2x=2 Now Swapping start tmp= 5 temp=no[min] 3 1954 12 10 min=2 3 1954 12 10 3 1954 12 10 x=2swap Inner loop finish no[min]=no[x]no[2]= 5 no[2]= 5 no[x]=temp101954 123 Pass 3 Final value:
  • 29. 101954 123 PASS 3 FINAL VALUE: Unsorted Value Sorted Value
  • 30. 101954 123 PASS 4 STARTS Where X=3 Sorted Value Y=x+1=4 K X=3 Inner loop Outer loop
  • 31. SELECTION SORT: no=[10,19,5,4,12,3] K=len(no) for x in range(0,K): min = x for y in range(x + 1, K): if no[min]> no[y]: min = y temp= no[min]; no[min] = no[x] no[x]=temp print("Pass: ",x+1,"=",no) print("Final List:",no) 3 1954 12 10no= 0 1 2 3 4 5 x=3 min=x K Outer loop [this is pass 4] Inner loop start where y starts from x+1 to K y=4 3 1954 12 10 min=3x=3 y=4 K=6(less than 6) If 19>12 TRUE min value change to 4 min=3
  • 32. SELECTION SORT: no=[10,19,5,4,12,3] K=len(no) for x in range(0,K): min = x for y in range(x + 1, K): if no[min]> no[y]: min = y temp= no[min]; no[min] = no[x] no[x]=temp print("Pass: ",x+1,"=",no) print("Final List:",no) 3 1954 12 10no= 0 1 2 3 4 5 x=3 min=x K Outer loop [this is pass 4] y=4 y=5 3 1954 12 10 min=4x=3 y=5 K=6(less than 6) If 12>10 TRUE min value change to 5 min=4 3 1954 12 10
  • 33. SELECTION SORT: no=[10,19,5,4,12,3] K=len(no) for x in range(0,K): min = x for y in range(x + 1, K): if no[min]> no[y]: min = y temp= no[min]; no[min] = no[x] no[x]=temp print("Pass: ",x+1,"=",no) print("Final List:",no) 3 1954 12 10no= 0 1 2 3 4 5 x=3 min=x K Outer loop [this is pass 4] y=4 y=5 min=5 x=3 Now Swapping start tmp= 10 temp=no[min] min=5 3 1954 12 10 3 1954 12 10 x=3 swap Inner loop finish no[min]=no[x]no[5]= 19 no[3]= 10 no[x]=temp191054 123 Pass 4 Final value:
  • 34. 10 1954 123 PASS 4 FINAL VALUE: Unsorted Value Sorted Value
  • 35. 10 1954 123 PASS 5 STARTS Where X=4 Sorted Value Y=x+1=5 K x=4 Inner loop Outer loop
  • 36. SELECTION SORT: no=[10,19,5,4,12,3] K=len(no) for x in range(0,K): min = x for y in range(x + 1, K): if no[min]> no[y]: min = y temp= no[min]; no[min] = no[x] no[x]=temp print("Pass: ",x+1,"=",no) print("Final List:",no) 3 1054 12 19no= 0 1 2 3 4 5 x=4 min=x K Outer loop [this is pass 5] Inner loop start where y starts from x+1 to K y=5 3 1054 12 19 min=4x=4 y=5 K=6(less than 6) If 12>19 FALSE min value remain same min=4
  • 37. SELECTION SORT: no=[10,19,5,4,12,3] K=len(no) for x in range(0,K): min = x for y in range(x + 1, K): if no[min]> no[y]: min = y temp= no[min]; no[min] = no[x] no[x]=temp print("Pass: ",x+1,"=",no) print("Final List:",no) 3 1054 12 19no= 0 1 2 3 4 5 x=3 min=x K Outer loop [this is pass 4] y=5 min=4 x=4 Now Swapping start tmp= 12 temp=no[min] min=4 3 1054 12 19 x=4 swap Inner loop finish no[min]=no[x]no[4]= 12 no[4]= 12 no[x]=temp191054 123 Pass 5 Final value:
  • 38. 10 1954 123 PASS 5 FINAL VALUE: Unsorted Value Sorted Value
  • 39. 10 1954 123 FINAL RESULT OF SELECTION SORT: Sorted Value