DEV Community

Cover image for Binary Tree
cody simon
cody simon

Posted on

Binary Tree

Given that its spooky season, I thought it would be a good idea to write a post about the scariest thing I could think of
--

                  **Binary Trees**
Enter fullscreen mode Exit fullscreen mode

As a beginner, I've googled my little heart out trying to find what the most complex white boarding challenges consist of for job interviews. Fingers crossed, if I ever get a call back, the only type of technical assessment will be in the form of a take home project. But assuming Google calls tomorrow, I want to be prepared to not only understand what a binary tree is, but also how data structures and algorithms work together as a whole. And you should too. Hence the blog post.

*What is a binary tree? *

'A binary tree is a hierarchical data structure used in computer science. It consists of nodes, where each node has at most two child nodes, referred to as the left child and the right child. The top node is called the root, and it branches downward into various levels, with each level containing nodes that are connected in a binary fashion. Binary trees are widely used for tasks like searching, sorting, and organizing data efficiently.'

Did your brain just go ERROR 404 on you after reading that? Mine did the first time I read a definition like that. I know what you're thinking. "I just want to change the background color on buttons and get paid $90,000 a year to do it. What does this have to do with anything?". Again, I feel you there. But here's the point, understanding How data structures and algorithms work will set you a part from the crowd.

Lets try an easier to understand definition.

A binary tree is like a family tree, but with a special rule: each person (or "node") can have at most two children, typically called left and right. It starts with one person at the top, called the "root," and branches down into more people as you go lower. This tree structure is often used in computers to organize and find data efficiently, like a phone book where you can quickly look up names because they're sorted in a particular order. Each person in the tree helps organize the information, making it easy to find what you're looking for.

Starting to make more sense? A binary tree is a data structure. How it ties in to BigO notation is probably for a different blog post, but I think I might make a series on this.

I hope this gave you at least a basic understanding of what a binary tree is. Its not as scary as they make it sound.

Oldest comments (0)