KEMBAR78
Selection sorting | PPTX
A SEMINAR ON
SELECTION
SORT
Presented To-
Mr. K.S.Bumrah
Asst. Proff.
Deptt. Of C.S.E
Presented By-
Kunal kesharwani
Contents
 Description.
 Sort Algorithm.
 Example.
 Analysis.
 Advantages of Sorting Algorithms.
 Disadvantages of Sorting Algorithms.
Description
 This sorting algorithm 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.
Description Contd.
 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
boundary by one element to the right
 each time selecting an item according to its ordering
and placing it in the correct position in the sequence.
The Selection Sort Algorithm
 For each index position i
 Find the smallest data value in the array from positions i
through length - 1 , where length is the number of data
values stored.
 Exchange (swap) the smallest value with the value at
position i.
Algorithm
 Step 1 − Set MIN to location 0
 Step 2 − Search the minimum element in the list
 Step 3 − Swap with value at location MIN
 Step 4 − Increment MIN to point to next element
 Step 5 − Repeat until list is sorted
Example
 Unsorted list:
 1st iteration:
 Smallest = 5
 2 < 5, smallest = 2
 1 < 2, smallest = 1
 4 > 1, smallest = 1
 3 > 1, smallest = 1
Swap 5 and 1
5 2 1 4 3
1 2 5 4 3
Example contd.
 2nd iteration:
 Smallest = 2
 2 < 5, smallest = 2
 2 < 4, smallest = 2
 2 < 3, smallest = 2
 No swap
1 2 5 4 3
Example contd.
 3rd iteration:
 Smallest = 5
 4 < 5, smallest = 4
 3 < 4, smallest = 3
 Swap 5 and 3
1 2 3 4 5
Example contd.
 4th iteration:
 Smallest = 4
 4 < 5, smallest = 4
 No swap
 Finally, the sorted list is
1 2 3 4 5
1 2 3 4 5
Selection Sort: Analysis
Complexity:
 Best case performanceО(n2)
 Average case performanceО(n2)
 Worst case performanceО(n2)
Advantages & Disadvantages
Advantages Disadvantages
 The main advantage of the
selection sort is that it performs
well on a small list.
 no additional temporary
storage is required.
 The primary disadvantage of
the selection sort is its poor
efficiency when dealing with
a huge list of items.
 the selection sort requires n-
squared number of steps for
sorting n elements.
Selection sorting

Selection sorting

  • 1.
    A SEMINAR ON SELECTION SORT PresentedTo- Mr. K.S.Bumrah Asst. Proff. Deptt. Of C.S.E Presented By- Kunal kesharwani
  • 2.
    Contents  Description.  SortAlgorithm.  Example.  Analysis.  Advantages of Sorting Algorithms.  Disadvantages of Sorting Algorithms.
  • 3.
    Description  This sortingalgorithm 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.
  • 4.
    Description Contd.  Thesmallest 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 boundary by one element to the right  each time selecting an item according to its ordering and placing it in the correct position in the sequence.
  • 5.
    The Selection SortAlgorithm  For each index position i  Find the smallest data value in the array from positions i through length - 1 , where length is the number of data values stored.  Exchange (swap) the smallest value with the value at position i.
  • 6.
    Algorithm  Step 1− Set MIN to location 0  Step 2 − Search the minimum element in the list  Step 3 − Swap with value at location MIN  Step 4 − Increment MIN to point to next element  Step 5 − Repeat until list is sorted
  • 7.
    Example  Unsorted list: 1st iteration:  Smallest = 5  2 < 5, smallest = 2  1 < 2, smallest = 1  4 > 1, smallest = 1  3 > 1, smallest = 1 Swap 5 and 1 5 2 1 4 3 1 2 5 4 3
  • 8.
    Example contd.  2nditeration:  Smallest = 2  2 < 5, smallest = 2  2 < 4, smallest = 2  2 < 3, smallest = 2  No swap 1 2 5 4 3
  • 9.
    Example contd.  3rditeration:  Smallest = 5  4 < 5, smallest = 4  3 < 4, smallest = 3  Swap 5 and 3 1 2 3 4 5
  • 10.
    Example contd.  4thiteration:  Smallest = 4  4 < 5, smallest = 4  No swap  Finally, the sorted list is 1 2 3 4 5 1 2 3 4 5
  • 12.
    Selection Sort: Analysis Complexity: Best case performanceО(n2)  Average case performanceО(n2)  Worst case performanceО(n2)
  • 13.
    Advantages & Disadvantages AdvantagesDisadvantages  The main advantage of the selection sort is that it performs well on a small list.  no additional temporary storage is required.  The primary disadvantage of the selection sort is its poor efficiency when dealing with a huge list of items.  the selection sort requires n- squared number of steps for sorting n elements.