

{"id":98532,"date":"2021-07-23T09:00:21","date_gmt":"2021-07-23T03:30:21","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=98532"},"modified":"2021-07-22T10:47:05","modified_gmt":"2021-07-22T05:17:05","slug":"binary-tree","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/binary-tree\/","title":{"rendered":"Binary Tree Data Structure"},"content":{"rendered":"<p>A binary tree is one of the types of tree data structure. It is one of the widely used abstract data structures that simulates a hierarchical tree structure. A Binary tree has only 2 child nodes at maximum.<\/p>\n<p>In this article, we will learn about binary trees, different types of binary trees and it\u2019s implementations in different programming languages.<\/p>\n<h3>Binary tree<\/h3>\n<p>A binary tree is a type of tree data structure where a parent node can have a maximum of 2 child nodes. The binary name itself means 2. Each parent node can have 0, 1, or 2 child nodes only. Each node in a binary tree has three parts:<\/p>\n<ul>\n<li>Data<\/li>\n<li>Address of left child node<\/li>\n<li>Address of right child node<\/li>\n<\/ul>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image01.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-98564\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image01.jpg\" alt=\"Binary tree Data Structure\" width=\"480\" height=\"314\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image01.jpg 480w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image01-320x209.jpg 320w\" sizes=\"auto, (max-width: 480px) 100vw, 480px\" \/><\/a><\/p>\n<h3>Types of binary tree<\/h3>\n<h4>1. Full Binary Tree<\/h4>\n<p>Here, each node in a tree has either 0 or exactly 2 child nodes. A full Binary tree is also known as a proper binary tree.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image02.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-98565\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image02.jpg\" alt=\"Full Binary tree\" width=\"432\" height=\"480\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image02.jpg 432w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image02-320x356.jpg 320w\" sizes=\"auto, (max-width: 432px) 100vw, 432px\" \/><\/a><\/p>\n<h4>2. Perfect binary tree<\/h4>\n<p>Here, each parent node has exactly 2 child nodes and all child nodes are at the same level.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image03.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-98566\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image03.jpg\" alt=\"Perfect Binary tree\" width=\"480\" height=\"314\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image03.jpg 480w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image03-320x209.jpg 320w\" sizes=\"auto, (max-width: 480px) 100vw, 480px\" \/><\/a><\/p>\n<h4>3. Complete binary tree<\/h4>\n<p>A complete binary tree is a version of a full binary tree with 2 major differences;<\/p>\n<p>1. Each level must be filled<\/p>\n<p>2. All leaf elements must lean towards left<\/p>\n<p>3. t is not compulsory for a left child node to have a right sibling node. A complete Binary tree need not necessarily be a full binary tree<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image04.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-98567\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image04.jpg\" alt=\"Complete Binary tree\" width=\"408\" height=\"314\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image04.jpg 408w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image04-320x246.jpg 320w\" sizes=\"auto, (max-width: 408px) 100vw, 408px\" \/><\/a><\/p>\n<h4>4. Degenerate tree<\/h4>\n<p>Each node in a degenerate tree has only 0 or 1 child node. The child node can either be the left or right child node. A degenerate tree is also known as a Pathological tree.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image05.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-98568\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image05.jpg\" alt=\"Degenerate tree\" width=\"266\" height=\"447\" \/><\/a><\/p>\n<h4>5. Skewed Binary Tree<\/h4>\n<p>A skewed Binary tree is a version of a Degenerate Binary Tree where it is dominated by either left or right child nodes only. Hence there can be a left Skewed binary tree or a right-skewed binary tree.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image06.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-98569\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image06.jpg\" alt=\"Skewed Binary tree\" width=\"574\" height=\"323\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image06.jpg 574w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image06-520x293.jpg 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image06-320x180.jpg 320w\" sizes=\"auto, (max-width: 574px) 100vw, 574px\" \/><\/a><\/p>\n<h4>6. Balanced Binary Tree<\/h4>\n<p>In a Balanced binary tree, the difference between the height of the left and right subtree of each node is either 0 or 1.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image07.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-98570\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image07.jpg\" alt=\"Balance Binary tree\" width=\"597\" height=\"353\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image07.jpg 597w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image07-520x307.jpg 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image07-320x189.jpg 320w\" sizes=\"auto, (max-width: 597px) 100vw, 597px\" \/><\/a><\/p>\n<h3>Traversing through Binary Tree<\/h3>\n<p>Unlike linear data structures, nonlinear data structures like graphs and trees have multiple ways for traversing from the root node to the leaf node. There are three ways of traversing through a tree:<\/p>\n<ul>\n<li>Inorder traversal<\/li>\n<li>Preorder traversal<\/li>\n<li>Postorder traversal<\/li>\n<\/ul>\n<p>Let us consider a tree:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image08.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-98571\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image08.jpg\" alt=\"Traversal of Binary Tree\" width=\"490\" height=\"314\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image08.jpg 490w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-normal-image08-320x205.jpg 320w\" sizes=\"auto, (max-width: 490px) 100vw, 490px\" \/><\/a><\/p>\n<h4>1. Inorder traversal<\/h4>\n<h5>Procedure<\/h5>\n<ul>\n<li>Traverse the left subtree<\/li>\n<li>Visit the root<\/li>\n<li>Traverse the right subtree<\/li>\n<\/ul>\n<p>Inorder traversal returns nodes in non-decreasing order in case of a binary search tree.<\/p>\n<p>Inorder Traversal of the above tree is: 5 4 3 1 2 6<\/p>\n<h4>2. Preorder traversal<\/h4>\n<h5>Procedure<\/h5>\n<ul>\n<li>Visit the root<\/li>\n<li>Traverse the left subtree in preorder<\/li>\n<li>Traverse the right subtree in preorder<\/li>\n<\/ul>\n<p>Preorder traversal is helpful while creating a copy of the tree. It returns the prefix expression of an expression tree.<\/p>\n<p>Preorder Traversal or above tree is: 1 4 5 3 2 6<\/p>\n<h4>3. Postorder traversal<\/h4>\n<h5>Procedure<\/h5>\n<ul>\n<li>Traverse the left subtree in preorder<\/li>\n<li>Traverse the right subtree in preorder<\/li>\n<li>Visit the root<\/li>\n<\/ul>\n<p>Postorder traversal is used to delete the tree. It returns the postfix expression of the expression tree.<\/p>\n<p>Postorder Traversal or above tree is: 5 4 3 6 2 1<\/p>\n<h3>Traversal of Binary Tree in C<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\r\n#include &lt;stdlib.h&gt;\r\n\r\nstruct node \r\n{\r\n  int data;\r\n  struct node* leftChild;\r\n  struct node* rightChild;\r\n};\r\n\r\nstruct node* newNode(int data)\r\n{\r\n  struct node* node\r\n    = (struct node*)malloc(sizeof(struct node));\r\n  node-&gt;data = data;\r\n  node-&gt;leftChild = NULL;\r\n  node-&gt;rightChild = NULL;\r\n\r\n  return (node);\r\n}\r\n\r\nvoid PostorderTraversal(struct node* node)\r\n{\r\n  if (node == NULL)\r\n    return;\r\n\r\n  PostorderTraversal(node-&gt;leftChild);\r\n  PostorderTraversal(node-&gt;rightChild);\r\n  printf(\"%d \", node-&gt;data);\r\n}\r\n\r\nvoid InorderTraversal(struct node* node)\r\n{\r\n  if (node == NULL)\r\n    return;\r\n\r\n  InorderTraversal(node-&gt;leftChild);\r\n  printf(\"%d \", node-&gt;data);\r\n  InorderTraversal(node-&gt;rightChild);\r\n}\r\n\r\nvoid PreorderTraversal(struct node* node)\r\n{\r\n  if (node == NULL)\r\n    return;\r\n    \r\n  printf(\"%d \", node-&gt;data);\r\n  PreorderTraversal(node-&gt;leftChild);\r\n  PreorderTraversal(node-&gt;rightChild);\r\n}\r\n\r\nint main()\r\n{\r\n  struct node* root = newNode(1);\r\n  root-&gt;leftChild = newNode(4);\r\n  root-&gt;rightChild = newNode(2);\r\n  root-&gt;leftChild-&gt;leftChild = newNode(5);\r\n  root-&gt;leftChild-&gt;rightChild = newNode(3);\r\n  root-&gt;rightChild-&gt;rightChild = newNode(6);\r\n\r\n  printf(\"\\nPreorder traversal \\n\");\r\n  PreorderTraversal(root);\r\n\r\n  printf(\"\\nInorder traversal  \\n\");\r\n  InorderTraversal(root);\r\n\r\n  printf(\"\\nPostorder traversal  \\n\");\r\n  PostorderTraversal(root);\r\n\r\n  \r\n  return 0;\r\n}\r\n<\/pre>\n<h3>Binary Tree Traversal in C++<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;iostream&gt;\r\nusing namespace std;\r\n\r\nstruct node \r\n{\r\n  int data;\r\n  struct node* leftChild;\r\n  struct node* rightChild;\r\n};\r\n\r\nstruct node* newNode(int data)\r\n{\r\n  struct node* node\r\n    = (struct node*)malloc(sizeof(struct node));\r\n  node-&gt;data = data;\r\n  node-&gt;leftChild = NULL;\r\n  node-&gt;rightChild = NULL;\r\n\r\n  return (node);\r\n}\r\n\r\nvoid PostorderTraversal(struct node* node)\r\n{\r\n  if (node == NULL)\r\n    return;\r\n\r\n  PostorderTraversal(node-&gt;leftChild);\r\n  PostorderTraversal(node-&gt;rightChild);\r\n  cout &lt;&lt; \" \" &lt;&lt; node-&gt;data;\r\n}\r\n\r\nvoid InorderTraversal(struct node* node)\r\n{\r\n  if (node == NULL)\r\n    return;\r\n\r\n  InorderTraversal(node-&gt;leftChild);\r\n  cout &lt;&lt; \" \" &lt;&lt; node-&gt;data;\r\n  InorderTraversal(node-&gt;rightChild);\r\n}\r\n\r\nvoid PreorderTraversal(struct node* node)\r\n{\r\n  if (node == NULL)\r\n    return;\r\n    \r\n  cout &lt;&lt; \" \" &lt;&lt; node-&gt;data;\r\n  PreorderTraversal(node-&gt;leftChild);\r\n  PreorderTraversal(node-&gt;rightChild);\r\n}\r\n\r\nint main()\r\n{\r\n  struct node* root = newNode(1);\r\n  root-&gt;leftChild = newNode(4);\r\n  root-&gt;rightChild = newNode(2);\r\n  root-&gt;leftChild-&gt;leftChild = newNode(5);\r\n  root-&gt;leftChild-&gt;rightChild = newNode(3);\r\n  root-&gt;rightChild-&gt;rightChild = newNode(6);\r\n\r\n  cout &lt;&lt; \"\\nPreorder traversal \\n\";\r\n  PreorderTraversal(root);\r\n\r\n  cout &lt;&lt; \"\\nInorder traversal  \\n\";\r\n  InorderTraversal(root);\r\n\r\n  cout &lt;&lt;\"\\nPostorder traversal  \\n\";\r\n  PostorderTraversal(root);\r\n\r\n  \r\n  return 0;\r\n}\r\n<\/pre>\n<h3>Binary Tree Traversal in JAVA<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class Node \r\n{\r\n  int key;\r\n  Node leftChild, rightChild;\r\n\r\n  public Node(int item)\r\n  {\r\n    key = item;\r\n    leftChild = rightChild = null;\r\n  }\r\n}\r\n\r\npublic class BinaryTree \r\n{\r\n  Node root;\r\n\r\n  BinaryTree() \r\n  { \r\n      root = null; \r\n  }\r\n\r\n  void printPostorder(Node node)\r\n  {\r\n    if (node == null)\r\n      return;\r\n\r\n    printPostorder(node.leftChild);\r\n    printPostorder(node.rightChild);\r\n    System.out.print(node.key + \" \");\r\n  }\r\n\r\n  void printInorder(Node node)\r\n  {\r\n    if (node == null)\r\n      return;\r\n\r\n    printInorder(node.leftChild);\r\n    System.out.print(node.key + \" \");\r\n    printInorder(node.rightChild);\r\n  }\r\n  \r\n  void printPreorder(Node node)\r\n  {\r\n    if (node == null)\r\n      return;\r\n      \r\n    System.out.print(node.key + \" \");\r\n    printPreorder(node.leftChild);\r\n    printPreorder(node.rightChild);\r\n  }\r\n\r\n  void printPostorder() \r\n  { \r\n      printPostorder(root); \r\n  }\r\n  void printInorder() \r\n  {\r\n      printInorder(root); \r\n      \r\n  }\r\n  void printPreorder() \r\n  {\r\n      printPreorder(root);\r\n  }\r\n\r\n  public static void main(String[] args)\r\n  {\r\n    BinaryTree tree = new BinaryTree();\r\n    tree.root = new Node(1);\r\n    tree.root.leftChild = new Node(4);\r\n    tree.root.rightChild = new Node(2);\r\n    tree.root.leftChild.leftChild = new Node(5);\r\n    tree.root.leftChild.rightChild = new Node(3);\r\n    tree.root.rightChild.rightChild = new Node(6);\r\n\r\n    System.out.println(\"Preorder traversal of binary tree is \");\r\n    tree.printPreorder();\r\n\r\n    System.out.println(\"\\nInorder traversal of binary tree is \");\r\n    tree.printInorder();\r\n\r\n    System.out.println(\"\\nPostorder traversal of binary tree is \");\r\n    tree.printPostorder();\r\n  }\r\n}\r\n<\/pre>\n<h3>Traversal of Binary Tree in Python<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class Node:\r\n    def __init__(self, key):\r\n        self.leftChild = None\r\n        self.rightChild = None\r\n        self.val = key\r\n\r\n    def PreorderTraversal(self):\r\n        print(self.val, end=' ')\r\n        if self.leftChild:\r\n            self.leftChild.PreorderTraversal()\r\n        if self.rightChild:\r\n            self.rightChild.PreorderTraversal()\r\n\r\n    def InorderTraversal(self):\r\n        if self.leftChild:\r\n            self.leftChild.InorderTraversal()\r\n        print(self.val, end=' ')\r\n        if self.rightChild:\r\n            self.rightChild.InorderTraversal()\r\n\r\n    def PostorderTraversal(self):\r\n        if self.leftChild:\r\n            self.leftChild.PostorderTraversal()\r\n        if self.rightChild:\r\n            self.rightChild.PostorderTraversal()\r\n        print(self.val, end=' ')\r\n\r\n\r\nroot = Node(1)\r\n\r\nroot.leftChild = Node(4)\r\nroot.rightChild = Node(2)\r\n\r\nroot.leftChild.leftChild = Node(5)\r\nroot.leftChild.rightChild = Node(3)\r\n\r\nroot.rightChild.rightChild = Node(6)\r\n\r\nprint(\"Preorder Traversal: \", end=\"\")\r\nroot.PreorderTraversal()\r\nprint(\"\\nInorder Traversal: \", end=\"\")\r\nroot.InorderTraversal()\r\nprint(\"\\nPostorder Traversal: \", end=\"\")\r\nroot.PostorderTraversal()\r\n<\/pre>\n<h3>Applications of Binary tree<\/h3>\n<p>1. Implementing heap data structures<br \/>\n2. creating syntax tree by a compiler for syntax checking<br \/>\n3. A binary tree provides easy access to data<br \/>\n4. A binary tree is used in routers and routing algorithms.<\/p>\n<h3>Summary<\/h3>\n<p>This was all about Binary Tree in Data Structure. Hope it was great learning for you!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A binary tree is one of the types of tree data structure. It is one of the widely used abstract data structures that simulates a hierarchical tree structure. A Binary tree has only 2&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":98562,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24020],"tags":[24816,1993,24813,24815,24814],"class_list":["post-98532","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-structure-tutorials","tag-applications-of-binary-tree","tag-binary-tree","tag-binary-tree-data-structure","tag-traversal-of-binary-tree-in-c","tag-traversing-through-binary-tree"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Binary Tree Data Structure - DataFlair<\/title>\n<meta name=\"description\" content=\"Binary tree is one of the types of tree data structure. It is one of the widely used abstract data structures. Learn more about it.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/binary-tree\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Binary Tree Data Structure - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Binary tree is one of the types of tree data structure. It is one of the widely used abstract data structures. Learn more about it.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/binary-tree\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-23T03:30:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-in-Ds.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Binary Tree Data Structure - DataFlair","description":"Binary tree is one of the types of tree data structure. It is one of the widely used abstract data structures. Learn more about it.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/binary-tree\/","og_locale":"en_US","og_type":"article","og_title":"Binary Tree Data Structure - DataFlair","og_description":"Binary tree is one of the types of tree data structure. It is one of the widely used abstract data structures. Learn more about it.","og_url":"https:\/\/data-flair.training\/blogs\/binary-tree\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2021-07-23T03:30:21+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-in-Ds.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/binary-tree\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/binary-tree\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/b49855299264df5e27e3ec6c2cd9fde9"},"headline":"Binary Tree Data Structure","datePublished":"2021-07-23T03:30:21+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/binary-tree\/"},"wordCount":571,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/binary-tree\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-in-Ds.jpg","keywords":["Applications of Binary tree","Binary Tree","Binary Tree Data Structure","Traversal of Binary Tree in C","Traversing through Binary Tree"],"articleSection":["Data Structure Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/binary-tree\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/binary-tree\/","url":"https:\/\/data-flair.training\/blogs\/binary-tree\/","name":"Binary Tree Data Structure - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/binary-tree\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/binary-tree\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-in-Ds.jpg","datePublished":"2021-07-23T03:30:21+00:00","description":"Binary tree is one of the types of tree data structure. It is one of the widely used abstract data structures. Learn more about it.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/binary-tree\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/binary-tree\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/binary-tree\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-in-Ds.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/07\/Binary-tree-in-Ds.jpg","width":1200,"height":628,"caption":"Binary tree in Data Structure"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/binary-tree\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Data Structure Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/data-structure-tutorials\/"},{"@type":"ListItem","position":3,"name":"Binary Tree Data Structure"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/b49855299264df5e27e3ec6c2cd9fde9","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/ef46b745ddad2fad690af626c6ef29b91809ad0a9f5ef398d07817d8cad042f5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/ef46b745ddad2fad690af626c6ef29b91809ad0a9f5ef398d07817d8cad042f5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ef46b745ddad2fad690af626c6ef29b91809ad0a9f5ef398d07817d8cad042f5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team is a group of passionate educators and industry experts dedicated to providing high-quality online learning resources on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. With years of experience in the field, the team aims to simplify complex topics and help learners advance their careers. At DataFlair, we believe in empowering students and professionals with the knowledge and skills needed to thrive in today\u2019s fast-paced tech industry. Follow us for Free courses, expert insights, tutorials, and practical tips to boost your learning journey.","url":"https:\/\/data-flair.training\/blogs\/author\/datafbdad\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/98532","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=98532"}],"version-history":[{"count":3,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/98532\/revisions"}],"predecessor-version":[{"id":98572,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/98532\/revisions\/98572"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/98562"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=98532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=98532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=98532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}