What is a Binary Tree?

Jonathan Rasmusson
A free video tutorial from Jonathan Rasmusson
Ex-Spotify Engineer, The Agile Samurai
4.5 instructor rating • 5 courses • 43,158 students

Learn more from the full course

Data Structures and Algorithms Bootcamp

How to ace your Silicon Valley style coding interview

06:27:06 of on-demand video • Updated December 2020

  • How to answer commonly asked Silicon Valley style interview questions
  • Demonstrate knowledge and mastery of data structures and algorithms
  • How to pass Silicon Valley style technical interviews
  • Interview confidently
  • Land your dream job
English Did you ever stop and wonder how certain pieces of data get represented in a computer or how when you search for things just the results seem to come back super super fast. In this section we're going to take a look at a really cool data structure called the binary tree and see what makes all these things possible and more. And in this section you're going to learn what binary trees are, one type of binary tree, the binary search tree works, and why they're used in so many algorithms today. A binary tree is a treelike data structure where data is stored in the nodes much like the leaves on a tree. You've got your root node at the top you've got your left and right nodes underneath and basically just store the information in various places in the tree. And then look them up. Now sometimes when you're at a cocktail party and you hear people talking about binary trees you'll hear words like full, perfect, and balanced. A full binary tree is one where every node has zero or two children. In other words there's no single nodes. An example of a perfect binary tree would be a family tree. Where every child has a mother and a father and a balanced binary tree is one that has the minimum possible height binary trees that are really really deep that aren't balanced correctly can be really inefficient. So what we try to use organize are trees that they have the minimum possible height. Still some terms you might hear, two others he might hear also our breadth first and depth first. When you search a binary tree breadth first what you're really doing is going across the tree first because you think the data that you're looking for lives somewhere near the top. Shortest path algorithms those types of things use breadth first. Depth first is when you want to go deep here you think that piece of data or the solution you're looking for is deep deep down in the binary tree. So things like maze problems would be an example of a deep first binary tree search. Now don't worry about how to check her code these things up for now. These are just some terms that are really good to know. Just in case they come up interview you can honestly say I've heard of these terms. I understand what they are but maybe you don't you know code these things up every day and that's perfectly OK. But now that you understand some of the words and terms we use to describe binary trees let's dive in a little bit deeper and see how these things actually work.