Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 10 · DSA · Built from the toolbox · with code: Python · about 18 min to read

Play it as a journeyTutor comes with a plan

Build an autocomplete

Trees
Trees · Open board

Is the board this build joins up. Its heap corner keeps the smallest number at the top and lists “top-K” among its uses. Its trie corner spells “cat” and “car” down one shared path and says a trie is “perfect for AUTOCOMPLETE”. This lesson makes those two corners work as one machine.

Before you start. Clinic #23: Implement Trie built a trie: every stored word is a path from one starting node, one letter per step, words that begin alike share their start, and a flag marks the node where a word ends. Trees (BST, balancing, heaps, tries) and Shortest Paths, Worked (Dijkstra, Bellman-Ford, A*) used a heap: a tree kept so the smallest item always sits at the top, which is how Dijkstra’s search always knew the nearest unfinished town.

Lesson 95 of 96 in DSA

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • 2004: Google Suggest, a search box that guesses while you type
  • The job by hand: eight words, a count each, and the best few
  • The shortlist that throws out its weakest: a min-heap
  • First try: scan the whole sorted list on every keystroke
  • Second try: walk the trie, then gather the subtree
  • The fix: every node keeps its own top 5, a cache
  • The eight-word log, by hand
  • All four engines agree
  • The timing table
  • What the cache costs in memory
  • Counts that change
  • In an interview

Terms it explains: top-k, min-heap, subtree, cache, Search Suggestions System, Top K Frequent Words, Implement Trie (Prefix Tree), B-tree, balanced, binary tree, BST, complete tree, heap, height h, priority queue, rotation, self-balancing BST (AVL / red-black), sift up/down, traversal, tree, trie.

Review DSA