Binary Search Trees
Learn how to build a binary search tree in Swift.
StartBinary Search Trees: Swift
Lesson 1 of 1
- 1A binary search tree (BST) is a specialized form of a standard binary tree. We have already built a binary tree inside of our heaps class so the structure will feel familiar as we implement our c…
- 2When we add elements to a binary search tree we have to ensure that we are following the rules of the data structure: - All values less than a parent’s value are stored on the left side of the tree…
- 3With our private add(:to:) function complete, it is time to implement our public-facing add(:) method. Users don’t need to be able to add a value to specific subtrees in our structure, actually, …
- 4Our implementation of a searching function will provide the user with a boolean value as to whether the value is in the tree or not. Since it provides the user with this type of answer, we will cal…
- 5Now that we have a insertion and searching in our binary search tree, the next functionality we will add is data removal. As you can imagine, removing data from a BST is not just as simple as delet…
- 6We’ve solved step 4 of our pseudocode algorithm, let’s review the code again to finish implementing our remove functions. 1. Check if the node passed into the function exists, if not, return nil …
- 7With the core functionality taken care of, we can focus on some of the aesthetics of our binary search tree. We are going to build in the feature that allows the tree to be printed in order, from l…
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory