7 Trees

In this chapter

  • You learn what a tree is and the difference between trees and graphs.
  • You get comfortable with running an algorithm over a tree.
  • You learn depth-first search and see the difference between depth-first search and breadth-first search.
  • You learn Huffman coding, a compression algorithm that makes use of trees.

What do compression algorithms and database storage have in common? There is often a tree underneath doing all the hard work. Trees are a subset of graphs. They are worth covering separately as there are many specialized types of trees. For example, Huffman coding, a compression algorithm you will learn in this chapter, uses binary trees.

Most databases use a balanced tree like a B-tree, which you will learn about ...

Get Grokking Algorithms, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.