Binary Trees and Tries
Overview
This lesson covers three similar, tree-based data structures:
- Binary trees.
- Tries.
- A self-balancing binary tree (aka, an AVL tree).
There are four components to this lesson. We recommend tackling them in the order below:
- myGA Module 1: Binary Trees and Tries
- If the above link does not take you to the correct module, you can find the lesson in your myGA dashboard.
- In-Class Exercise: Implementing a Binary Tree
- myGA Module 2: Balancing a Binary Tree
- If the above link does not take you to the correct module, you can find the lesson in your myGA dashboard.
- In-Class Exercise: Implementing an AVL Tree
The myGA modules contain a link to an exercise in CodePen. The code in CodePen is the exact same as the code in the in-class exercises. Try out the exercise in CodePen and see how far you can get with it. Stop when you get stuck and we'll review the solution in class.
Learning Objectives
By the end of this lesson, you'll be able to:
- Describe how a binary tree is structured and what makes it powerful.
- Describe how a trie is structured.
- Identify scenarios in which trees are used in programming.
- Balance a binary tree.
Prerequisites
- Big O notation
- Recursion
Duration
3 hours total:
- 1 hour myGA
- 2 hours in class
Additional Resources
- Since we don't cover how to build a trie, read about how it's implemented in code here.
- Check out these beautiful visualizations: a binary tree, a trie, and an AVL tree.
- How to distinguish between several types of tree data structures.
- Common interview questions about binary trees.
- Tree balancing interview prep: here and here.
- Whiteboarding an AVL tree.