text: Recursive Selection Sort | Return minimum index ; Find minimum of remaining elements ; Return minimum of current and remaining . ; Recursive selection sort . n is size of a [ ] and index is index of starting element . ; Return when starting and size are same ; calling minimum index function for minimum index ; Swapping when index and minimum index are not same ; swap ; Recursively calling selection sort function ; Driver code ; Calling function ; printing sorted array
code: def minIndex ( a , i , j ) : NEW_LINE INDENT if i == j : NEW_LINE INDENT return i NEW_LINE DEDENT k = minIndex ( a , i + 1 , j ) NEW_LINE return ( i if a [ i ] < a [ k ] else k ) NEW_LINE DEDENT def recurSelectionSort ( a , n , index = 0 ) : NEW_LINE INDENT if index == n : NEW_LINE INDENT return - 1 NEW_LINE DEDENT k = minIndex ( a , index , n - 1 ) NEW_LINE if k != index : NEW_LINE INDENT a [ k ] , a [ index ] = a [ index ] , a [ k ] NEW_LINE INDENT a [ k ] , a [ index ] = a [ index ] , a [ k ] NEW_LINE DEDENT DEDENT recurSelectionSort ( a , n , index + 1 ) NEW_LINE DEDENT arr = [ 3 , 1 , 5 , 2 , 7 , 0 ] NEW_LINE n = len ( arr ) NEW_LINE recurSelectionSort ( arr , n ) NEW_LINE for i in arr : NEW_LINE INDENT print ( i , end = ' ▁ ' ) NEW_LINE DEDENT