Selection Sort
Given an integer array nums of size n, sort the array in ascending order using the Selection Sort algorithm.
Selection Sort repeatedly finds the smallest element from the unsorted part of the array and places it at the beginning.
Return the sorted array.
Example 1
Input
5 64 25 12 22 11
Output
11 12 22 25 64
Explanation
In each pass, Selection Sort finds the smallest element from the unsorted portion of the array and swaps it with the first unsorted element.
After all passes, the array becomes sorted in ascending order.
Example 2
Input
6 5 4 3 2 1 0
Output
0 1 2 3 4 5
Explanation
The algorithm repeatedly selects the minimum element and places it in its correct position until the entire array is sorted.
Constraints
Hints:
Hint 1
For each position i, find the smallest element from index i to the end of the array.
Hint 2
Swap the smallest element with the element at index i. Repeat this process until the array is sorted.
Author & Technical Reviewer
Technically reviewed by: ExamAdda Technical Review Team
Technical Reviewers, ExamAdda
Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.
Published
Jul 21, 2026
Last updated
Aug 6, 2026
Content Verification Methodology
Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.
Expected Output