Linked list
A list where each element, called a node, stores its value and where the next one is. Nodes can be anywhere in memory, joined like links in a chain.
Example
Adding a node at the start is 1 step: the new one points to the old first. But to reach element 500 you have to pass the 499 before it.
Test yourself: Linked list
Linked lists
What does each node of a linked list store?
A node with value 7 stores the 7 and, for example, address 2,048 where the next one is. With that address you jump to the next.
Linked lists
Inserting a node when you already know where it goes costs O(___) in a linked list.
Only 2 references change. In an array of 1 million, inserting at the start shifts 1 million elements.
Linked lists
To remove P from A → P → B, it's enough for A to point to ___.
With A → B, walking from the head no longer passes P. It was 1 change, in a list of 4 or 4 million.
0/3
â–¶ PlayLessons that use it
What is an algorithm
You already use algorithms
Measuring efficiency
Fast and light on memory
Types of structures
How they relate and where they live
Arrays
Adjacent cells
Linked lists
Links of a chain
Dynamic lists
An array that grows by itself
Memory and cache
Close is fast
Stacks
Last in, first out
Queues
First in, first out
Deques
In and out at both ends
Hash collisions
When 2 keys want the same spot
Binary trees
Each node, at most 2 children
Graphs
Points and connections
Merge sort
Split in half and merge in order
