KEMBAR78
Selection-sort-in-algorithm and complexity.pptx
By Group 3:
Martin Perocho
Joshua Velasco
Kian Manny Datu
Lovely Joy Senoron
Alaine Pasucal
Sunday Yvette Santos
SELECTION SORT IN ALGORITHM
AND COMPLEXITY
SELECTION SORT
• Selection sort is an effective and efficient sort algorithm based on comparison operations.
It adds one element in each iteration. You need to select the smallest element in the array
and move it to the beginning of the array by swapping with the front element
SELECTION SORT
• Selection sort is a simple sorting algorithm. This sorting algorithm, like insertion sort, is an
in-place comparison-based algorithm in which the list is divided into two parts, the sorted
part at the left end and the unsorted part at the right end. Initially, the sorted part is empty
and the unsorted part is the entire list.
• The smallest element is selected from the unsorted array and swapped with the leftmost
element, and that element becomes a part of the sorted array. This process continues
moving unsorted array boundaries by one element to the right.
• This algorithm is not suitable for large data sets as its average and worst case
complexities are of O(n2), where n is the number of items.
SELECTION SORT ALGORITHM
• This type of sorting is called Selection Sort as it works by repeatedly sorting elements.
That is: we first find the smallest value in the array and exchange 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 we continue the process in this way until the entire array is
sorted.
PSEUDO CODE FOR SELECTION SORT
ALGORITHM
• 1. Set min index to the first index of an unsorted array.
• 2. Iterate the entire unsorted array and do the comparison with min.
• 3. If the element present at the min index is greater than the element present at the
current index, then update min with the current index.
• 4. Once the iteration is complete, swap the element of the min index with the first element
of the unsorted part.
Flowchart for Selection Sort
Algorithm
Step 1:
For the first position in the sorted array,
the whole array is traversed from index
0 to 4 sequentially. The first position
where 64 is stored presently, after
traversing whole array it is clear
that 11 is the lowest value.
Thus, replace 64 with 11. After one
iteration 11, which happens to be the
least value in the array, tends to appear
in the first position of the sorted list.
Step 2:
For the second position, where 25 is
present, again traverse the rest of the
array in a sequential manner.
After traversing, we found that 12 is the
second lowest value in the array and it
should appear at the second place in the
array, thus swap these values.
Step 3:
Now, for third place, where 25 is present
again traverse the rest of the array and
find the third least value present in the
array.
While traversing, 22 came out to be the
third least value and it should appear at
the third place in the array, thus
swap 22 with element present at third
position.
Step 4:
Similarly, for fourth position traverse the
rest of the array and find the fourth least
element in the array
As 25 is the 4th lowest value hence, it
will place at the fourth position.
Step 5:
At last the largest value present in the
array automatically get placed at the last
position in the array
The resulted array is the sorted array.
THANK YOU!

Selection-sort-in-algorithm and complexity.pptx

  • 1.
    By Group 3: MartinPerocho Joshua Velasco Kian Manny Datu Lovely Joy Senoron Alaine Pasucal Sunday Yvette Santos SELECTION SORT IN ALGORITHM AND COMPLEXITY
  • 2.
    SELECTION SORT • Selectionsort is an effective and efficient sort algorithm based on comparison operations. It adds one element in each iteration. You need to select the smallest element in the array and move it to the beginning of the array by swapping with the front element
  • 3.
    SELECTION SORT • Selectionsort is a simple sorting algorithm. This sorting algorithm, like insertion sort, is an in-place comparison-based algorithm in which the list is divided into two parts, the sorted part at the left end and the unsorted part at the right end. Initially, the sorted part is empty and the unsorted part is the entire list. • The smallest element is selected from the unsorted array and swapped with the leftmost element, and that element becomes a part of the sorted array. This process continues moving unsorted array boundaries by one element to the right. • This algorithm is not suitable for large data sets as its average and worst case complexities are of O(n2), where n is the number of items.
  • 4.
    SELECTION SORT ALGORITHM •This type of sorting is called Selection Sort as it works by repeatedly sorting elements. That is: we first find the smallest value in the array and exchange 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 we continue the process in this way until the entire array is sorted.
  • 5.
    PSEUDO CODE FORSELECTION SORT ALGORITHM • 1. Set min index to the first index of an unsorted array. • 2. Iterate the entire unsorted array and do the comparison with min. • 3. If the element present at the min index is greater than the element present at the current index, then update min with the current index. • 4. Once the iteration is complete, swap the element of the min index with the first element of the unsorted part.
  • 6.
  • 7.
    Step 1: For thefirst position in the sorted array, the whole array is traversed from index 0 to 4 sequentially. The first position where 64 is stored presently, after traversing whole array it is clear that 11 is the lowest value. Thus, replace 64 with 11. After one iteration 11, which happens to be the least value in the array, tends to appear in the first position of the sorted list.
  • 8.
    Step 2: For thesecond position, where 25 is present, again traverse the rest of the array in a sequential manner. After traversing, we found that 12 is the second lowest value in the array and it should appear at the second place in the array, thus swap these values.
  • 9.
    Step 3: Now, forthird place, where 25 is present again traverse the rest of the array and find the third least value present in the array. While traversing, 22 came out to be the third least value and it should appear at the third place in the array, thus swap 22 with element present at third position.
  • 10.
    Step 4: Similarly, forfourth position traverse the rest of the array and find the fourth least element in the array As 25 is the 4th lowest value hence, it will place at the fourth position.
  • 11.
    Step 5: At lastthe largest value present in the array automatically get placed at the last position in the array The resulted array is the sorted array.
  • 12.