liveBook · Manning

Chapter 7: Trees

What you will learn in chapter 7 of Grokking Algorithms, Second Edition

The introduction places trees within graphs and shows why specialized trees matter for compression and database storage.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction places trees within graphs and shows why specialized trees matter for compression and database storage.

Key terms: trees, graphs, specialized types of trees, Huffman coding, binary trees, balanced tree, B-tree

7.1 Your first tree

Introduces rooted trees as graphs and defines the node relationships used throughout the chapter.

Key terms: tree, graph, nodes, edges, rooted trees, parent, child, root, leaf nodes

7.2 File Directories

The section uses breadth-first search to list files in a directory tree and explains why a tree needs no visited-folder tracking.

Key terms: breadth-first search, traversal algorithm, queue, node, trees, cycles, parent, symbolic links

7.3 A space odyssey: Depth-first search

The section contrasts depth-first and breadth-first traversal of a file directory, then explains why only breadth-first search finds the closest match in the examples.

Key terms: breadth-first search, depth-first search, queue, recursively, shortest path, first-degree friends

7.4 A better definition of trees

Defines a tree as a connected graph without cycles and clarifies that the chapter considers rooted trees.

Key terms: tree, connected, acyclic graph, rooted trees, root, cycles

7.5 Binary trees

Defines binary trees by their limit of two children per node and introduces left and right children and subtrees.

Key terms: binary tree, node, left child, right child, left subtree, right subtree

7.6 Huffman coding

The section uses Huffman coding to show how a binary tree gives frequently used characters shorter codes while still allowing the encoded text to be decoded unambiguously.

Key terms: bit, byte, ISO-8859-1, ASCII, Unicode, UTF-8, variable-length character encoding, Huffman coding, compression, shorter codes

7.7 Recap

Recaps how trees and binary trees relate to graphs, what depth-first search cannot do, and how Unicode and UTF-8 relate to character encoding.

Key terms: tree, graph, cycles, binary tree, children, depth-first search, graph traversal algorithm, shortest paths, character encodings, Unicode

Where this is used later

Concepts explained in this chapter

← Chapter 6: Breadth-first search Chapter 8: Balanced trees →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.