VOOZH about

URL: https://www.geeksforgeeks.org/dsa/recursive-selection-sort/

⇱ Recursive Selection Sort - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Recursive Selection Sort

Last Updated : 17 Mar, 2023

The Selection Sort algorithm sorts maintain two parts. 

  1. The first part that is already sorted
  2. The second part is yet to be sorted.

The algorithm works by repeatedly finding the minimum element (considering ascending order) from the unsorted part and putting it at the end of the 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 Iterative Selection Sort. In this article recursive approach is discussed. The idea of a recursive solution is to one by one increment sorted part and recursively call for the remaining (yet to be sorted) part.

Output: 
 

0 1 2 3 5 7 

Time Complexity: O(n2)
Auxiliary Space: O(n)


 

Comment
Article Tags:
Article Tags: