跳至内容

Chapter 2

Translated from Chinese by an LLM.

Memory

An array occupies contiguous space; each access reads base address + index, so the complexity is O(1)O(1).
A linked list occupies non-contiguous space; each access follows the next address, so the complexity is O(n)O(n).
Comparison table for insert, delete, update, and query:

OperationArrayLinked List
InsertO(n)O(n)O(1)O(1)
DeleteO(n)O(n)O(1)O(1)
UpdateO(1)O(1)O(n)O(n)
QueryO(1)O(1)O(n)O(n)

Selection Sort

Selection sort has the same complexity as bubble sort: O(n2)O(n^2). Painfully slow.
As shown: svg
The principle is to pick the smallest (or largest) element each time and place it in order until sorted.