Assignment of Discrete Mathematics: TOPIC: Algorithms
Assignment of Discrete Mathematics: TOPIC: Algorithms
Mathematics
TOPIC: Algorithms
Bubble Sort
1. Repeat step 2 to 4 for k=1 to n-1 by 1
2. Repeat step 3 to 4 for j=0 to n by 1
3. if a[ j ] >a[ j+1]
temp= a[ j ]
a[ j ] = a[ j+1]
a[ j+1] = temp
[End if]
[End loop]
4. End
Selection Sort
1. Repeat step 2 to 10 for i=1 to n by 1
2. Max=0
3. j=max+1
4. n=5
5. Repeat step 7 to 8 while( j < n)
6. If a[max]<a[j] then
7. Max=j
End if
8. j=j+1
[End while loop]
9. n=n-1
Temp=a[j]
a[j] =a[max]
a [max] =temp
[end for loop]
10. End
Insertion Sort
1. Repeat step 2 to 6 for c=1 to n by 1
2. Temp=a[c]
3. j=c
4. Repeat step 5 while( j>0 and temp<a[ j-1])
5. a[j]= a[j-1]
j=j-1
[End while loop]
6. a[j]= Temp
[End for loop]
7. End