<br />
<b>Warning</b>:  Undefined array key "global_protection_id" in <b>/home/wikitechy/public_html/interview-questions/wp-content/plugins/content-protector/inc/class-ps-rest-handler.php</b> on line <b>51</b><br />
{"id":495,"date":"2021-07-13T16:37:21","date_gmt":"2021-07-13T16:37:21","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=495"},"modified":"2021-09-13T07:07:39","modified_gmt":"2021-09-13T07:07:39","slug":"what-is-binary-tree-in-data-structures","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures\/","title":{"rendered":"What is Binary Tree in Data Structures ?"},"content":{"rendered":"<div class=\"TextHeading\">\n<div class=\"hddn\">\n<h2 id=\"what-is-binary-tree-in-data-structures\" class=\"color-pink\">What is Binary Tree in Data Structures ?<\/h2>\n<\/div>\n<\/div>\n<div class=\"Content\">\n<div class=\"hddn\">\n<ul>\n<li><a href=\"https:\/\/www.wikitechy.com\/technology\/c-program-lowest-common-ancestor-binary-search-tree\/\" target=\"_blank\" rel=\"noopener\">Binary tree<\/a>\u00a0is a special type of\u00a0<a href=\"https:\/\/www.wikitechy.com\/technology\/applications-tree-data-structure\/\" target=\"_blank\" rel=\"noopener\">data structure<\/a>. In binary tree, every node can have a maximum of 2 children, which are known as Left child and Right Child.<\/li>\n<li>It is a method of placing and locating the records in a database, especially when all the data is known to be in random access memory (RAM).<\/li>\n<li>A\u00a0<a href=\"https:\/\/www.wikitechy.com\/technology\/c-program-check-binary-tree-bst-not\/\" target=\"_blank\" rel=\"noopener\">binary tree<\/a>\u00a0has the benefits of both an ordered array and a\u00a0linked list\u00a0as search is as quick as in a\u00a0<a href=\"https:\/\/www.wikitechy.com\/technology\/algorithm-in-c-median-of-two-sorted-arrays\/\" target=\"_blank\" rel=\"noopener\">sorted array<\/a>\u00a0and insertion or deletion operation are as fast as in linked list.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<div class=\"ImageContent\">\n<div class=\"hddn\"><img decoding=\"async\" class=\"img-responsive center-block\" src=\"https:\/\/cdn.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures.jpg\" alt=\"What is Binary Tree in Data Structures\" \/><\/div>\n<\/div>\n<div class=\"TextHeading\">\n<div class=\"hddn\">\n<h2 id=\"representation-of-binary-tree-using-array\" class=\"color-green\">Representation of Binary Tree using Array<\/h2>\n<\/div>\n<\/div>\n<ul>\n<li><a href=\"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/if-the-depth-of-a-tree-is-3-levels-then-what-is-the-size-of-the-tree\/\" target=\"_blank\" rel=\"noopener\">Binary tree<\/a>\u00a0using array represents a node which is numbered sequentially level by level from left to right. Even empty nodes are numbered.<\/li>\n<\/ul>\n<div class=\"TextHeading\">\n<div class=\"hddn\">\n<h2 id=\"sample-code\" class=\"color-blue\">Sample Code<\/h2>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-javascript code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-javascript code-embed-code\">\/\/ JAVA implementation of tree using array <br\/>\/\/ numbering starting from 0 to n-1. <br\/>import java.util.*;<br\/>import java.lang.*;<br\/>import java.io.*;<br\/><br\/>class bTree {<br\/>    public static void main(String[] args) {<br\/>        btree_Array obj = new btree_Array();<br\/>        obj.Root(&quot;P&quot;);<br\/>        \/\/ obj.set_Left(&quot;Q&quot;, 0); <br\/>        obj.set_Right(&quot;R&quot;, 0);<br\/>        obj.set_Left(&quot;S&quot;, 1);<br\/>        obj.set_Right(&quot;T&quot;, 1);<br\/>        obj.set_Left(&quot;U&quot;, 2);<br\/>        obj.print_Tree();<br\/>    }<br\/>}<br\/><br\/>class btree_Array {<br\/>    static int root = 0;<br\/>    static String[] s = new String[10];<br\/><br\/>    \/*create root*\/<br\/>    public void Root(String key) {<br\/>        s[0] = key;<br\/>    }<br\/><br\/>    \/*create left son of root*\/<br\/>    public void set_Left(String key, int root) {<br\/>        int t = (root * 2) + 1;<br\/><br\/>        if (s[root] == null) {<br\/>            System.out.printf(&quot;Can&#039;t set child at %d, no parent found\\n&quot;, t);<br\/>        } else {<br\/>            s[t] = key;<br\/>        }<br\/>    }<br\/><br\/>    \/*create right son of root*\/<br\/>    public void set_Right(String key, int root) {<br\/>        int t = (root * 2) + 2;<br\/><br\/>        if (s[root] == null) {<br\/>            System.out.printf(&quot;Can&#039;t set child at %d, no parent found\\n&quot;, t);<br\/>        } else {<br\/>            s[t] = key;<br\/>        }<br\/>    }<br\/><br\/>    public void print_Tree() {<br\/>        for (int i = 0; i &lt; 10; i++) {<br\/>            if (s[i] != null)<br\/>                System.out.print(s[i]);<br\/>            else<br\/>                System.out.print(&quot;-&quot;);<br\/><br\/>        }<br\/>    }<br\/>}<\/code><\/pre> <\/div>\n<h2 id=\"output\" class=\"color-purple\">Output<\/h2>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-javascript code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-javascript code-embed-code\">Can&#039;t set child at 3, no parent found<br\/>Can&#039;t set child at 4, no parent found<br\/>P-R--U----<\/code><\/pre> <\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Answer : Binary tree is a special type of data structure&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"passster_activate_protection":false,"passster_protect_child_pages":"","passster_protection_type":"password","passster_password":"","passster_activate_overwrite_defaults":"","passster_headline":"","passster_instruction":"","passster_placeholder":"","passster_button":"","passster_id":"","passster_activate_misc_settings":"","passster_redirect_url":"","passster_hide":"no","passster_area_shortcode":"","gtb_hide_title":false,"gtb_wrap_title":false,"gtb_class_title":"","gtb_remove_headerfooter":false,"footnotes":""},"categories":[3028],"tags":[3468,195,3446,971,491,3469,3457,221,3456,3440,3444,3442,3443,3439,3441,368,3463,3470,3460,3467,3459,203,199,214,198,363,3057,15908,3438,3445,3458,3464,3466,3465,205,3449,3451,222,3452,3450,484,3054,196,212,207,366,204,3448,3453,3455,3454,206,972,3447,200,3055,3461,3044,3462,197,968,3056,285,969],"class_list":["post-495","post","type-post","status-publish","format-standard","hentry","category-data-structure","tag-a-full-binary-tree-with-n-leaves-contains","tag-accenture-interview-questions-and-answers","tag-almost-complete-binary-tree","tag-altimetrik-india-pvt-ltd-interview-questions-and-answers","tag-applied-materials-interview-questions-and-answers","tag-array-to-bst","tag-b-tree-in-data-structure","tag-bharti-airtel-interview-questions-and-answers","tag-binary-search-tree-example","tag-binary-search-tree-in-data-structure","tag-binary-tree","tag-binary-tree-example","tag-binary-tree-in-data-structure-program","tag-binary-tree-properties","tag-binary-treetypes-of-binary-tree","tag-bmc-software-interview-questions-and-answers","tag-bst-deletion","tag-bst-in-data-structure","tag-bst-java","tag-bst-traversal","tag-bst-tree","tag-capgemini-interview-questions-and-answers","tag-casting-networks-india-pvt-limited-interview-questions-and-answers","tag-cgi-group-inc-interview-questions-and-answers","tag-chetu-interview-questions-and-answers","tag-ciena-corporation-interview-questions-and-answers","tag-collabera-te-interview-questions-and-answers","tag-comodo-india-interview-questions-and-answers","tag-complete-binary-tree-in-data-structure","tag-complete-binary-tree-properties","tag-data-tree","tag-database-tree-structure","tag-define-bst","tag-define-tree-in-data-structure","tag-dell-international-services-india-pvt-ltd-interview-questions-and-answers","tag-difference-between-binary-tree-and-complete-binary-tree","tag-extended-binary-tree","tag-flipkart-interview-questions-and-answers","tag-full-binary-tree","tag-full-binary-tree-number-of-nodes","tag-genpact-interview-questions-and-answers","tag-globallogic-india-pvt-ltd-interview-questions-and-answers","tag-ibm-interview-questions-and-answers","tag-indecomm-global-services-interview-questions-and-answers","tag-mphasis-interview-questions-and-answers","tag-netapp-interview-questions-and-answers","tag-oracle-corporation-interview-questions-and-answers","tag-perfect-binary-tree","tag-properties-of-binary-search-tree","tag-properties-of-binary-search-tree-in-data-structure","tag-properties-of-binary-tree","tag-sap-labs-india-pvt-ltd-interview-questions-and-answers","tag-sapient-consulting-pvt-ltd-interview-questions-and-answers","tag-strictly-binary-tree","tag-tech-mahindra-interview-questions-and-answers","tag-tracxn-technologies-pvt-ltd-interview-questions-and-answers","tag-tree-algorithms","tag-tree-data-structure","tag-tree-structure","tag-unitedhealth-group-interview-questions-and-answers","tag-wipro-infotech-interview-questions-and-answers","tag-wm-global-technology-services-india-pvt-ltd-limited-wmgts-interview-questions-and-answers","tag-xoriant-solutions-pvt-ltd-interview-questions-and-answers","tag-yodlee-infotech-pvt-ltd-interview-questions-and-answers"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What is Binary Tree in Data Structures ? - Data Structure<\/title>\n<meta name=\"description\" content=\"What is Binary Tree in data structures ? - Binary tree is a special type of data structure. In binary tree, every node can have a maximum of 2 children, which are known as Left child and Right Child\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures\/\" \/>\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 Structures ? - Data Structure\" \/>\n<meta property=\"og:description\" content=\"What is Binary Tree in data structures ? - Binary tree is a special type of data structure. In binary tree, every node can have a maximum of 2 children, which are known as Left child and Right Child\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-13T16:37:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-09-13T07:07:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures.jpg\" \/>\n<meta name=\"author\" content=\"Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures\/\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures\/\",\"name\":\"What is Binary Tree in Data Structures ? - Data Structure\",\"isPartOf\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdn.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures.jpg\",\"datePublished\":\"2021-07-13T16:37:21+00:00\",\"dateModified\":\"2021-09-13T07:07:39+00:00\",\"author\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757\"},\"description\":\"What is Binary Tree in data structures ? - Binary tree is a special type of data structure. In binary tree, every node can have a maximum of 2 children, which are known as Left child and Right Child\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures\/#primaryimage\",\"url\":\"https:\/\/cdn.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures.jpg\",\"contentUrl\":\"https:\/\/cdn.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures.jpg\"},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/\",\"name\":\"Wikitechy\",\"description\":\"Interview Questions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757\",\"name\":\"Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g\",\"caption\":\"Editor\"},\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/author\/editor\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is Binary Tree in Data Structures ? - Data Structure","description":"What is Binary Tree in data structures ? - Binary tree is a special type of data structure. In binary tree, every node can have a maximum of 2 children, which are known as Left child and Right Child","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:\/\/www.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures\/","og_locale":"en_US","og_type":"article","og_title":"What is Binary Tree in Data Structures ? - Data Structure","og_description":"What is Binary Tree in data structures ? - Binary tree is a special type of data structure. In binary tree, every node can have a maximum of 2 children, which are known as Left child and Right Child","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures\/","og_site_name":"Wikitechy","article_published_time":"2021-07-13T16:37:21+00:00","article_modified_time":"2021-09-13T07:07:39+00:00","og_image":[{"url":"https:\/\/cdn.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures.jpg"}],"author":"Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Editor","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures\/","name":"What is Binary Tree in Data Structures ? - Data Structure","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures\/#primaryimage"},"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures\/#primaryimage"},"thumbnailUrl":"https:\/\/cdn.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures.jpg","datePublished":"2021-07-13T16:37:21+00:00","dateModified":"2021-09-13T07:07:39+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757"},"description":"What is Binary Tree in data structures ? - Binary tree is a special type of data structure. In binary tree, every node can have a maximum of 2 children, which are known as Left child and Right Child","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures\/#primaryimage","url":"https:\/\/cdn.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures.jpg","contentUrl":"https:\/\/cdn.wikitechy.com\/interview-questions\/data-structure\/what-is-binary-tree-in-data-structures.jpg"},{"@type":"WebSite","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website","url":"https:\/\/www.wikitechy.com\/interview-questions\/","name":"Wikitechy","description":"Interview Questions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757","name":"Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g","caption":"Editor"},"url":"https:\/\/www.wikitechy.com\/interview-questions\/author\/editor\/"}]}},"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/495","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/comments?post=495"}],"version-history":[{"count":4,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/495\/revisions"}],"predecessor-version":[{"id":3508,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/495\/revisions\/3508"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=495"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}