Tells the basic data structure in memory, array is good at finding the element, the list is good at finding the position, in order to adapt to the data different operation request, should use flexibly.
1. How the Memory Works
Computer memory is like a cupboard with many drawers.
2. Arrays and Linked lists
The position of the element in the array is called the index element xx at index XX
The time complexity of the array and the different operations of the linked list
3. Select sort
Definition: Iterate over this array, remove the largest element to the new array and delete the largest element in the tuple, and iterate over the array again ... Until the original array is empty
Python implementation selection sort
def findSmallest(arr): smallest = arr[0] smallest_index = 0 for i in range(1, len(arr)): if arr[i] < smallest: smallest = arr[i] smallest_index = i return smallest_indexdef selectionSort(arr): newArr = [] for i in range(len(arr)): smallest = findSmallest(arr) newArr.append(arr.pop(smallest)) return newArrprint(selectionSort([5, 3, 6, 2, 10])) # [2, 3, 5, 6, 10]
Selection and sequencing of algorithm plots