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
- Sorting Algorithms Visualization | Selection Sort
- C++ program for Sorting Dates using Selection Sort
- Iterative selection sort for linked list
- A sorting algorithm that slightly improves on 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 Insertion Sort
- C++ Program for Recursive Bubble Sort
Improved By : princi singh