Selection Sort🛫

Tehleel Mir
1 min readFeb 28, 2022
Photo by Brienne Hong on Unsplash

selection sort is a sorting algorithm that is used to sort an array/list.

Time Complexity
The time complexity of the selection sort is O(n²). i.e. Quadratic time.

Explanation
In Selection sort, we do the following operations:

  • First, pick an element from a list
  • Second, we compare that element with the other remaining elements in this list.
  • Repeat step first until the list is empty.

So, we have to perform step first for every element in the list, and the time complexity for that is O(n)
And then we have to compare that element with the other remaining elements in the list, and the time complexity for that is O(n — z), where z is the number of elements we have already checked, but since we ignore constants in Big O notation, so instead of writing O(n — z) we will just write it as O(n)

So we have O(n * n) time complexity for the whole algorithm, which we can also write as O(n²).

Code

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response