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.
- Recursive selection sort for singly linked list | Swapping node links
- Comparison among Bubble Sort, Selection Sort and Insertion Sort
- Program to sort an array of strings using Selection Sort
- Selection Sort
- Stable Selection Sort
- 8086 program for selection sort
- Iterative selection sort for linked list
- C++ program for Sorting Dates using Selection Sort
- A sorting algorithm that slightly improves on selection sort
- Recursive Insertion Sort
- Recursive Bubble Sort
- C++ Program for Recursive Bubble Sort
- C Program for Recursive Insertion Sort
- Java Program for Recursive Bubble Sort
- Java Program for Recursive Insertion Sort