{"id":81399,"date":"2021-06-30T09:00:34","date_gmt":"2021-06-30T03:30:34","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=81399"},"modified":"2021-06-30T09:00:34","modified_gmt":"2021-06-30T03:30:34","slug":"binary-search-in-data-structure","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/binary-search-in-data-structure\/","title":{"rendered":"Binary Search in Data Structure"},"content":{"rendered":"<p>There are various ways to search a particular element from a given list. One of them is Binary search.<br \/>\nWhen there exists so much data everywhere, it is very necessary to have a good searching method to search for the particular data in lesser time.<\/p>\n<p>Binary search works faster than linear search. It is one of the fastest searching algorithms.<\/p>\n<h3>What is Binary Search?<\/h3>\n<p>It is a searching technique. It is based upon Divide and conquer strategy. Binary search is applicable only on sorted data. It takes O(log n) time for completion.<\/p>\n<p>It divides the given array into halves and then checks the middle element. If the middle element is smaller than the element to be searched, the algorithm selects the second half of the array and discards the first half.<\/p>\n<p>Thus, at every step, the binary search algorithm keeps on discarding half of the array based on the value of the middle element. This process continues until the array becomes of the size 1 or 2 and the algorithm finally gets the required element.<\/p>\n<p>If the search is successful i.e. the element is present in the array, it returns the index of that element. If the element is not present inside the array, the algorithm returns -1.<\/p>\n<h3>Working of Binary Search<\/h3>\n<p>Let us understand the working of a binary search algorithm with the help of an example.<\/p>\n<p>Consider a sorted array having 10 elements as shown:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/Binary-Search-normal-image01.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81471\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/Binary-Search-normal-image01.jpg\" alt=\"Binary Search Working\" width=\"750\" height=\"152\" \/><\/a><\/p>\n<p>Suppose we wish to search 38 in the array.<\/p>\n<p><strong>Step 1:<\/strong> Find the middle element of the array.<\/p>\n<p><strong>index(Middle) = index(low) + index(high &#8211; low)\/2.<\/strong><\/p>\n<p>Here, middle = 0 + (9-0)\/2 = 4 i.e. the element at the 4th index i.e. 25.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/Binary-Search-normal-image02.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81472\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/Binary-Search-normal-image02.jpg\" alt=\"Working of Binary Search\" width=\"750\" height=\"350\" \/><\/a><\/p>\n<p><strong>Step 2<\/strong>: Compare 38 with the middle element. 38 &gt; 25 So, discard the first half.<\/p>\n<p><strong>Step 3:<\/strong> Select the send half of the array. For the second half, low = middle+1 as shown:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/Binary-Search-normal-image03.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81473\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/Binary-Search-normal-image03.jpg\" alt=\"Binary Search Algorithm\" width=\"750\" height=\"350\" \/><\/a><\/p>\n<p><strong>Step 4:<\/strong> Find the middle element of this smaller array which comes out to 32. Compare 38 with 32.<\/p>\n<p>38 &gt; 32 Thus, discard the first half of this array.<\/p>\n<p><strong>Step 5:<\/strong> Select the remaining half of the array by doing low = middle+1 as shown:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/Binary-Search-normal-image04.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81474\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/Binary-Search-normal-image04.jpg\" alt=\"Binary Search\" width=\"750\" height=\"350\" \/><\/a><\/p>\n<p>Finally, we have found 38 and thus the algorithm will halt here.<\/p>\n<p>Output: 8.<\/p>\n<h3>Pseudo-code for Binary Search<\/h3>\n<p>We can implement binary search in two ways:<\/p>\n<p>1. Iterative approach<br \/>\n2. Recursive approach (Using divide and conquer)<\/p>\n<p>The<strong> pseudo-code for binary search<\/strong> is given as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Procedure Binary_Search(int Arr[], n) \/\/Arr is an array of length n\n   key := value to be searched\n\n   Set low = 1\n   Set high = n \n\n   while x not found\n      if high &lt; low \n         Display x does not exist\n         EXIT.\n   \n      set middle = low + (high - low) \/ 2\n      \n      if Arr[mid] &lt; key\n         set low = middle + 1\n         \n      if Arr[middle] &gt; key\n         set high = middle - 1 \n\n      if Arr[middle] = key \n        Display x found at location middle\n         EXIT.\n   end while\n   \nend procedure\n<\/pre>\n<h3>Binary Search Algorithm:<\/h3>\n<h4>1. Using Iterative approach:<\/h4>\n<p><strong>Step 1:<\/strong> Set low = first_index, high = last_index, location = -1<br \/>\n<strong>Step 2<\/strong>: Repeat steps 3 and 4 while low &lt;= high<br \/>\n<strong>Step 3<\/strong>: set middle = (low + high)\/2<br \/>\n<strong>Step 4<\/strong>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">if Arr[middle] == key\n             set loc = middle\n             Display \u201cThe element to be searched is present at location: \u201c + loc\n             go to step 6\n        else if Arr[mid] &lt; key\n             set low = middle + 1\n        else\n             set high = middle - 1\n        [end if]\n        [end loop]\n<\/pre>\n<p><strong>Step 5<\/strong>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">if loc == -1\n             print \"Element to be searched is not present in the array\"\n             [end of if]\n<\/pre>\n<p><strong>Step 6<\/strong>: Stop<\/p>\n<h4>2. Using Recursive approach:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int Binary_Search(Arr[], key, low, high)\n        middle = (low + high) \/ 2 \n        if key == Arr[middle]\n            return mid\n        else if key &gt; Arr[middle]       \n            return Binary_Search(Arr[], key, middle+1, high)\n        else                               \n            return Binary_Search(Arr[], key, low, middle-1)\n<\/pre>\n<h4>Implementation of Linear Search in C:<\/h4>\n<h5>Iterative code:<\/h5>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int Binary_Search(int Arr[], int low, int high, int key)\n{\n    while (low &lt;= high) {\n        int middle = low + (high - low) \/ 2;\n \n        if (Arr[middle] == key)\n            return middle;\n \n        if (Arr[middle] &lt; key)\n            low = middle + 1;\n \n        else\n            high = middle - 1;\n    }\n \n    return -1;\n}\n \nint main(void)\n{\n    int arr[] = {2, 4, 8, 17, 25, 27, 32, 38, 45};\n    int len = sizeof(arr) \/ sizeof(arr[0]);\n    int key = 38;\n    int result = Binary_Search(arr, 0, len-1, key);\n    if(result == -1)\n    printf(\"Element not found\");\n    else\n    printf(\"Element found at index: %d\",result+1);\n    return 0;\n}\n<\/pre>\n<h5>Recursive code:<\/h5>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\nint Binary_Search(int Arr[], int low, int high, int key)\n{\n    if (high &gt;= low) {\n        int middle = low + (high - low) \/ 2;\n        if (Arr[middle] == key)\n            return middle;\n        if (Arr[middle] &gt; key)\n            return Binary_Search(Arr, low, middle-1, key);\n        return binarySearch(Arr, middle+1, high, key);\n    }\n    return -1;\n}\n \nint main(void)\n{\n    int arr[] = {2, 4, 8, 17, 25, 27, 32, 38, 45};\n    int len = sizeof(arr) \/ sizeof(arr[0]);\n    int key = 38;\n    int result = Binary_Search(arr, 0, len-1, key);\n    if(result == -1) \n    printf(\"Element not found in the array\");\n    else\n    printf(\"Element is found at location:  %d \",result+1);\n    return 0;\n}\n<\/pre>\n<h4>Binary Search implementation in C++<\/h4>\n<h5>Iterative code:<\/h5>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;bits\/stdc++.h&gt;\nusing namespace std;\n \nint Binary_Search(int Arr[], int low, int high, int key)\n{\n    while (low &lt;= high) {\n        int middle = low + (high - low) \/ 2;\n \n        if (Arr[middle] == key)\n            return middle;\n        if (Arr[middle] &lt; key)\n            low = middle + 1;\n \n        else\n            high = middle - 1;\n    }\n \n    return -1;\n}\n \nint main(void)\n{\n    int arr[] = {2, 4, 8, 17, 25, 27, 32, 38, 45};\n    int len = sizeof(arr) \/ sizeof(arr[0]);\n    int key = 38;\n    int result = Binary_Search(arr, 0, len - 1, key);\n    if(result == -1)\n    cout &lt;&lt; \"Element not found\" ;\n    else\n    cout &lt;&lt; \"Element found at index \" &lt;&lt; result+1;\n    return 0;\n}\n<\/pre>\n<h5>Recursive code:<\/h5>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;bits\/stdc++.h&gt;\nusing namespace std;\nint Binary_Search(int Arr[], int low, int high, int key)\n{\n    if (high &gt;= low) {\n        int middle = low + (high - low) \/ 2;\n        if (Arr[middle] == key)\n            return middle;\n \n        if (Arr[middle] &gt; key)\n            return Binary_Search(Arr, low, middle-1, key);\n \n        return Binary_Search(Arr, middle+1, high, key);\n    }\n    return -1;\n}\n \nint main(void)\n{\n    int arr[] = {2, 4, 8, 17, 25, 27, 32, 38, 45};\n    int key = 38;\n    int len = sizeof(arr) \/ sizeof(arr[0]);\n    int result = Binary_Search(arr, 0, len - 1, key);\n    if(result == -1) \n    cout &lt;&lt; \"Element not found in the array\" ;\n    else\n    cout &lt;&lt; \"Element found at location: \" &lt;&lt; result+1;\n    return 0;\n}\n<\/pre>\n<h4>Implementation of Binary Search in Java:<\/h4>\n<h5>Iterative code:<\/h5>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">public class BinarySearch {\n    int Binary_Search(int Arr[], int key)\n    {\n        int low = 0, high = Arr.length - 1;\n        while (low &lt;= high) {\n            int middle = low + (high - low) \/ 2;\n \n            if (Arr[middle] == key)\n                return middle;\n \n            if (Arr[middle] &lt; key)\n                low = middle + 1;\n \n            else\n                high = middle - 1;\n        }\n \n        return -1;\n    }\n \n    public static void main(String args[])\n    {\n        BinarySearch obj = new BinarySearch();\n        int Arr[] = {2, 4, 8, 17, 25, 27, 32, 38, 45};\n        int key = 38;\n        int result = obj.Binary_Search(Arr, key);\n        if (result == -1)\n            System.out.println(\"Element not found\");\n        else\n            System.out.println(\"Element found at index: \" + (result+1));\n    }\n}\n<\/pre>\n<h5>Recursive code:<\/h5>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">public class BinarySearch {\n    \n    int Binary_Search(int Arr[], int low, int high, int key)\n    {\n        if (high &gt;= low) {\n            int middle = low + (high - low) \/ 2;\n            \n            if (Arr[middle] == key)\n                return middle;\n \n            if (Arr[middle] &gt; key)\n                return Binary_Search(Arr, low, middle-1, key);\n            return Binary_Search(Arr, middle+1, high, key);\n        }\n        return -1;\n    }\n \n    public static void main(String args[])\n    {\n        BinarySearch obj = new BinarySearch();\n        int Arr[] = {2, 4, 8, 17, 25, 27, 32, 38, 45};\n        int len = Arr.length;\n        int key = 38;\n        int result = ob.Binary_Search(Arr, 0, len-1, key);\n        if (result == -1)\n            System.out.println(\"Element not found\");\n        else\n            System.out.println(\"Element found at index: \" + result+1);\n    }\n}\n<\/pre>\n<h4>Binary Search implementation in Python:<\/h4>\n<h5>Iterative code:<\/h5>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def Binary_Search(Arr, low, high, key):\n \n    while low &lt;= high:\n \n        middle = low + (high - low)\/\/2\n       \n        if Arr[middle] == key:\n            return middle\n \n        elif Arr[middle] &lt; key:\n            low = middle + 1\n \n        else:\n            high = middle - 1\n  \n    return -1\n \nlist = [2, 4, 8, 17, 25, 27, 32, 38, 45]\nkey = 38\n \nresult = Binary_Search(list, 0, len(list)-1, key)\n \nif result == -1:\n    print (\"Element not found\")\nelse:\n    print (\"Element found at location: % d\" % (result+1))\n<\/pre>\n<h5>Recursive code:<\/h5>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def Binary_Search (Arr, low,high, key):\n \n    if high &gt;= low:\n \n        middle = low + (high - low) \/\/ 2\n \n        if Arr[middle] == key:\n            return key\n         \n        elif arr[middle] &gt; key:\n            return Binary_Search(Arr, low, middle-1, key)\n \n        else:\n            return Binary_Search(Arr, middle + 1, high, key)\n \n    else:\n        return -1\n \nlist = [2, 4, 8, 17, 25, 27, 32, 38, 45]\nkey = 38\n \nresult = Binary_Search(list, 0, len(list)-1, key)\n \nif result != -1:\n    print (\"Element foubd at location % d\" % (result+1))\nelse:\n    print (\"Element not found\")\n<\/pre>\n<h3>Complexity of Binary Search<\/h3>\n<h4>Binary Search Time complexity:<\/h4>\n<table style=\"height: 172px\" width=\"652\">\n<tbody>\n<tr>\n<td><b>Case\u00a0<\/b><\/td>\n<td><b>Complexity\u00a0<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Best case<\/span><\/td>\n<td><span style=\"font-weight: 400\">O(1)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Average case<\/span><\/td>\n<td><span style=\"font-weight: 400\">O(log n)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Worst case<\/span><\/td>\n<td><span style=\"font-weight: 400\">O(log n)<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>Binary Search Space complexity:<\/h4>\n<p>In the worst case, the space complexity is O(1).<\/p>\n<h3>Linear Search v\/s Binary Search<\/h3>\n<table>\n<tbody>\n<tr>\n<td><strong>Linear search<\/strong><\/td>\n<td><strong>Binary search<\/strong><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">It follows a sequential approach.<\/span><\/td>\n<td><span style=\"font-weight: 400\">This follows a divide and conquer approach.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">It works well on unsorted data.<\/span><\/td>\n<td><span style=\"font-weight: 400\">To apply binary search, data has to be sorted.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Its worst-case time complexity is O(n).<\/span><\/td>\n<td><span style=\"font-weight: 400\">Its worst-case time complexity is O(log n)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">It is slower in comparison to binary search.<\/span><\/td>\n<td><span style=\"font-weight: 400\">It is more efficient than linear search.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">In linear search, we compare an element with every other element.<\/span><\/td>\n<td><span style=\"font-weight: 400\">In binary search, we don\u2019t compare an element with all other elements. We leave a few comparisons.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">We prefer linear search only for small-sized data.<\/span><\/td>\n<td><span style=\"font-weight: 400\">It is preferred for large-sized data.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">We can implement linear search on all linear data structures like arrays and linked lists.\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400\">We can implement binary search only on those data structures that permit 2-way traversal.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Applications of Binary Search<\/h3>\n<p>1. It is internally used in the inbuilt libraries of programming languages such as C, C++ and Java.<\/p>\n<p>2. It helps to pinpoint the position of error during debugging of a particular code.<\/p>\n<h3>Conclusion<\/h3>\n<p>Binary search is a searching technique that follows the divide and conquer strategy. It is more efficient in comparison to other searching algorithms.<\/p>\n<p>In this article, we have covered the working of binary search, its implementation in various programming languages as well as its application in the programming world. We have also discussed how binary search is different from linear search.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are various ways to search a particular element from a given list. One of them is Binary search. When there exists so much data everywhere, it is very necessary to have a good&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":81467,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3555],"tags":[3646,3647,3648],"class_list":["post-81399","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-structure","tag-binary-search","tag-binary-search-implementation","tag-working-of-binary-search"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Binary Search in Data Structure - TechVidvan<\/title>\n<meta name=\"description\" content=\"Learn the working of binary search, its implementation in various programming languages as well as its application in the programming world.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/binary-search-in-data-structure\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Binary Search in Data Structure - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Learn the working of binary search, its implementation in various programming languages as well as its application in the programming world.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/binary-search-in-data-structure\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-06-30T03:30:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/TV-Binary-Search.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Binary Search in Data Structure - TechVidvan","description":"Learn the working of binary search, its implementation in various programming languages as well as its application in the programming world.","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:\/\/techvidvan.com\/tutorials\/binary-search-in-data-structure\/","og_locale":"en_US","og_type":"article","og_title":"Binary Search in Data Structure - TechVidvan","og_description":"Learn the working of binary search, its implementation in various programming languages as well as its application in the programming world.","og_url":"https:\/\/techvidvan.com\/tutorials\/binary-search-in-data-structure\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2021-06-30T03:30:34+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/TV-Binary-Search.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/binary-search-in-data-structure\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/binary-search-in-data-structure\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Binary Search in Data Structure","datePublished":"2021-06-30T03:30:34+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/binary-search-in-data-structure\/"},"wordCount":731,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/binary-search-in-data-structure\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/TV-Binary-Search.jpg","keywords":["Binary Search","Binary Search Implementation","Working of Binary Search"],"articleSection":["Data Structure Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/binary-search-in-data-structure\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/binary-search-in-data-structure\/","url":"https:\/\/techvidvan.com\/tutorials\/binary-search-in-data-structure\/","name":"Binary Search in Data Structure - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/binary-search-in-data-structure\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/binary-search-in-data-structure\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/TV-Binary-Search.jpg","datePublished":"2021-06-30T03:30:34+00:00","description":"Learn the working of binary search, its implementation in various programming languages as well as its application in the programming world.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/binary-search-in-data-structure\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/binary-search-in-data-structure\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/binary-search-in-data-structure\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/TV-Binary-Search.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/TV-Binary-Search.jpg","width":1200,"height":628,"caption":"Binary Search"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/binary-search-in-data-structure\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Binary Search in Data Structure"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/81399","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=81399"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/81399\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/81467"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=81399"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=81399"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=81399"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}