\
home Home
sort Sorts
Bubble Sort Insertion Sort Counting Sort
SORTING VISUALIZER - SELECTION SORT

  SelectionSort(A[],n)

    1.   For i = 0 to n - 2

    2.     min =i

    3.     For j =i+1 to n-1

    4.       If A[j] < A[min])

    5.         min = j

    6.     End For

    7.     swap A[min] <-> A[i];


No of Comparisons:



     

Complexity

Time
Space
Best Case Average Case Worst Case
O(1)
O(n)
O(n2)
O(n2)

Selection Sort

What is the working mechanism of Selection Sort ?

Selection sort is a simple sorting algorithm that sorts an array by repeatedly finding the minimum element from unsorted part of the array and placing it at the beginning of the sorted part of the array.


Is selection sort a stable, in-place sorting algorithm or an out-of-place sorting algorithm?

Selection sort is an unstable in-place algorithm, meaning that it does not require any extra space but can't maintain the relative order of duplicates.


How does the number of elements impact the efficiency of Selection sort?

The time complexity of selection sort is O(n^2), where n is the number of elements in the array. This means that the efficiency of selection sort is directly impacted by the number of elements in the array. As the number of elements increases, the time taken to sort the array using selection sort also increases.


What are advantages and disadvantages of Selection Sort?

Advantages:

  • Works well with small datasets.
  • It does not require any additional memory space.
  • It's adaptability to different types of data.
  • It is easy to modify to sort in ascending or descending order.

  • Disadvantages:
    • Selection sort has a time complexity of O(n^2) in the worst and average case.
    • Not adaptive, meaning it doesn’t take advantage of the fact that the list may already be sorted or partially sorted