Professional Documents
Culture Documents
Mohammad Ali Jinnah University Computer Programming Assignment 03
Mohammad Ali Jinnah University Computer Programming Assignment 03
Computer Programming
Assignment 03
Let’s Sort
1. Test the algorithm on the numbers of elements equal to the number of alphabets your
first name has.
2. Test the algorithm on the array of marks you got in mid exams.
HELP ME!
For more clarity the illustration and example of the above algorithm is given below.
0 1 2 3 4 5 6
6 -->First 2 5 8 1 9 10
6-->First 2 5 8 1 9 10
- Step b will swap the smallest element found with first element of the array
- Now the first element is sorted, and the first will move to the next position.
0 1 2 3 4 5 6
1 2--->First 5 8 6 9 10
0 1 2 3 4 5 6
1 2--->First 5 8 6 9 10
2 will be replaced with the first/start element so it remains in the same position. Second
element is also sorted and the third element is the first/start now.
0 1 2 3 4 5 6
1 2 5--->First 8 6 9 10
1 2 5--->First 8 6 9 10
5 will be replaced with the first/start element so it remains in the same position. Third element
is also sorted and the fourth element is the first/start now.
0 1 2 3 4 5 6
0 1 2 3 4 5 6
1 2 5 8--->First 6 9 10
0 1 2 3 4 5 6
1 2 5 8--->First 6 9 10
In step b, 6 will be swapped with the first of the array which is 8 and start will move to the next
position.
0 1 2 3 4 5 6
1 2 5 6 8--->First 9 10
0 1 2 3 4 5 6
1 2 5 6 8--->First 9 10
In step b, 8 will remain in the same position as that’s the first element of the array. Fifth
element of the array is sorted so the start will move to the next position.
0 1 2 3 4 5 6
1 2 5 6 8 9--->First 10
0 1 2 3 4 5 6
1 2 5 6 8 9--->First 10
In step b, 9 will remain in the same position as that’s the first element of the array. Sixth
element of the array is sorted so the start will move to the next position.
0 1 2 3 4 5 6
1 2 5 6 8 9 10-->First
If the start of the array is the last index then no need to repeat any more. Array is said to be
sorted.
0 1 2 3 4 5 6
1 2 5 6 8 9 10