Sort the given unsorted array 'arr' of size 'N' in non-decreasing order using the selection sort algorithm.
Change in the input array/list itself.
Input:
N = 5
arr = {8, 6, 2, 5, 1}
Output:
1 2 5 6 8
Explanation:

First line contains an integer 'N' representing the size of the array/list.
Second line contains 'N' single space separated integers representing the elements in the array/list.
Output format :
The output contains the integers of the sorted array, separated by a single space.
Note:-
You don’t need to print anything. Just implement the given function.
6
2 13 4 1 3 6
1 2 3 4 6 13
Select 1 and swap with element at index 0. arr= {1,13,4,2,3,6}
Select 2 and swap with element at index 1. arr= {1,2,4,13,3,6}
Select 3 and swap with element at index 2. arr= {1,2,3,13,4,6}
Select 4 and swap with element at index 3. arr= {1,2,3,4,13,6}
Select 6 and swap with element at index 4. arr= {1,2,3,4,6,13}
5
9 3 6 2 0
0 2 3 6 9
1 <= N <= 10^3
0 <= arr[i] <= 10^5
Time Limit: 1 sec
Repeatedly find the minimum element in the unsorted part of the array and swap it with the first element of the unsorted part.
Approach:
The selection sort algorithm works by repeatedly selecting the smallest element from the unsorted part of the array and moving it to the beginning of the unsorted part. This process is done iteratively until the entire array is sorted.
Here is the step-by-step approach for selection sort:
Algorithm:
function selectionSort(arr):
O(N^2), where ‘N’ is the number of length of array.
The algorithm consists of two nested loops. The outer loop runs n-1 times, as it iterates from the first element to the second-to-last element of the array. The inner loop runs from i+1 to n-1, which is also approximately n iterations on average.
Therefore, the total number of comparisons and updates performed by the algorithm is approximately (n-1) + (n-2) + ... + 1, which is equal to (n * (n-1)) / 2. This gives us the time complexity of O(n^2) for the selection sort algorithm.
O(1)
No extra space is used.