Posts

Presume a value as initial, update its value in the loop

Image
0 I am learning selection sort algorithms from typing import List def find_smallest(arr:List) -> int: smallest = arr[0] #set pivot smallest_index = 0 for i in range(1, len(arr)): if arr[i] < smallest: smallest = arr[i] smallest_index = i return smallest_index def selection_sort(arr) -> List: new_arr = for i in range(len(arr)): smallest = find_smallest(arr) new_arr.append(arr.pop(smallest)) return new_arr I am curious about the function find_smallest , it firstly presume arr[0] as the smallest and initiate the loop. I know the complete code is called selection sort algorithms, How about the presume and update its value in the loop, is there an terminology for it? ...