All lessons in Software Engineering: Programs, Systems, and Maintainable Software

Trees, Heaps, and Ordered Work

Distinguish search trees from heaps and use each for the operations it supports.

40 minutes · Members lesson · preview

What you will learn

  • Explain which ordering property a search tree and a heap each maintain.
  • Trace heap insertion and removal while preserving its invariant.
  • Choose a structure for exact lookup, ordered traversal, or repeated minimum removal.

The library wants to process loans in earliest-due order. Keeping a fully sorted list is one option, but the workload repeatedly adds a loan and removes the earliest item. A heap fits that operation directly. It does not, however, provide efficient arbitrary lookup merely because it has a tree shape.

Tree-shaped structures serve different contracts. Learn the ordering invariant first; otherwise it is easy to borrow a performance claim from the wrong structure.

Choose another lesson