The Selection Sort algorithm sorts maintains two parts.
- First part that is already sorted
- Second part that is yet to be sorted.
The algorithm works by repeatedly finding the minimum element (considering ascending order) from unsorted part and putting it at the end of sorted part.
arr = 64 25 12 22 11 // Find the minimum element in arr[0...4] // and place it at beginning 11 25 12 22 64 // Find the minimum element in arr[1...4] // and place it at beginning of arr[1...4] 11 12 25 22 64 // Find the minimum element in arr[2...4] // and place it at beginning of arr[2...4] 11 12 22 25 64 // Find the minimum element in arr[3...4] // and place it at beginning of arr[3...4] 11 12 22 25 64
We have already discussed about Iterative Selection Sort. In this article recursive approach is discussed. The idea of recursive solution is to one by one increment sorted part and recursively call for remaining (yet to be sorted) part.
0 1 2 3 5 7
This article is contributed by Sahil Rajput. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Comparison among Bubble Sort, Selection Sort and Insertion Sort
- Recursive selection sort for singly linked list | Swapping node links
- Program to sort an array of strings using Selection Sort
- Selection Sort
- C++ program for Sorting Dates using Selection Sort
- A sorting algorithm that slightly improves on selection sort
- Stable Selection Sort
- 8086 program for selection sort
- Iterative selection sort for linked list
- Sorting Algorithms Visualization | Selection Sort
- C program for Time Complexity plot of Bubble, Insertion and Selection Sort using Gnuplot
- Recursive Bubble Sort
- Recursive Insertion Sort
- C++ Program for Recursive Bubble Sort
- Java Program for Recursive Bubble Sort
- C Program for Recursive Insertion Sort
- Java Program for Recursive Insertion Sort
- Python Program for Recursive Insertion Sort
- Job Selection Problem - Loss Minimization Strategy | Set 2
- Why Quick Sort preferred for Arrays and Merge Sort for Linked Lists?
Improved By : princi singh