Selection Sort Algorithms | How to sort an Array/List using Selection sort?

Selection Sort is a efficient and simple algorithms for sorting the elements by repeatedly selecting the largest or smallest element from the unsorted portion of the list and moving it to the sorted portion of the list. Lets go in deep dive.

Selection sort algorithm
Selection sort algorithm

Steps to follow for Selection Sort Algorithms

In this type of sort, pick the smallest element from the list and push it to beginning of the list by iterating two loops.

  • Pick smallest element in one iteration and do only single swipe.
  • Run the inner loop from next element j+1 till the length.
  • Compare that the min element is greater than the next element, if yes then swipe after completing the iteration.

Java

Dart

Same approach follows in the dart programming, only the way of declaring of variables changes.

Time Complexity and Auxiliary Space Analysis

Time Complexity: O(N2) due to two iterations. We are looping the an array two times that why the time complexity is O(N2).

Auxiliary Space : O(1)

Do you know Bubble Sort Algorithms in DSA? See more examples.

Thank you for reaching out us. You can look into more Data Structure Tutorials from here. In case of any question, query and doubt, you can comment in the comment section below.

Donโ€™t miss new tips!

We donโ€™t spam! Read our [link]privacy policy[/link] for more info.

Leave a Comment

Translate ยป
Scroll to Top