8. Binary Trees

In This Chapter

Why Use Binary Trees?

Tree Terminology

An Analogy

How Do Binary Search Trees Work?

Finding a Node

Inserting a Node

Traversing the Tree

Finding Minimum and Maximum Key Values

Deleting a Node

The Efficiency of Binary Search Trees

Trees Represented as Arrays

Printing Trees

Duplicate Keys

The BinarySearchTreeTester.py Program

The Huffman Code

In this chapter we switch from algorithms, the focus of Chapter 7, “Advanced Sorting,” to data structures. Binary trees are one of the fundamental data storage structures used in programming. They provide advantages that the data structures you’ve seen so far cannot. In this chapter you learn why you would want to use trees, how they work, and how ...

Get Data Structures & Algorithms in Python now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.