๐Ÿง  What I Learned Today: Big-O Notation, Trees, and Validating a BST

kasumbi philkasumbi phil
4 min read

Today was a BIG day in my coding journey. I dove into some foundational computer science concepts, and while it was intense, I walked away feeling more confident and curious than ever.

Let me take you through everything I learned โ€” broken down in simple, beginner-friendly language, just the way I needed it when I started.


๐Ÿš€ Starting With Big-O Notation

I finally began understanding Big-O Notation โ€” one of those terms that gets thrown around a lot but rarely explained in a way that sticks.

Hereโ€™s what I learned:

๐Ÿ’ก What is Big-O?

Big-O is a way of describing how fast or slow an algorithm is, especially when the input gets really big. Itโ€™s like measuring a carโ€™s speed, but for code performance.

There are two main things we care about:

  • Time Complexity โ€“ how much time an algorithm takes as the input grows

  • Space Complexity โ€“ how much memory it needs

๐Ÿ“Š Common Big-O Categories:

  • O(1) โ€“ Constant time: super fast, doesnโ€™t grow with input

  • O(log n) โ€“ Logarithmic: still fast, cuts work in half each time

  • O(n) โ€“ Linear: work grows directly with input

  • O(n^2) โ€“ Quadratic: slower, usually means nested loops

And so on...

The key thing is: we use Big-O to describe the worst-case scenario of how our code performs, so we can make better choices.


๐ŸŒฒ Next: Tree Data Structures

After Big-O, I jumped into the world of trees. And let me tell you โ€” trees are weird at first, but once they click, theyโ€™re kind of beautiful.

๐ŸŒณ What is a Tree?

A tree is a way to organize data where each item (called a node) points to other nodes like branches.

Each tree has:

  • A root node (the top)

  • Child nodes (left and right)

  • Possibly more levels, depending on the structure

๐ŸŒด Types of Trees I Met Today:

  • Binary Tree โ€“ Each node has at most 2 children

  • Binary Search Tree (BST) โ€“ Left child < parent < right child

  • Others like AVL and Red-Black trees (more advanced, didnโ€™t dive into them yet)

๐Ÿ”„ Tree Traversals:

I also learned the three main ways to visit all nodes in a tree:

  • Inorder โ€“ left โ†’ root โ†’ right

  • Preorder โ€“ root โ†’ left โ†’ right

  • Postorder โ€“ left โ†’ right โ†’ root

These are ways to walk through a tree to either print its values, search, or manipulate it.


๐Ÿงฑ BST Methods โ€“ How We Work With Binary Search Trees

This part really brought it all together for me. A Binary Search Tree is a special kind of binary tree where every node follows the rule:
๐Ÿ‘‰ Left is smaller, right is bigger

โž• Insertion in a BST:

To insert a value:

  • Start at the root

  • If the new value is smaller, go left

  • If bigger, go right

  • Repeat this until you find an empty spot

This ensures the tree stays sorted, which is the whole point of a BST!

โŒ Deletion in a BST:

Deletion was a little tricky, but hereโ€™s the breakdown:

There are three cases to handle:

  1. Deleting a Leaf Node:
    Just remove it (easy).

  2. Deleting a Node with One Child:
    Replace the node with its child.

  3. Deleting a Node with Two Children:
    Find the inorder successor โ€” the smallest value in the right subtree โ€” and use that to replace the node being deleted.


โœ… Validating a BST (No Code Yet!)

This was the last thing I studied today โ€” and probably the trickiest at first.

Validating a BST means checking whether a given binary tree actually follows the BST rules.

  • It's not enough to just compare the immediate children.

  • You need to check the entire subtree to make sure every node on the left is smaller and every node on the right is bigger โ€” recursively.

This is where the idea of using minimum and maximum bounds comes in (more on that in the next blog post ๐Ÿ˜‰).


๐Ÿ’ฌ Final Thoughts

Today stretched my brain in a really good way.
I went from "Big-O what now?" to confidently explaining tree operations and even understanding how to validate a tree structure without needing the code just yet.

Sometimes, itโ€™s not about memorizing every little detail โ€” itโ€™s about getting the big picture to click.


๐Ÿ‘€ Whatโ€™s Next?

In my next blog post, Iโ€™ll walk you through:

  • How I finally understood the code behind validating a BST

  • What mistakes I kept making

  • And how I now see it like a game of setting boundaries for every node!

0
Subscribe to my newsletter

Read articles from kasumbi phil directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

kasumbi phil
kasumbi phil