Reading Notes: "Algorithm Illustration" Chapter 2 Selection Sort

  • Array: The so-called array is an unordered sequence of elements. All elements in an array have the same type (unlike fields in a struct or class, which can be of different types). Elements in an array are stored in a contiguous block of memory and accessed by index (unlike fields in structures and classes, which are accessed by name).

  • Linked list: A linked list is a non-consecutive, non-sequential storage structure on a physical storage unit. The logical order of data elements is achieved through the link order of pointers in the linked list. A linked list consists of a series of nodes (each element in the linked list is called a node), and nodes can be dynamically generated at runtime. Each node consists of two parts: one is the data field that stores the data element, and the other is the pointer field that stores the address of the next node. Compared with the linear table sequential structure, the operation is complicated. Since it does not have to be stored in order, a linked list can achieve O(1) complexity when inserting, which is much faster than another linear list sequential list, but it takes O(n) to find a node or access a specific number of nodes time, and the corresponding time complexity of linear table and sequential table are respectivelyO(logn)O(log⁡n)andO(1)O(1). There are many different types of linked lists: singly linked lists, doubly linked lists, and circular linked lists.

Linked lists are good at insertion and deletion, and arrays are good at random access.

Selection sort: #

Selection sort is a simple and intuitive sorting algorithm. Its working principle is to select the smallest (or largest) element from the data elements to be sorted each time, and store it at the beginning of the sequence until all the data elements to be sorted are exhausted. Selection sort is an unstable sorting method (for example, the sequence [5, 5, 3] swaps the first [5] with [3] for the first time, causing the first 5 to move behind the second 5).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326445101&siteId=291194637