{"id":44,"date":"2019-02-06T23:14:57","date_gmt":"2019-02-06T23:14:57","guid":{"rendered":"https:\/\/www.kindsonthegenius.com\/coding\/?p=44"},"modified":"2019-02-06T23:14:57","modified_gmt":"2019-02-06T23:14:57","slug":"binary-search-tree","status":"publish","type":"post","link":"https:\/\/www.kindsonthegenius.com\/coding\/binary-search-tree\/","title":{"rendered":"Binary Search Tree"},"content":{"rendered":"<p>We would cover the Binary Search Tree implementation in Java under the following:<\/p>\n<ol>\n<li><a href=\"#t1\">Introduction to Binary Search Tree<\/a><\/li>\n<li><a href=\"#t2\">Java Program for Binary Search Tree<\/a><\/li>\n<li><a href=\"#t3\">Inserting into a Binary Search Tree<\/a><\/li>\n<li><a href=\"#t4\">Search for a key in Binary Search Tree<\/a><\/li>\n<li><a href=\"#t5\">Inorder Traversal of Binary Search Tree<\/a><\/li>\n<li><a href=\"#t6\">Complete Java Implementation of Binary Search Tree<\/a><\/li>\n<li><a href=\"#t7\">Performance of Binary Search Tree<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t1\">1. Introduction to Binary Search Tree<\/strong><\/h4>\n<p>A Binary search tree is a data structure that stores data in form of a tree. So there is a root node at the top, then left child and right child.<\/p>\n<p>A binary search tree have the following properties for every node:<\/p>\n<ul>\n<li>each node has at most two children<\/li>\n<li>the left child is less than or equal to the root node (left child\u00a0\u2264 root node)<\/li>\n<li>the right child is greater than or equal to the root (right\u00a0 child\u00a0\u2265 root node)<\/li>\n<\/ul>\n<p>An example of a binary search tree is given in Figure 1.0. You can check that it satisfies the above 3 properties.<\/p>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_173\" aria-describedby=\"caption-attachment-173\" style=\"width: 373px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-173 \" src=\"https:\/\/kindsonthegenius.com\/java\/wp-content\/uploads\/sites\/4\/2019\/01\/Binary-Search-tree.jpg\" alt=\"Example of a Binary Search Tree\" width=\"373\" height=\"273\" \/><figcaption id=\"caption-attachment-173\" class=\"wp-caption-text\">Figure 1.0: Example of a Binary Search Tree<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t2\">2. Java Program for Binary Search Tree<\/strong><\/h4>\n<p>We are going to write a class the implement the binary search tree in Java. The class would have the following methods:<\/p>\n<p>void Insert(int key): inserts the specified key into the tree<\/p>\n<p>boolean contains(int key): checks if the tree contains the specified key<\/p>\n<p>void PrintInOrder(): prints all the keys in the tree in sorted order<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t3\">3. Inserting into a Binary Search Tree &#8211; void Insert(int key)<\/strong><\/h4>\n<p>To insert a key, we first check if the key is\u00a0\u2264 the current data. If yes, then we check if the left is null. If null, then we return false. Else recursively call the insert() method on the left child<\/p>\n<p>If however, the key is\u00a0&gt; the root, then we do the same on the right child.<\/p>\n<p>The java program is given below:<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">\/\/Insert a key into a binary search tree<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #333399; font-weight: bold;\">void<\/span> <span style=\"color: #0066bb; font-weight: bold;\">insert<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #333399; font-weight: bold;\">int<\/span> key<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">if<\/span><span style=\"color: #333333;\">(<\/span>key <span style=\"color: #333333;\">&lt;=<\/span> <span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">data<\/span><span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>   <span style=\"color: #888888;\">\/\/Go left<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">if<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">left<\/span> <span style=\"color: #333333;\">==<\/span> <span style=\"color: #008800; font-weight: bold;\">null<\/span><span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">left<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> Node<span style=\"color: #333333;\">(<\/span>key<span style=\"color: #333333;\">);<\/span>\r\n\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">else<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">left<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">insert<\/span><span style=\"color: #333333;\">(<\/span>key<span style=\"color: #333333;\">);<\/span>\r\n\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">else<\/span> <span style=\"color: #333333;\">{<\/span>\t<span style=\"color: #888888;\">\/\/Go right<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">if<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">right<\/span> <span style=\"color: #333333;\">==<\/span> <span style=\"color: #008800; font-weight: bold;\">null<\/span><span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">right<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> Node<span style=\"color: #333333;\">(<\/span>key<span style=\"color: #333333;\">);<\/span>\r\n\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">else<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t <span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">right<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">insert<\/span><span style=\"color: #333333;\">(<\/span>key<span style=\"color: #333333;\">);<\/span>\r\n\t\t<span style=\"color: #333333;\">}<\/span>\t\t\t\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p><strong>Listing 1.0<\/strong>: The Insert Method for a Binary Search Tree<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t4\">4. Searching for a key in BST &#8211; boolean contains(int key)<\/strong><\/h4>\n<p>This would first check if the key equals the current node data. If yes, just return true.<\/p>\n<p>If no, check if the key is less than the current node data. If yes, then check the left child is null, and if null, return false. Else recursively call the contains() method on the left child.<\/p>\n<p>Repeat the same procedure on the right child, if the key is greater than the current node.<\/p>\n<p>The implementation of the contains method in java is given in Listing 1.1 below<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">\/\/Check if binary tree contains the given key<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #333399; font-weight: bold;\">boolean<\/span> <span style=\"color: #0066bb; font-weight: bold;\">contains<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #333399; font-weight: bold;\">int<\/span> key<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">if<\/span><span style=\"color: #333333;\">(<\/span>key <span style=\"color: #333333;\">==<\/span> <span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">data<\/span><span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> <span style=\"color: #008800; font-weight: bold;\">true<\/span><span style=\"color: #333333;\">;<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">if<\/span><span style=\"color: #333333;\">(<\/span>key <span style=\"color: #333333;\">&lt;<\/span> <span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">data<\/span><span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span> <span style=\"color: #888888;\">\/\/check left child<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">if<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">left<\/span> <span style=\"color: #333333;\">==<\/span> <span style=\"color: #008800; font-weight: bold;\">null<\/span><span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> <span style=\"color: #008800; font-weight: bold;\">false<\/span><span style=\"color: #333333;\">;<\/span>\r\n\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">else<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> <span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">left<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">contains<\/span><span style=\"color: #333333;\">(<\/span>key<span style=\"color: #333333;\">);<\/span>\r\n\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">else<\/span> <span style=\"color: #333333;\">{<\/span>  <span style=\"color: #888888;\">\/\/check right child<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">if<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">right<\/span> <span style=\"color: #333333;\">==<\/span> <span style=\"color: #008800; font-weight: bold;\">null<\/span><span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> <span style=\"color: #008800; font-weight: bold;\">false<\/span><span style=\"color: #333333;\">;<\/span>\r\n\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">else<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> <span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">right<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">contains<\/span><span style=\"color: #333333;\">(<\/span>key<span style=\"color: #333333;\">);<\/span>\r\n\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>Listing 1.1: The contains() method for Binary Search Tree<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t5\">5. void PrintInOrder()<\/strong><\/h4>\n<p>The PrintInOrder() uses the InOrder traversal to print all the nodes of the binary search tree. The InOrder traversal first visits the left subtree, then the root, then the right subtree.<\/p>\n<p>The Java implementation if quite easy to understand. It is given in Listing 1.2.<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">\/\/PrintInorder uses InOrder traversal<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #333399; font-weight: bold;\">void<\/span> <span style=\"color: #0066bb; font-weight: bold;\">PrintInOrder<\/span><span style=\"color: #333333;\">()<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">if<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">left<\/span> <span style=\"color: #333333;\">!=<\/span> <span style=\"color: #008800; font-weight: bold;\">null<\/span><span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">left<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">PrintInOrder<\/span><span style=\"color: #333333;\">();<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\tSystem<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">out<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">print<\/span><span style=\"color: #333333;\">(<\/span>data <span style=\"color: #333333;\">+<\/span> <span style=\"background-color: #fff0f0;\">\" \"<\/span><span style=\"color: #333333;\">);<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">if<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">right<\/span> <span style=\"color: #333333;\">!=<\/span> <span style=\"color: #008800; font-weight: bold;\">null<\/span><span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">right<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">PrintInOrder<\/span><span style=\"color: #333333;\">();<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>Listing 1.2: InOrder Printing of Binary Search Tree<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t6\">6. Complete Implementation of Binary Search Tree in Java<\/strong><\/h4>\n<p>You can find the complete program for Java Implementation of the binary search tree. Also, a test main method is provide. You can just copy and run the code.<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #bb0066; font-weight: bold;\">Node<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\tNode left<span style=\"color: #333333;\">;<\/span>\r\n\tNode right<span style=\"color: #333333;\">;<\/span>\r\n\t<span style=\"color: #333399; font-weight: bold;\">int<\/span> data<span style=\"color: #333333;\">;<\/span>\r\n\t\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #0066bb; font-weight: bold;\">Node<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #333399; font-weight: bold;\">int<\/span> data<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">data<\/span> <span style=\"color: #333333;\">=<\/span> data<span style=\"color: #333333;\">;<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\r\n\t<span style=\"color: #888888;\">\/\/Insert a key into a binary search tree<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #333399; font-weight: bold;\">void<\/span> <span style=\"color: #0066bb; font-weight: bold;\">insert<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #333399; font-weight: bold;\">int<\/span> key<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">if<\/span><span style=\"color: #333333;\">(<\/span>key <span style=\"color: #333333;\">&lt;=<\/span> <span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">data<\/span><span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>   <span style=\"color: #888888;\">\/\/Go left<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">if<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">left<\/span> <span style=\"color: #333333;\">==<\/span> <span style=\"color: #008800; font-weight: bold;\">null<\/span><span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">left<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> Node<span style=\"color: #333333;\">(<\/span>key<span style=\"color: #333333;\">);<\/span>\r\n\t\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">else<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">left<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">insert<\/span><span style=\"color: #333333;\">(<\/span>key<span style=\"color: #333333;\">);<\/span>\r\n\t\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">else<\/span> <span style=\"color: #333333;\">{<\/span>\t<span style=\"color: #888888;\">\/\/Go right<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">if<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">right<\/span> <span style=\"color: #333333;\">==<\/span> <span style=\"color: #008800; font-weight: bold;\">null<\/span><span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">right<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> Node<span style=\"color: #333333;\">(<\/span>key<span style=\"color: #333333;\">);<\/span>\r\n\t\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">else<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t\t <span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">right<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">insert<\/span><span style=\"color: #333333;\">(<\/span>key<span style=\"color: #333333;\">);<\/span>\r\n\t\t\t<span style=\"color: #333333;\">}<\/span>\t\t\t\r\n\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\t\r\n\t<span style=\"color: #888888;\">\/\/Check if binary tree contains the given key<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #333399; font-weight: bold;\">boolean<\/span> <span style=\"color: #0066bb; font-weight: bold;\">contains<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #333399; font-weight: bold;\">int<\/span> key<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">if<\/span><span style=\"color: #333333;\">(<\/span>key <span style=\"color: #333333;\">==<\/span> <span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">data<\/span><span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> <span style=\"color: #008800; font-weight: bold;\">true<\/span><span style=\"color: #333333;\">;<\/span>\r\n\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">if<\/span><span style=\"color: #333333;\">(<\/span>key <span style=\"color: #333333;\">&lt;<\/span> <span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">data<\/span><span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span> <span style=\"color: #888888;\">\/\/check left child<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">if<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">left<\/span> <span style=\"color: #333333;\">==<\/span> <span style=\"color: #008800; font-weight: bold;\">null<\/span><span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> <span style=\"color: #008800; font-weight: bold;\">false<\/span><span style=\"color: #333333;\">;<\/span>\r\n\t\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">else<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> <span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">left<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">contains<\/span><span style=\"color: #333333;\">(<\/span>key<span style=\"color: #333333;\">);<\/span>\r\n\t\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">else<\/span> <span style=\"color: #333333;\">{<\/span>  <span style=\"color: #888888;\">\/\/check right child<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">if<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">right<\/span> <span style=\"color: #333333;\">==<\/span> <span style=\"color: #008800; font-weight: bold;\">null<\/span><span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> <span style=\"color: #008800; font-weight: bold;\">false<\/span><span style=\"color: #333333;\">;<\/span>\r\n\t\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">else<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> <span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">right<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">contains<\/span><span style=\"color: #333333;\">(<\/span>key<span style=\"color: #333333;\">);<\/span>\r\n\t\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\t\r\n\t<span style=\"color: #888888;\">\/\/PrintInorder uses InOrder traversal<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #333399; font-weight: bold;\">void<\/span> <span style=\"color: #0066bb; font-weight: bold;\">PrintInOrder<\/span><span style=\"color: #333333;\">()<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">if<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">left<\/span> <span style=\"color: #333333;\">!=<\/span> <span style=\"color: #008800; font-weight: bold;\">null<\/span><span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">left<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">PrintInOrder<\/span><span style=\"color: #333333;\">();<\/span>\r\n\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t\tSystem<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">out<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">print<\/span><span style=\"color: #333333;\">(<\/span>data <span style=\"color: #333333;\">+<\/span> <span style=\"background-color: #fff0f0;\">\" \"<\/span><span style=\"color: #333333;\">);<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">if<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">right<\/span> <span style=\"color: #333333;\">!=<\/span> <span style=\"color: #008800; font-weight: bold;\">null<\/span><span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">right<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">PrintInOrder<\/span><span style=\"color: #333333;\">();<\/span>\r\n\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\t\r\n\t\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #008800; font-weight: bold;\">static<\/span> <span style=\"color: #333399; font-weight: bold;\">void<\/span> <span style=\"color: #0066bb; font-weight: bold;\">main<\/span><span style=\"color: #333333;\">(<\/span>String args<span style=\"color: #333333;\">[])<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t<span style=\"color: #333399; font-weight: bold;\">int<\/span> ar<span style=\"color: #333333;\">[]<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"color: #333333;\">{<\/span><span style=\"color: #0000dd; font-weight: bold;\">4<\/span><span style=\"color: #333333;\">,<\/span><span style=\"color: #0000dd; font-weight: bold;\">7<\/span><span style=\"color: #333333;\">,<\/span><span style=\"color: #0000dd; font-weight: bold;\">9<\/span><span style=\"color: #333333;\">,<\/span><span style=\"color: #0000dd; font-weight: bold;\">1<\/span><span style=\"color: #333333;\">,<\/span> <span style=\"color: #0000dd; font-weight: bold;\">11<\/span><span style=\"color: #333333;\">,<\/span> <span style=\"color: #0000dd; font-weight: bold;\">8<\/span><span style=\"color: #333333;\">,<\/span> <span style=\"color: #0000dd; font-weight: bold;\">3<\/span><span style=\"color: #333333;\">,<\/span> <span style=\"color: #0000dd; font-weight: bold;\">5<\/span><span style=\"color: #333333;\">};<\/span>\r\n\t\tNode binarytree <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> Node<span style=\"color: #333333;\">(<\/span><span style=\"color: #0000dd; font-weight: bold;\">8<\/span><span style=\"color: #333333;\">);<\/span>\r\n\t\t\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">for<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #333399; font-weight: bold;\">int<\/span> item <span style=\"color: #333333;\">:<\/span> ar<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\tbinarytree<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">insert<\/span><span style=\"color: #333333;\">(<\/span>item<span style=\"color: #333333;\">);<\/span>\r\n\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t\t\r\n\t\tbinarytree<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">PrintInOrder<\/span><span style=\"color: #333333;\">();<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>Listing 1.2: Complete implementation of Binary Search Tree in Java<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t7\">7. Performance of Binary Search Tree<\/strong><\/h4>\n<p>Both insert, delete and search operations take logarithmic time. This is means that the time complexity is order of logn &#8211; O(logn).<\/p>\n<p>Space complexity if linear. That is O(n)<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We would cover the Binary Search Tree implementation in Java under the following: Introduction to Binary Search Tree Java Program for Binary Search Tree Inserting &hellip; <\/p>\n","protected":false},"author":395,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,2,3],"tags":[],"class_list":["post-44","post","type-post","status-publish","format-standard","hentry","category-binary-search-tree","category-coding-challenge","category-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Binary Search Tree - Coding Challenge<\/title>\n<meta name=\"description\" content=\"How to create a binary search tree in Java and performs operations. Insert an element, Search, Delete and Print In Order traversal\" \/>\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.kindsonthegenius.com\/coding\/binary-search-tree\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Binary Search Tree - Coding Challenge\" \/>\n<meta property=\"og:description\" content=\"How to create a binary search tree in Java and performs operations. Insert an element, Search, Delete and Print In Order traversal\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.kindsonthegenius.com\/coding\/binary-search-tree\/\" \/>\n<meta property=\"og:site_name\" content=\"Coding Challenge\" \/>\n<meta property=\"article:published_time\" content=\"2019-02-06T23:14:57+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/kindsonthegenius.com\/java\/wp-content\/uploads\/sites\/4\/2019\/01\/Binary-Search-tree.jpg\" \/>\n<meta name=\"author\" content=\"kindsonthegenius\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"kindsonthegenius\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/binary-search-tree\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/binary-search-tree\\\/\"},\"author\":{\"name\":\"kindsonthegenius\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/#\\\/schema\\\/person\\\/63a68934672db675ff0cd80d066510c2\"},\"headline\":\"Binary Search Tree\",\"datePublished\":\"2019-02-06T23:14:57+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/binary-search-tree\\\/\"},\"wordCount\":576,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/binary-search-tree\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/kindsonthegenius.com\\\/java\\\/wp-content\\\/uploads\\\/sites\\\/4\\\/2019\\\/01\\\/Binary-Search-tree.jpg\",\"articleSection\":[\"BST\",\"Coding Challenge\",\"Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/binary-search-tree\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/binary-search-tree\\\/\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/binary-search-tree\\\/\",\"name\":\"Binary Search Tree - Coding Challenge\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/binary-search-tree\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/binary-search-tree\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/kindsonthegenius.com\\\/java\\\/wp-content\\\/uploads\\\/sites\\\/4\\\/2019\\\/01\\\/Binary-Search-tree.jpg\",\"datePublished\":\"2019-02-06T23:14:57+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/#\\\/schema\\\/person\\\/63a68934672db675ff0cd80d066510c2\"},\"description\":\"How to create a binary search tree in Java and performs operations. Insert an element, Search, Delete and Print In Order traversal\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/binary-search-tree\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/binary-search-tree\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/binary-search-tree\\\/#primaryimage\",\"url\":\"https:\\\/\\\/kindsonthegenius.com\\\/java\\\/wp-content\\\/uploads\\\/sites\\\/4\\\/2019\\\/01\\\/Binary-Search-tree.jpg\",\"contentUrl\":\"https:\\\/\\\/kindsonthegenius.com\\\/java\\\/wp-content\\\/uploads\\\/sites\\\/4\\\/2019\\\/01\\\/Binary-Search-tree.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/binary-search-tree\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Binary Search Tree\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/#website\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/\",\"name\":\"Coding Challenge\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/#\\\/schema\\\/person\\\/63a68934672db675ff0cd80d066510c2\",\"name\":\"kindsonthegenius\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g\",\"caption\":\"kindsonthegenius\"},\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/coding\\\/author\\\/kindsonthegenius-2\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Binary Search Tree - Coding Challenge","description":"How to create a binary search tree in Java and performs operations. Insert an element, Search, Delete and Print In Order traversal","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.kindsonthegenius.com\/coding\/binary-search-tree\/","og_locale":"en_US","og_type":"article","og_title":"Binary Search Tree - Coding Challenge","og_description":"How to create a binary search tree in Java and performs operations. Insert an element, Search, Delete and Print In Order traversal","og_url":"https:\/\/www.kindsonthegenius.com\/coding\/binary-search-tree\/","og_site_name":"Coding Challenge","article_published_time":"2019-02-06T23:14:57+00:00","og_image":[{"url":"https:\/\/kindsonthegenius.com\/java\/wp-content\/uploads\/sites\/4\/2019\/01\/Binary-Search-tree.jpg","type":"","width":"","height":""}],"author":"kindsonthegenius","twitter_card":"summary_large_image","twitter_misc":{"Written by":"kindsonthegenius","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.kindsonthegenius.com\/coding\/binary-search-tree\/#article","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/coding\/binary-search-tree\/"},"author":{"name":"kindsonthegenius","@id":"https:\/\/www.kindsonthegenius.com\/coding\/#\/schema\/person\/63a68934672db675ff0cd80d066510c2"},"headline":"Binary Search Tree","datePublished":"2019-02-06T23:14:57+00:00","mainEntityOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/coding\/binary-search-tree\/"},"wordCount":576,"commentCount":0,"image":{"@id":"https:\/\/www.kindsonthegenius.com\/coding\/binary-search-tree\/#primaryimage"},"thumbnailUrl":"https:\/\/kindsonthegenius.com\/java\/wp-content\/uploads\/sites\/4\/2019\/01\/Binary-Search-tree.jpg","articleSection":["BST","Coding Challenge","Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.kindsonthegenius.com\/coding\/binary-search-tree\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.kindsonthegenius.com\/coding\/binary-search-tree\/","url":"https:\/\/www.kindsonthegenius.com\/coding\/binary-search-tree\/","name":"Binary Search Tree - Coding Challenge","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/coding\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/coding\/binary-search-tree\/#primaryimage"},"image":{"@id":"https:\/\/www.kindsonthegenius.com\/coding\/binary-search-tree\/#primaryimage"},"thumbnailUrl":"https:\/\/kindsonthegenius.com\/java\/wp-content\/uploads\/sites\/4\/2019\/01\/Binary-Search-tree.jpg","datePublished":"2019-02-06T23:14:57+00:00","author":{"@id":"https:\/\/www.kindsonthegenius.com\/coding\/#\/schema\/person\/63a68934672db675ff0cd80d066510c2"},"description":"How to create a binary search tree in Java and performs operations. Insert an element, Search, Delete and Print In Order traversal","breadcrumb":{"@id":"https:\/\/www.kindsonthegenius.com\/coding\/binary-search-tree\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.kindsonthegenius.com\/coding\/binary-search-tree\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.kindsonthegenius.com\/coding\/binary-search-tree\/#primaryimage","url":"https:\/\/kindsonthegenius.com\/java\/wp-content\/uploads\/sites\/4\/2019\/01\/Binary-Search-tree.jpg","contentUrl":"https:\/\/kindsonthegenius.com\/java\/wp-content\/uploads\/sites\/4\/2019\/01\/Binary-Search-tree.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.kindsonthegenius.com\/coding\/binary-search-tree\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.kindsonthegenius.com\/coding\/"},{"@type":"ListItem","position":2,"name":"Binary Search Tree"}]},{"@type":"WebSite","@id":"https:\/\/www.kindsonthegenius.com\/coding\/#website","url":"https:\/\/www.kindsonthegenius.com\/coding\/","name":"Coding Challenge","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.kindsonthegenius.com\/coding\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.kindsonthegenius.com\/coding\/#\/schema\/person\/63a68934672db675ff0cd80d066510c2","name":"kindsonthegenius","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g","caption":"kindsonthegenius"},"url":"https:\/\/www.kindsonthegenius.com\/coding\/author\/kindsonthegenius-2\/"}]}},"_links":{"self":[{"href":"https:\/\/www.kindsonthegenius.com\/coding\/wp-json\/wp\/v2\/posts\/44","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kindsonthegenius.com\/coding\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kindsonthegenius.com\/coding\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/coding\/wp-json\/wp\/v2\/users\/395"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/coding\/wp-json\/wp\/v2\/comments?post=44"}],"version-history":[{"count":1,"href":"https:\/\/www.kindsonthegenius.com\/coding\/wp-json\/wp\/v2\/posts\/44\/revisions"}],"predecessor-version":[{"id":45,"href":"https:\/\/www.kindsonthegenius.com\/coding\/wp-json\/wp\/v2\/posts\/44\/revisions\/45"}],"wp:attachment":[{"href":"https:\/\/www.kindsonthegenius.com\/coding\/wp-json\/wp\/v2\/media?parent=44"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/coding\/wp-json\/wp\/v2\/categories?post=44"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/coding\/wp-json\/wp\/v2\/tags?post=44"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}