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

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 inputO(log n)
โ Logarithmic: still fast, cuts work in half each timeO(n)
โ Linear: work grows directly with inputO(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:
Deleting a Leaf Node:
Just remove it (easy).Deleting a Node with One Child:
Replace the node with its child.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!
Subscribe to my newsletter
Read articles from kasumbi phil directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
