0% found this document useful (0 votes)
20 views5 pages

Selection Sort

Uploaded by

kushalkansal0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views5 pages

Selection Sort

Uploaded by

kushalkansal0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Selection Sort

Selection Sort is a comparison-based sorting algorithm. It sorts an array by repeatedly


selecting the smallest element from the unsorted portion and swapping it with the first
unsorted element. This process continues until the entire array is sorted.
1. First we find the smallest element and swap it with the first element.
2. Then we find the second smallest and swap it with the second element.
3. We keep doing this until we get all elements moved to correct position.
The Selection Sort algorithm finds the lowest value in an array and moves it to the
front of the array.
Algorithm
Here are the steps of the Selection Sort algorithm:
1. Start with the first element of the array as the current minimum.
2. Compare the current minimum with the remaining unsorted elements to find the
smallest element.
3. Swap the smallest element with the first element of the unsorted part.
4. Move the boundary between the sorted and unsorted parts one element to the right.
5. Repeat steps 1-4 until the entire array is sorted.
Complexity of Selection Sort
1 Time Complexity:
 Worst-Case Complexity (): This occurs when the array is in reverse order, requiring
the maximum number of comparisons and swaps.

 Average-Case Complexity (): On average, each element must be compared with


half of the remaining unsorted elements.
 Space Complexity:
 Selection Sort is an in-place algorithm, meaning it does not require additional space
for another array. Its space complexity is .

You might also like