{"id":11677,"date":"2023-01-13T04:32:00","date_gmt":"2023-01-13T04:32:00","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=11677"},"modified":"2023-01-13T04:32:00","modified_gmt":"2023-01-13T04:32:00","slug":"what-is-binary-tree-in-data-structure","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/","title":{"rendered":"What is Binary Tree in Data Structure?"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673530844021-What%20is%20Binary%20Tree%20in%20Data%20Structure.jpg\" alt=\"\" \/><\/p>\n<p>In this article, we will discuss binary tree in data structure. This is one of the most important topics of data structure.<\/p>\n<h2>Binary Tree in Data Structure<\/h2>\n<p>A binary tree is a tree data structure in which each parent node can have at most two children. Each node of a binary tree consists of three items:<\/p>\n<ul>\n<li>data element<\/li>\n<li>address of left child<\/li>\n<li>address of right child<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673530844120-What%20is%20Binary%20Tree%20in%20Data%20Structure1.png\" alt=\"\" \/><\/p>\n<p><strong>Structure of Node<\/strong><\/p>\n<pre><code>structure node\n{\nint data;\nstructure node *left;\nstructure node *right;\n};<\/code><\/pre>\n<h2>Types of Binary Tree<\/h2>\n<h3>1. Full Binary Tree<\/h3>\n<p>A full Binary tree is a special type of binary tree in which every parent node\/internal node has either two or no children.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673530844120-What%20is%20Binary%20Tree%20in%20Data%20Structure2.png\" alt=\"\" \/><\/p>\n<h3>2. Perfect Binary Tree<\/h3>\n<p>A perfect binary tree is a type of binary tree in which every internal node has exactly two child nodes and all the leaf nodes are at the same level.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673530844129-What%20is%20Binary%20Tree%20in%20Data%20Structure3.png\" alt=\"\" \/><\/p>\n<h3>3. Complete Binary Tree<\/h3>\n<p>A complete binary tree is just like a full binary tree, but with two major differences<\/p>\n<ol>\n<li>Every level must be completely filled<\/li>\n<li>All the leaf elements must lean towards the left.<\/li>\n<li>The last leaf element might not have a right sibling i.e. a complete binary tree doesn&#8217;t have to be a full binary tree.<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673530844130-What%20is%20Binary%20Tree%20in%20Data%20Structure4.png\" alt=\"\" \/><\/p>\n<h3>5. Skewed Binary Tree<\/h3>\n<p>A skewed binary tree is a pathological\/degenerate tree in which the tree is either dominated by the left nodes or the right nodes. Thus, there are two types of skewed binary tree: <strong>left-skewed binary tree and right-skewed binary tree.<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673530844130-What%20is%20Binary%20Tree%20in%20Data%20Structure5.png\" alt=\"\" \/><\/p>\n<h3>6. Balanced Binary Tree<\/h3>\n<p>It is a type of binary tree in which the difference between the height of the left and the right subtree for each node is either 0 or 1.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673530844130-What%20is%20Binary%20Tree%20in%20Data%20Structure6.png\" alt=\"\" \/><\/p>\n<h2>Binary search tree in data structure<\/h2>\n<p>A node in a binary tree is represented by a structure containing data and two pointers to other structures of the same type. It is a type of binary tree because each tree node has at most two children. It is called a search tree because it can be used to search for the existence of a number in <strong>O(log(n))<\/strong> time.<\/p>\n<p>The properties that separate binary search trees from regular binary trees are<\/p>\n<ol>\n<li>All nodes in the left subtree are less than the root node<\/li>\n<li>All nodes in the right subtree are greater than the root node<\/li>\n<li>Both subtrees of each node are also BST.<\/li>\n<\/ol>\n<h3>Algorithm of Search Operation<\/h3>\n<p>The algorithm relies on the property of BST where all left subtrees have values \u200b\u200bbelow the root and all right subtrees have values \u200b\u200babove the root.<br \/>\nIf the value is less than the root, we can say for sure that the value is not in the right subtree; we need to only search in the left subtree and if the value is above the root, we can say for sure that the value is not in the left subtree; we need to only search in the right subtree.<\/p>\n<h3>Binary Search Tree Complexities<\/h3>\n<p><strong>Time Complexity<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>Operation<\/th>\n<th>Best Case Complexity<\/th>\n<th>Average Case Complexity<\/th>\n<th>Worst Case Complexity<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Search<\/td>\n<td>O(log n)<\/td>\n<td>O(log n)<\/td>\n<td>O(n)<\/td>\n<\/tr>\n<tr>\n<td>Insertion<\/td>\n<td>O(log n)<\/td>\n<td>O(log n)<\/td>\n<td>O(n)<\/td>\n<\/tr>\n<tr>\n<td>Deletion<\/td>\n<td>O(log n)<\/td>\n<td>O(log n)<\/td>\n<td>O(n)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Here, n is the number of nodes in the tree.<\/strong><\/p>\n<p><strong>Space Complexity:<\/strong> The space complexity for all the operations is O(n).<\/p>\n<h2>Binary tree traversal in data structure<\/h2>\n<h3>What is the Traversal of a Binary Tree?<\/h3>\n<p>A binary tree is a data structure in which data is stored in a hierarchical form. Traversal of the binary tree means visiting every node of the tree. The process of accessing the nodes of a tree in some order is called a traversal of a binary tree. Any process for visiting all of the nodes is called a traversal.<\/p>\n<h3>What is Traversal Order?<\/h3>\n<p>Unlike linear data structures(Array, Queues, Linked List, Queues, etc.) that have only one way to traverse them but the tree data structure can be traversed in multiple ways.<br \/>\n<strong>The tree can be traversed in three ways:<\/strong><\/p>\n<p><strong>1. In-order Traversal<\/strong><br \/>\nIn inorder traversal of the binary tree, these 3 steps are recursively performed.<\/p>\n<p><strong>Step 1:<\/strong> Firstly left subtree is visited<br \/>\n<strong>Step 2:<\/strong> Then the root is visited<br \/>\n<strong>Step 3:<\/strong> Then the right subtree is visited.<\/p>\n<p><strong>An in-order traversal of the Binary Search Tree gives us the ascending order of values stored in the tree.<\/strong><\/p>\n<p><strong>2. Pre-order Traversal<\/strong><br \/>\nIn pre-order traversal of a binary tree, these 3 steps are recursively performed.<\/p>\n<p><strong>Step 1:<\/strong> Firstly root is visited<br \/>\n<strong>Step 2:<\/strong> Then the left subtree is visited<br \/>\n<strong>Step 3:<\/strong> Then finally the right subtree is visited.<\/p>\n<p><strong>3. Post-order Traversal<\/strong><br \/>\nIn post-order traversal of the binary tree root node is visited at the last. In this traversal, these 3 steps are recursively performed.<\/p>\n<p><strong>Step 1:<\/strong> Firstly left subtree is visited<br \/>\n<strong>Step 2:<\/strong> Then the right subtree is visited.<br \/>\n<strong>Step 3:<\/strong> And at last, the root is visited.<\/p>\n<h3>What are Tree Traversal Methods?<\/h3>\n<p><strong>Traversal Implementation in C++<\/strong><\/p>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_11625 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_11625 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_11625 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_11625 .wpsm_nav-tabs > li.active > a, #tab_container_11625 .wpsm_nav-tabs > li.active > a:hover, #tab_container_11625 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_11625 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_11625 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_11625 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_11625 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_11625 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_11625 .wpsm_nav-tabs > li > a:hover , #tab_container_11625 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_11625 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_11625 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_11625 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_11625 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_11625 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_11625 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_11625 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_11625 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_11625 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_11625 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_11625 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_11625\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_11625\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_11625_1\" aria-controls=\"tabs_desc_11625_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C++<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_11625\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_11625_1\">\r\n\t\t\t\t\t\t\t\t<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\">\/\/ C++ program to display in-order, post-order, pre-order traversal of tree\r\n#include &lt;iostream&gt;\r\nusing namespace std;\r\n\r\n\/* A binary tree node has data stored as value, pointer to left child\r\nand right child *\/\r\nstruct Node {\r\n  int value;\r\n  struct Node *left, *right;\r\n};\r\n\r\n\/\/function for creating new tree node\r\nNode* createNode(int value){\r\n  Node* t = new Node;\r\n  t-&gt;value = value;\r\n  t-&gt;left = t-&gt;right = NULL;\r\n  return t;\r\n}\r\n\r\n\/* printing postorder traversal of binary tree *\/\r\nvoid postorder(struct Node* root){\r\n  if (root == NULL)\r\n    return;\r\n\r\n  \/\/ first traverse left subtree\r\n  postorder(root-&gt;left);\r\n\r\n  \/\/ then traverse right subtree\r\n  postorder(root-&gt;right);\r\n\r\n  \/\/ now visit root node\r\n  cout &lt;&lt; root-&gt;value &lt;&lt; \" \";\r\n}\r\n\r\n\/* inorder traversal of the binary tree*\/\r\nvoid inorder(struct Node* root){\r\n  if (root == NULL)\r\n    return;\r\n\r\n  \/* first visit left child *\/\r\n  inorder(root-&gt;left);\r\n\r\n  \/* print root data *\/\r\n  cout &lt;&lt; root-&gt;value &lt;&lt; \" \";\r\n\r\n  \/* at last recur over right subtree *\/\r\n  inorder(root-&gt;right);\r\n}\r\n\r\n\/* Preorder traversal of the binary tree*\/\r\nvoid preorder(struct Node * root){\r\n  if (root == NULL)\r\n    return;\r\n\r\n  \/* display node value *\/\r\n  cout &lt;&lt; root-&gt;value &lt;&lt; \" \";\r\n\r\n  \/* then traverse left subtree *\/\r\n  preorder(root-&gt;left);\r\n\r\n  \/* now traverse right subtree *\/\r\n  preorder(root-&gt;right);\r\n}\r\nint main(){\r\n  struct Node* n = createNode(1);\r\n  n-&gt;left = createNode(2);\r\n  n-&gt;right = createNode(3);\r\n  n-&gt;left-&gt;left = createNode(4);\r\n  n-&gt;left-&gt;right = createNode(5);\r\n\r\n  cout &lt;&lt; \"&#92;nPreorder traversal of  tree: &#92;n\";\r\n  preorder(n);\r\n\r\n  cout &lt;&lt; \"&#92;nInorder traversal of tree: &#92;n\";\r\n  inorder(n);\r\n\r\n  cout &lt;&lt; \"&#92;nPostorder traversal of tree: &#92;n\";\r\n  postorder(n);\r\n\r\n  return 0;\r\n}\r\n<\/pre>\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_11625 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_11625 a\"),jQuery(\"#tab-content_11625\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<p><strong>Output<\/strong><\/p>\n<pre><code>Preorder traversal of binary tree:\n1 2 4 5 3 \nInorder traversal of binary tree:\n4 2 5 1 3 \nPostorder traversal of binary tree:\n4 5 2 3 1<\/code><\/pre>\n<h2>Complete Binary Tree in Data Structure<\/h2>\n<p>A complete binary tree is just like a full binary tree, but with two major differences<\/p>\n<ol>\n<li>Every level must be completely filled<\/li>\n<li>\n<p>All the leaf elements must lean towards the left, In other words, every node is filled in the direction of left to right.<\/p>\n<pre><code>                    5                                          7\n                   \/ \\                                        \/  \\\n                4     2                                    8     1\n               \/\\                                          \/\\    \/\n            11  9                                      6  4  5\n\n         NOT C.B.T                               C.B.T<\/code><\/pre>\n<\/li>\n<\/ol>\n<p><strong>C.B.T stands for Complete Binary Tree<\/strong><\/p>\n<h2>Threaded binary tree in data structure<\/h2>\n<p>Inorder traversal of the binary tree can either be done using recursion or with the use of an auxiliary stack. The idea of threaded binary trees is to make inorder traversal faster and do it without stack and without recursion. A binary tree is made threaded by making all right child pointers that would normally be NULL point to the inorder successor of the node (if it exists).<br \/>\nThere are two types of threaded binary trees. <\/p>\n<p><strong>Single Threaded:<\/strong> Where a NULL right pointers is made to point to the inorder successor (if successor exists)<\/p>\n<p><strong>Double Threaded:<\/strong> Where both left and right NULL pointers are made to point to inorder predecessor and inorder successor respectively. The predecessor threads are useful for reverse inorder traversal and postorder traversal.<\/p>\n<p>The threads are also useful for fast accessing ancestors of a node.<\/p>\n<p><strong>Conclusion<\/strong><br \/>\nIn this article, we have discussed what is binary search tree in data structure,  binary tree traversal and its types, and complete binary tree in data structure.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will discuss binary tree in data structure. This is one of the most important topics of data structure. Binary Tree in Data Structure A binary tree is a tree data structure in which each parent node can have at most two children. Each node of a binary tree consists of three [&hellip;]<\/p>\n","protected":false},"author":52,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[153],"tags":[],"class_list":["post-11677","post","type-post","status-publish","format-standard","hentry","category-tree"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What is Binary Tree in Data Structure?<\/title>\n<meta name=\"description\" content=\"Here we will learn about what a Binary Tree is, its types and its traversal methods.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is Binary Tree in Data Structure?\" \/>\n<meta property=\"og:description\" content=\"Here we will learn about what a Binary Tree is, its types and its traversal methods.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/\" \/>\n<meta property=\"og:site_name\" content=\"PrepBytes Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prepbytes0211\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-01-13T04:32:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673530844021-What%20is%20Binary%20Tree%20in%20Data%20Structure.jpg\" \/>\n<meta name=\"author\" content=\"Prepbytes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prepbytes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"What is Binary Tree in Data Structure?\",\"datePublished\":\"2023-01-13T04:32:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/\"},\"wordCount\":1032,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673530844021-What%20is%20Binary%20Tree%20in%20Data%20Structure.jpg\",\"articleSection\":[\"Trees\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/\",\"name\":\"What is Binary Tree in Data Structure?\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673530844021-What%20is%20Binary%20Tree%20in%20Data%20Structure.jpg\",\"datePublished\":\"2023-01-13T04:32:00+00:00\",\"description\":\"Here we will learn about what a Binary Tree is, its types and its traversal methods.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673530844021-What%20is%20Binary%20Tree%20in%20Data%20Structure.jpg\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673530844021-What%20is%20Binary%20Tree%20in%20Data%20Structure.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/43.205.93.38\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Trees\",\"item\":\"https:\/\/prepbytes.com\/blog\/category\/tree\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"What is Binary Tree in Data Structure?\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/43.205.93.38\/#website\",\"url\":\"http:\/\/43.205.93.38\/\",\"name\":\"PrepBytes Blog\",\"description\":\"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING\",\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/43.205.93.38\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/43.205.93.38\/#organization\",\"name\":\"Prepbytes\",\"url\":\"http:\/\/43.205.93.38\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"contentUrl\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"width\":160,\"height\":160,\"caption\":\"Prepbytes\"},\"image\":{\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/prepbytes0211\/\",\"https:\/\/www.instagram.com\/prepbytes\/\",\"https:\/\/www.linkedin.com\/company\/prepbytes\/\",\"https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\",\"name\":\"Prepbytes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"caption\":\"Prepbytes\"},\"url\":\"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is Binary Tree in Data Structure?","description":"Here we will learn about what a Binary Tree is, its types and its traversal methods.","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:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/","og_locale":"en_US","og_type":"article","og_title":"What is Binary Tree in Data Structure?","og_description":"Here we will learn about what a Binary Tree is, its types and its traversal methods.","og_url":"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2023-01-13T04:32:00+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673530844021-What%20is%20Binary%20Tree%20in%20Data%20Structure.jpg","type":"","width":"","height":""}],"author":"Prepbytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Prepbytes","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"What is Binary Tree in Data Structure?","datePublished":"2023-01-13T04:32:00+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/"},"wordCount":1032,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673530844021-What%20is%20Binary%20Tree%20in%20Data%20Structure.jpg","articleSection":["Trees"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/","url":"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/","name":"What is Binary Tree in Data Structure?","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673530844021-What%20is%20Binary%20Tree%20in%20Data%20Structure.jpg","datePublished":"2023-01-13T04:32:00+00:00","description":"Here we will learn about what a Binary Tree is, its types and its traversal methods.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673530844021-What%20is%20Binary%20Tree%20in%20Data%20Structure.jpg","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1673530844021-What%20is%20Binary%20Tree%20in%20Data%20Structure.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/what-is-binary-tree-in-data-structure\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/43.205.93.38\/"},{"@type":"ListItem","position":2,"name":"Trees","item":"https:\/\/prepbytes.com\/blog\/category\/tree\/"},{"@type":"ListItem","position":3,"name":"What is Binary Tree in Data Structure?"}]},{"@type":"WebSite","@id":"http:\/\/43.205.93.38\/#website","url":"http:\/\/43.205.93.38\/","name":"PrepBytes Blog","description":"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING","publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/43.205.93.38\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/43.205.93.38\/#organization","name":"Prepbytes","url":"http:\/\/43.205.93.38\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/","url":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","contentUrl":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","width":160,"height":160,"caption":"Prepbytes"},"image":{"@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/prepbytes0211\/","https:\/\/www.instagram.com\/prepbytes\/","https:\/\/www.linkedin.com\/company\/prepbytes\/","https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA"]},{"@type":"Person","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e","name":"Prepbytes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","caption":"Prepbytes"},"url":"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/"}]}},"_links":{"self":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/11677","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/users\/52"}],"replies":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/comments?post=11677"}],"version-history":[{"count":2,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/11677\/revisions"}],"predecessor-version":[{"id":11710,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/11677\/revisions\/11710"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=11677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=11677"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=11677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}