once againwe only return the first index if there is only one element in the list the arraylist[first:secondreturns an array with index up to the size of the list - when we find the index of the medianwe lose the portion in the list where it occurs because of the new range indexing the [first:secondcode returns thereforewe must add whatever index is returned by arraylist[first:secondto first to obtain the true index where the median was foundswap(unsorted_arrayfirst_indexindex_of_nearest_medianwe then swap the first element in unsorted_array with index_of_nearest_medianusing the swap function the utility function to swap two array elements is shown heredef swap(array_listfirstsecond)temp array_list[firstarray_list[firstarray_list[secondarray_list[secondtemp our approximate median is now stored at first_index of the unsorted list the partition function continues as it would in the code of the quick select algorithm after the partitioning stepthe array looks like thisdef deterministic_select(array_listleftrightk)split partition(array_listleftrightif split =kreturn array_list[splitelif split return deterministic_select(array_listsplit rightkelsereturn deterministic_select(array_listleftsplit-