Objective: In this lesson, we'll cover this concept, and focus on these outcomes:
- You'll learn what is a
tree
in general in the context of computer science. - You'll learn what
binary trees
andbinary search trees
are. - We'll show you how to use them in programming interviews.
- We'll dive into their traversal methods, and explain why they're useful.
- You'll see how to utilize this concept in interviews.
Trees are a very popular ADT (Abstract Data Type)
used in computer science. They are organized in a hierarchy of nodes. Anything stored in a tree is represented with a node that keeps track of its own data as well as references to the location of its children. Below are the properties of a tree
:
- All the nodes of a tree must be some-how connected via a path of parent-child relationship.
- There can be one and only one path between two nodes in a tree. In other words, there cannot be any cycles in a tree.

A binary tree
is a data structure
containing a collection of elements often referred to as nodes. It can store any data item, be it names, places, numbers, etc. of any type. It enables quick search, addition, and removal of items
It also contains a root node with a left subtree and a right subtree. A subtree is itself a binary tree
and the left and right subtrees are disjoint.
Let's dive into them in this guide.