DONE BY:
D.STELLA
CSE B SECTION
140071601073
B.S.ABDUR RAHMAN UNIVERSITY
VANDALORE,CHENNAI.
SELECTION SORT
SELECTION SORT
selection sort is a sorting algorithm,
specifically an in-place comparison sort.
It has O(n2
) time complexity, making it
inefficient on large lists, and generally
performs worse than the similar
insertion sort.
ALGORITHM FOR SELECTION SORT
The list is divided in to two sublist ,sorted and
unsorted by an imajinary wall.
We find a smallest element from the unsorted sublist
and swap it with the element at the beginning of
unsorted data.
After each selection and swapping in the imajinary
wall between sublist move one element ahead,
increasingly the number of sorted elements and
decreases the number of unsorted one.
The process of moving one element from the
unsorted list to sorted list is called a pass.
A list of n elements requires n-1 passes to complete
the sorting.
86 32 961951 23
 This is unsorted list. Lets find the smallest
element from the unsorted list.
Then swap the element with the element at
the beginning of the unsorted list.
Lets find the smaller number
86 32 961951 23
Selecting the smaller
86 32 961951 23
Selecting the smaller
86 32 961951 23
Selecting the smaller
86 32 961951 23
Selecting the smaller
86 32 961951 23
Selecting the smaller
86 32 961951 23
From this sorted list, the smallest element is 19.
According to the algorithm,the smallest number is
replaced in the beginning of the unsorted list.
This is first pass. Pass is defined as the the
process of moving one element from the unsorted
list to the sorted list.
Pass 1
19 32 968651 23
Now,the list is divided in to two sublist
sorted and unsorted list
Then,find the smallest element in the unsorted list.
once again follow the same procedure.
sorted unsorted
Selecting the smaller
Selecting the smaller
Selecting the smaller
Selecting the smaller
19 32 968651 23
Now,from the unsorted list ,the smallest element is
23. so replace it by same manner.
19 32 968651 23
19 23 51 86 32 96
Now the list becomes changed.
The list is divided in to sorted and unsorted list.
Pass 2
19 23 968651 32
Selecting the smaller
19 23 968651 32
Selecting the smaller
19 23 968651 32
Selecting the smaller
19 23 968651 32
smaller
Now,the list is rearranged.
19 23 86 51 9632
Pass 3
19 23 968632 51
Selecting the smaller
19 23 968632 51
Selecting the smaller
19 23 968632 51
smaller
Selecting the smaller
19 23 965132 86
Selecting the smaller
19 23 965132 86
While checking the remaining elements,they
are automatically arranged in order.
19 23 965132 86
Pass 4
19 23 965132 86
SORTED LIST
PSEUDO CODE FOR SELECTION SORT
for(i=0;i<n-1;i++)
{
min=i;
For(j=i+1;j<n;j++)
If(a[j]<a[min})
Min=j;
Swap(a[i},a[min}
}
}
Pass 5
Selection sort

Selection sort

  • 1.
    DONE BY: D.STELLA CSE BSECTION 140071601073 B.S.ABDUR RAHMAN UNIVERSITY VANDALORE,CHENNAI. SELECTION SORT
  • 2.
    SELECTION SORT selection sort isa sorting algorithm, specifically an in-place comparison sort. It has O(n2 ) time complexity, making it inefficient on large lists, and generally performs worse than the similar insertion sort.
  • 3.
    ALGORITHM FOR SELECTIONSORT The list is divided in to two sublist ,sorted and unsorted by an imajinary wall. We find a smallest element from the unsorted sublist and swap it with the element at the beginning of unsorted data. After each selection and swapping in the imajinary wall between sublist move one element ahead, increasingly the number of sorted elements and decreases the number of unsorted one. The process of moving one element from the unsorted list to sorted list is called a pass. A list of n elements requires n-1 passes to complete the sorting.
  • 4.
    86 32 96195123  This is unsorted list. Lets find the smallest element from the unsorted list. Then swap the element with the element at the beginning of the unsorted list. Lets find the smaller number
  • 5.
    86 32 96195123 Selecting the smaller
  • 6.
    86 32 96195123 Selecting the smaller
  • 7.
    86 32 96195123 Selecting the smaller
  • 8.
    86 32 96195123 Selecting the smaller
  • 9.
    86 32 96195123 Selecting the smaller
  • 10.
    86 32 96195123 From this sorted list, the smallest element is 19. According to the algorithm,the smallest number is replaced in the beginning of the unsorted list. This is first pass. Pass is defined as the the process of moving one element from the unsorted list to the sorted list. Pass 1
  • 11.
    19 32 96865123 Now,the list is divided in to two sublist sorted and unsorted list Then,find the smallest element in the unsorted list. once again follow the same procedure. sorted unsorted
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
    19 32 96865123 Now,from the unsorted list ,the smallest element is 23. so replace it by same manner.
  • 17.
    19 32 96865123 19 23 51 86 32 96 Now the list becomes changed. The list is divided in to sorted and unsorted list. Pass 2
  • 18.
    19 23 96865132 Selecting the smaller
  • 19.
    19 23 96865132 Selecting the smaller
  • 20.
    19 23 96865132 Selecting the smaller
  • 21.
    19 23 96865132 smaller Now,the list is rearranged. 19 23 86 51 9632 Pass 3
  • 22.
    19 23 96863251 Selecting the smaller
  • 23.
    19 23 96863251 Selecting the smaller
  • 24.
    19 23 96863251 smaller Selecting the smaller
  • 25.
    19 23 96513286 Selecting the smaller
  • 26.
    19 23 96513286 While checking the remaining elements,they are automatically arranged in order.
  • 27.
    19 23 96513286 Pass 4
  • 28.
    19 23 96513286 SORTED LIST PSEUDO CODE FOR SELECTION SORT for(i=0;i<n-1;i++) { min=i; For(j=i+1;j<n;j++) If(a[j]<a[min}) Min=j; Swap(a[i},a[min} } } Pass 5