Data Structures & Algorithms · Complexity
Choosing a data structure
List, tuple, set, dict, deque: pick the right container and half the algorithm writes itself.
Step 1 of 4 · Overview15 min read ·
| Structure | Ordered | Mutable | Fast at | Use for |
|---|---|---|---|---|
| list | yes | yes | index, append | sequence of fills |
| tuple | yes | no | hashable record | (trade_id, field) |
| set | no | yes | membership, union/intersection | which ids exist |
| dict | insertion | yes | key → value lookup | trades by id |
| deque | yes | yes | append/pop both ends | rolling window of prices |
ours_ids = {t["id"] for t in ours}
theirs_ids = {t["id"] for t in theirs}
missing_at_cpty = ours_ids - theirs_ids
missing_in_ours = theirs_ids - ours_ids
both = ours_ids & theirs_idsKey idea
Set algebra does half the reconciler: difference = missing trades, intersection = trades to field-compare.Next: Practice