Arrays and linked lists
How to count the cost of an operation, what arrays make cheap and expensive, and how linked lists give up indexing in return for easy insertion.
About 9 hours of study
Learning objectives
- Describe growth with Big-O
- Insert and delete in an array by shifting
- Build singly and doubly linked lists
- Handle the first, the last and the only node correctly
Lessons
- 1
What a data structure is
A way to store data so the operations you need are fast, and how to count the cost of an operation.
- 2
Arrays: insert, delete and 2D arrays
Insert and delete by shifting, keep a count next to the capacity, and see how a 2D array sits in memory.
- 3
Singly linked lists
Append with a tail pointer, search, and delete a value while keeping the chain joined.
- 4
Doubly and circular linked lists
Nodes with prev and next pointers, removing a node in O(1), and a circle of nodes for the Josephus problem.
Module practice
- Count the comparisonsEasy
- Count equal pairsMedium
- Halving stepsHard
- Insert into a sorted arrayEasy
- Delete at positionsMedium
- Rotate a matrixHard
- Build and measure a listEasy
- Reverse a linked listMedium
- Remove every copy of a valueMedium
- Merge two sorted listsHard
- Forwards and backwardsEasy
- The Josephus circleMedium
- A playlist cursorHard