Binary Search Trees: Swift
Lesson 1 of 1
  1. 1
    A 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…
  2. 2
    When 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…
  3. 3
    With 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, …
  4. 4
    Our 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…
  5. 5
    Now 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…
  6. 6
    We’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 …
  7. 7
    With 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…
  8. 8
    Congratulations on building a binary search tree! When implementing a BST in your own code, here are a few things to remember: - In a BST, the left child is less than the parent and the right chi…

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo