Data structures
The way you organise information decides how easy (and fast) your program can be. Meet the toolbox every programmer uses.
Which structure fits?
Real situations, matched with the right tool.
Browser history โ StackLast page in, first page out when you press Back.
Printer queue โ QueueFirst document in is the first one printed.
Contacts โ MapLook up a phone number instantly by name.
Organisation chart โ TreeEach manager has a team below them.
Road network โ GraphCities are nodes; roads are edges between them.
Task priorities โ Priority queueThe most urgent task always comes out first.
๐ Stack in action
Undo, like in your favourite editor
A stack is a pile of plates: you add on top and take from the top. Thatโs exactly how โUndoโ remembers what you did.
undo-stack.pseudo
1BEGIN2 SET HISTORY = []3 ADD "type Hello" TO HISTORY4 ADD "make bold" TO HISTORY5 ADD "change colour" TO HISTORY6 SET LAST = POP(HISTORY)7 DISPLAY "Undo:", LAST8 DISPLAY "Still in history:", HISTORY9END
๐บ Data structure lessons (Phase 08)
01
Why Data Structures?
02
Stack
03
Queue
04
Linked List
05
Hash Table / Map
06
Tree
07
Binary Tree
08
Binary Search Tree
09
Heap
10
Priority Queue
11
Graph
12
Nodes and Edges
13
Directed / Undirected Graphs
14
Weighted Graphs
15
Choosing Data Structures