Sample Video Frame

Created by Zed A. Shaw Updated 2024-11-15 13:50:32
 

Exercise 40: Binary Search Trees

The binary tree is the simplest tree-based data structure, and even though it's been replaced by hash maps in many languages, it's still useful for many applications. Variants on the binary tree exist for very useful things like database indexes, search algorithm structures, and even graphics.

I'm calling my binary tree a BSTree for binary search tree, and the best way to describe it is that it's another way to do a Hashmap style key/value store. The difference is that instead of hashing the key to find a location, the BSTree compares the key to nodes in a tree, and then walks through the tree to find the best place to store it, based on how it compares to other nodes.

Before I really explain how this works, let me show you the bstree.h header file so that you can see the data structures, and then I can use that to explain how it's built.

View Source file liblcthw/src/lcthw/bstree.h Only

Previous Lesson Next Lesson

Register for Learn C the Hard Way

Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.