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

Launch price

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year, or $19.50 for your first year with LAUNCH50, ends 1 Nov, 18:30 UTC.

See plansStart free instead

Module 09 · DSA · Four patterns the ladders lean on

Two heaps and a merge (running median, k-way merge, top-k)

Before you start. Trees (BST, balancing, heaps, tries) told you how a heap works: a pile where every parent is smaller than its children, so the smallest value always sits on top. Clinic #19: Kth Largest Element in an Array and Clinic #20: Top K Frequent Elements used one to keep the biggest few of a list. This lesson takes the same pile and shows the three jobs it gets hired for most often, one of which needs two piles at once.

Lesson 70 of 74 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, or $19.50 for your first year with LAUNCH50, ends 1 Nov, 18:30 UTC.

See plansAlready a member? Sign in

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

In this lesson

  • 1964: two pages in the June issue, and a pile that always knows its weakest member
  • Job one: top-k, a scoreboard with k seats and the weakest score on top
  • Job two: the running median, two scoreboards facing each other
  • Job three: k-way merge, k sorted heats and a board with k seats
  • When the pile is the wrong tool

Terms it explains: min-heap, Top-k, median, max-heap, Two heaps, k-way merge, heap.

Review DSA