Introduction of Binary Tree - The Coding Shala

Last Updated: 19-Jan-2021
Home >> Data Structures >> Binary Tree

 In this post, we will learn the basic Introduction of Binary Tree Data Structure.

Binary Tree

A tree is an important data structure to simulate a hierarchical tree structure. In every tree, there will be a root node and a list of references to other nodes which are called child nodes. If a tree has N nodes then there are N-1 edges connecting them.

A binary tree is one of the typical tree structure. In a Binary tree, each node has at most two children which are referred to as the left and the right child.

How to Traverse a Binary Tree

There are many ways to traverse a binary tree.

We can traverse a binary tree using BFS and DFS.

Using BFS

  • level order traverse
Using DFS
  • Pre Order Traversal
  • In Order Traversal
  • Post-Order Traversal
We can also use the Recursive and Iterative method to traverse the tree. Recursion is one of the most important methods to traverse the Binary tree.

Pre-Order Traversal

In Pre Order traversal we visit the root first, then traverse the left subtree and finally traverse the right subtree.

Order: root-left-right

In-Order Traversal

In In-Order traversal, we visit the left subtree first then the root, and finally traverse the right subtree.

Order: left-root-right

Post-Order Traversal

In Post-Order Traversal we visit the left subtree first then the right subtree and finally visit the root node.

Order: left-right-root

Level Order Traversal

In Level Order Traversal we visit all the nodes at the same level first then move to the next level.

More Content will be added soon.

Other Posts You May Like
Please leave a comment below if you like this post or found some errors, it will help me to improve my content.


Popular Posts from this Blog

LeetCode - Crawler Log Folder Solution - The Coding Shala

Richest Customer Wealth LeetCode Solution - The Coding Shala

Shell Script to find sum, product and average of given numbers - The Coding Shala

First Unique Character in a String Java - The Coding Shala

Add two numbers in Scala - The Coding Shala