Ch 10 · Mini-Projects & Practice · Data Structures & Algorithms

Topic 10 of 10 in Data Structures & Algorithms — Foundations — 3 lessons.

Project: Bracket Validator

Use a stack (last in, first out) to build a tiny tool that checks whether code brackets are balanced — the same check your editor runs as you type.

Project: Word Frequency Counter

Count how often each word appears in a sentence — a one-line job for a dict (and the seed of how search engines rank pages).

Project: Pair Finder (Two-Sum)

A shop has a list of prices and you have a gift card worth exactly 43. Which two items add up to 43? The slow way tries every possible pair, which means a loop inside a loop. The fast way walks the list once. For each price it works out the partner it would need (43 minus the price) and asks a set whether it has already seen that partner. Both functions also count how many checks they make. Here the matching pair, 3 and 40, sits at the very end of the list, which is the worst case: the slow version checks all 28 pairs, while the fast version needs only 8 checks. With a thousand prices the gap grows to about half a million checks against one thousand.

All topics in Data Structures & Algorithms Beginner

  1. Thinking Like a Computer Scientist
  2. Arrays & Lists — The Workhorse
  3. Stacks — Last In, First Out
  4. Queues — First In, First Out
  5. Linked Lists — Nodes on a Chain
  6. Searching — Finding the Needle
  7. Sorting — Putting Things in Order
  8. Recursion — Functions That Call Themselves
  9. Hash Tables — Instant Lookups
  10. Mini-Projects & Practice