# Introduction to Selection Sort

## Sorting algorithm 01

Mar 2 · 3 min read
• In each iteration, find the maximum/minimum element in the unsorted subarray and swap it with the first element of the unsorted subarray. After swapping, the first element of the unsorted subarray will be appended to the sorted subarray. Swapping the minimum value will sort the elements in ascending order while swapping the maximum value will sort the elements in descending order.
• Continue the iteration until the last element

## Analysis of Selection Sort

1. Selection sort is an in-place algorithm which means it does not require additional memory space to perform sorting.
2. The time complexity is O(n²). Suppose the number of elements to be sorted is n, initially, the minimum value should be found among n elements which requires (n-1) comparisons. In the next iteration, it requires (n-2) comparisons. The following figure shows the number of comparisons required in each iteration.

## Nerd For Tech

From Confusion to Clarification

Written by

A Computer Science Research Student who loves to do Research, Write and Travel

## Nerd For Tech

An Educational Media House

Written by

A Computer Science Research Student who loves to do Research, Write and Travel

## Nerd For Tech

An Educational Media House

## Your First Open Source Contribution

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app