Chapter 2
Translated from Chinese by an LLM.
Memory
An array occupies contiguous space; each access reads base address + index, so the complexity is .
A linked list occupies non-contiguous space; each access follows the next address, so the complexity is .
Comparison table for insert, delete, update, and query:
| Operation | Array | Linked List |
|---|---|---|
| Insert | ||
| Delete | ||
| Update | ||
| Query |
Selection Sort
Selection sort has the same complexity as bubble sort: . Painfully slow.
As shown:
The principle is to pick the smallest (or largest) element each time and place it in order until sorted.