{"id":261586,"date":"2024-07-07T01:57:06","date_gmt":"2024-07-07T01:57:06","guid":{"rendered":"https:\/\/namso-gen.co\/blog\/?p=261586"},"modified":"2024-07-07T01:57:06","modified_gmt":"2024-07-07T01:57:06","slug":"how-to-modify-binary-search-to-find-closest-value","status":"publish","type":"post","link":"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/","title":{"rendered":"How to modify binary search to find closest value?"},"content":{"rendered":"<p>Binary search is a commonly used algorithm for searching for a specific value in a sorted array. However, what if we want to find the closest value instead of an exact match? In this article, we will discuss how to modify the binary search algorithm to find the closest value efficiently.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_62 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/#Using_Binary_Search_to_Find_Closest_Value\" title=\"Using Binary Search to Find Closest Value\">Using Binary Search to Find Closest Value<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/#How_to_Modify_Binary_Search_to_Find_Closest_Value\" title=\"How to Modify Binary Search to Find Closest Value?\">How to Modify Binary Search to Find Closest Value?<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/#1_Can_binary_search_be_used_to_find_the_closest_value_in_an_unsorted_array\" title=\"1. Can binary search be used to find the closest value in an unsorted array?\">1. Can binary search be used to find the closest value in an unsorted array?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/#2_Will_this_modified_binary_search_always_find_the_closest_value\" title=\"2. Will this modified binary search always find the closest value?\">2. Will this modified binary search always find the closest value?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/#3_What_is_the_time_complexity_of_this_modified_binary_search_algorithm\" title=\"3. What is the time complexity of this modified binary search algorithm?\">3. What is the time complexity of this modified binary search algorithm?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/#4_How_does_this_modified_binary_search_differ_from_the_regular_binary_search\" title=\"4. How does this modified binary search differ from the regular binary search?\">4. How does this modified binary search differ from the regular binary search?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/#5_Can_this_modified_binary_search_algorithm_handle_duplicate_values_in_the_array\" title=\"5. Can this modified binary search algorithm handle duplicate values in the array?\">5. Can this modified binary search algorithm handle duplicate values in the array?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/#6_What_should_be_done_if_there_are_multiple_values_with_the_same_minimum_difference\" title=\"6. What should be done if there are multiple values with the same minimum difference?\">6. What should be done if there are multiple values with the same minimum difference?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/#7_Will_this_algorithm_work_on_arrays_with_negative_values\" title=\"7. Will this algorithm work on arrays with negative values?\">7. Will this algorithm work on arrays with negative values?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/#8_What_happens_if_the_target_value_is_greater_than_the_maximum_value_in_the_array\" title=\"8. What happens if the target value is greater than the maximum value in the array?\">8. What happens if the target value is greater than the maximum value in the array?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/#9_Is_it_possible_to_modify_this_algorithm_to_find_closest_values_within_a_certain_range\" title=\"9. Is it possible to modify this algorithm to find closest values within a certain range?\">9. Is it possible to modify this algorithm to find closest values within a certain range?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/#10_How_does_this_algorithm_perform_on_large_arrays\" title=\"10. How does this algorithm perform on large arrays?\">10. How does this algorithm perform on large arrays?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/#11_Is_it_necessary_for_the_array_to_be_sorted_in_ascending_order\" title=\"11. Is it necessary for the array to be sorted in ascending order?\">11. Is it necessary for the array to be sorted in ascending order?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/#12_Can_this_modified_binary_search_be_used_to_find_the_closest_value_in_a_multidimensional_array\" title=\"12. Can this modified binary search be used to find the closest value in a multidimensional array?\">12. Can this modified binary search be used to find the closest value in a multidimensional array?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Using_Binary_Search_to_Find_Closest_Value\"><\/span>Using Binary Search to Find Closest Value<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The binary search algorithm works by continuously dividing the search space in half until the target value is found or the search space is empty. This is done by comparing the target value with the middle element of the array and narrowing down the search space accordingly.<\/p>\n<p>To modify the binary search algorithm to find the closest value, we can follow the same approach but with a slight tweak in the comparison. Instead of checking for an exact match, we update our condition to find the element with the minimum difference from the target value.<\/p>\n<p>Let&#8217;s take a look at the modified binary search algorithm to find the closest value:<\/p>\n<p>&#8220;`<br \/>\n1. Set low = 0 and high = length of the array &#8211; 1<br \/>\n2. While low <= high:<br \/>\n   3. Set mid = low + (high &#8211; low) \/ 2    \/\/ Calculate the middle index<br \/>\n   4. If array[mid] is equal to target value:<br \/>\n        &#8211; Return array[mid] as it is an exact match.<br \/>\n   5. If array[mid] is greater than target value:<br \/>\n        &#8211; Set high = mid &#8211; 1    \/\/ Discard the right half of the array<br \/>\n   6. If array[mid] is less than target value:<br \/>\n        &#8211; Set low = mid + 1    \/\/ Discard the left half of the array<br \/>\n   7. Update closest value:<br \/>\n        &#8211; If the absolute difference between array[mid] and the target value is less than the absolute difference between the current closest value and the target value,<br \/>\n          &#8211; Update closest value = array[mid]<br \/>\n8. Return closest value<br \/>\n&#8220;`<\/p>\n<p>By following these steps, we can find the closest value to our target efficiently using binary search.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_to_Modify_Binary_Search_to_Find_Closest_Value\"><\/span><strong>How to Modify Binary Search to Find Closest Value?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><strong>The modification required to find the closest value in binary search is to update the condition when an exact match is not found. Instead, update the closest value with the element having the minimum difference from the target value.<\/strong><\/p>\n<h3><span class=\"ez-toc-section\" id=\"1_Can_binary_search_be_used_to_find_the_closest_value_in_an_unsorted_array\"><\/span>1. Can binary search be used to find the closest value in an unsorted array?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nNo, binary search can only be applied to sorted arrays.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"2_Will_this_modified_binary_search_always_find_the_closest_value\"><\/span>2. Will this modified binary search always find the closest value?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nYes, the modified binary search algorithm will always return the closest value to the target value.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"3_What_is_the_time_complexity_of_this_modified_binary_search_algorithm\"><\/span>3. What is the time complexity of this modified binary search algorithm?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nThe time complexity of this modified binary search algorithm is O(log n), where n is the number of elements in the array.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"4_How_does_this_modified_binary_search_differ_from_the_regular_binary_search\"><\/span>4. How does this modified binary search differ from the regular binary search?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nThe main difference lies in the condition to update the closest value when an exact match is not found.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"5_Can_this_modified_binary_search_algorithm_handle_duplicate_values_in_the_array\"><\/span>5. Can this modified binary search algorithm handle duplicate values in the array?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nYes, this algorithm can handle duplicate values in the array.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"6_What_should_be_done_if_there_are_multiple_values_with_the_same_minimum_difference\"><\/span>6. What should be done if there are multiple values with the same minimum difference?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nIn such cases, the algorithm will return the first occurrence of the value with the minimum difference.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"7_Will_this_algorithm_work_on_arrays_with_negative_values\"><\/span>7. Will this algorithm work on arrays with negative values?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nYes, this algorithm can handle arrays with negative values. The absolute difference is used to calculate the minimum difference.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"8_What_happens_if_the_target_value_is_greater_than_the_maximum_value_in_the_array\"><\/span>8. What happens if the target value is greater than the maximum value in the array?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nThe modified binary search algorithm will return the maximum value in the array as the closest value.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"9_Is_it_possible_to_modify_this_algorithm_to_find_closest_values_within_a_certain_range\"><\/span>9. Is it possible to modify this algorithm to find closest values within a certain range?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nYes, by adding additional conditions, this algorithm can be modified to find closest values within a specified range.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"10_How_does_this_algorithm_perform_on_large_arrays\"><\/span>10. How does this algorithm perform on large arrays?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nThis algorithm performs efficiently on large arrays due to its logarithmic time complexity.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"11_Is_it_necessary_for_the_array_to_be_sorted_in_ascending_order\"><\/span>11. Is it necessary for the array to be sorted in ascending order?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nYes, the array must be sorted in ascending order for the binary search algorithm to work correctly.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"12_Can_this_modified_binary_search_be_used_to_find_the_closest_value_in_a_multidimensional_array\"><\/span>12. Can this modified binary search be used to find the closest value in a multidimensional array?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nNo, this algorithm is specifically designed for one-dimensional sorted arrays. It cannot be directly applied to multidimensional arrays.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Binary search is a commonly used algorithm for searching for a specific value in a sorted array. However, what if we want to find the closest value instead of an exact match? In this article, we will discuss how to modify the binary search algorithm to find the closest value efficiently. Using Binary Search to &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"How to modify binary search to find closest value?\" class=\"read-more button\" href=\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/#more-261586\">Read more<span class=\"screen-reader-text\">How to modify binary search to find closest value?<\/span><\/a><\/p>\n","protected":false},"author":66,"featured_media":107420,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[86279],"tags":[],"class_list":["post-261586","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-learn","no-featured-image-padding"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to modify binary search to find closest value?<\/title>\n<meta name=\"description\" content=\"Binary search is a commonly used algorithm for searching for a specific value in a sorted array. However, what if we want to find the closest value\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to modify binary search to find closest value?\" \/>\n<meta property=\"og:description\" content=\"Binary search is a commonly used algorithm for searching for a specific value in a sorted array. However, what if we want to find the closest value\" \/>\n<meta property=\"og:url\" content=\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/\" \/>\n<meta property=\"og:site_name\" content=\"Namso Gen Blog - Free Credit Card Generator [100% Valid]\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/synchronyfinancial\" \/>\n<meta property=\"article:published_time\" content=\"2024-07-07T01:57:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2024\/03\/faq.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Jamie Steele\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@synchrony\" \/>\n<meta name=\"twitter:site\" content=\"@synchrony\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jamie Steele\" \/>\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\":\"Article\",\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/\"},\"author\":{\"name\":\"Jamie Steele\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/4938663f06a1cff2dff5c1af38d151c0\"},\"headline\":\"How to modify binary search to find closest value?\",\"datePublished\":\"2024-07-07T01:57:06+00:00\",\"dateModified\":\"2024-07-07T01:57:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/\"},\"wordCount\":188,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/#organization\"},\"articleSection\":[\"Learn\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/\",\"url\":\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/\",\"name\":\"How to modify binary search to find closest value?\",\"isPartOf\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/#website\"},\"datePublished\":\"2024-07-07T01:57:06+00:00\",\"dateModified\":\"2024-07-07T01:57:06+00:00\",\"description\":\"Binary search is a commonly used algorithm for searching for a specific value in a sorted array. However, what if we want to find the closest value\",\"breadcrumb\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/namso-gen.co\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to modify binary search to find closest value?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#website\",\"url\":\"https:\/\/namso-gen.co\/blog\/\",\"name\":\"Namso Gen Blog - Free Credit Card Generator [100% Valid]\",\"description\":\"In Namso gen blog you can get many tips regarding to Credit cards, VCC, Credit card security etc. You can generate credit cards by using Namso-gen.co\",\"publisher\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/namso-gen.co\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#organization\",\"name\":\"Namso Gen Blog - Free Credit Card Generator [100% Valid]\",\"url\":\"https:\/\/namso-gen.co\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png\",\"contentUrl\":\"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png\",\"width\":500,\"height\":164,\"caption\":\"Namso Gen Blog - Free Credit Card Generator [100% Valid]\"},\"image\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/synchronyfinancial\",\"https:\/\/twitter.com\/synchrony\",\"https:\/\/www.youtube.com\/synchronyfinancial\",\"https:\/\/www.instagram.com\/synchrony\",\"https:\/\/www.linkedin.com\/company\/synchrony-financial\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/4938663f06a1cff2dff5c1af38d151c0\",\"name\":\"Jamie Steele\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"caption\":\"Jamie Steele\"},\"description\":\"Guest author Jamie Steele has meticulously crafted and revised this article to the best of their knowledge and understanding. Readers are strongly advised to exercise caution, verify information independently, and rely on their own judgment when considering the information provided. Read more articles on Namso Gen here.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to modify binary search to find closest value?","description":"Binary search is a commonly used algorithm for searching for a specific value in a sorted array. However, what if we want to find the closest value","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:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/","og_locale":"en_US","og_type":"article","og_title":"How to modify binary search to find closest value?","og_description":"Binary search is a commonly used algorithm for searching for a specific value in a sorted array. However, what if we want to find the closest value","og_url":"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/","og_site_name":"Namso Gen Blog - Free Credit Card Generator [100% Valid]","article_publisher":"https:\/\/www.facebook.com\/synchronyfinancial","article_published_time":"2024-07-07T01:57:06+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2024\/03\/faq.png","type":"image\/png"}],"author":"Jamie Steele","twitter_card":"summary_large_image","twitter_creator":"@synchrony","twitter_site":"@synchrony","twitter_misc":{"Written by":"Jamie Steele","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/#article","isPartOf":{"@id":"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/"},"author":{"name":"Jamie Steele","@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/4938663f06a1cff2dff5c1af38d151c0"},"headline":"How to modify binary search to find closest value?","datePublished":"2024-07-07T01:57:06+00:00","dateModified":"2024-07-07T01:57:06+00:00","mainEntityOfPage":{"@id":"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/"},"wordCount":188,"commentCount":0,"publisher":{"@id":"https:\/\/namso-gen.co\/blog\/#organization"},"articleSection":["Learn"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/","url":"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/","name":"How to modify binary search to find closest value?","isPartOf":{"@id":"https:\/\/namso-gen.co\/blog\/#website"},"datePublished":"2024-07-07T01:57:06+00:00","dateModified":"2024-07-07T01:57:06+00:00","description":"Binary search is a commonly used algorithm for searching for a specific value in a sorted array. However, what if we want to find the closest value","breadcrumb":{"@id":"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/namso-gen.co\/blog\/how-to-modify-binary-search-to-find-closest-value\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/namso-gen.co\/blog\/"},{"@type":"ListItem","position":2,"name":"How to modify binary search to find closest value?"}]},{"@type":"WebSite","@id":"https:\/\/namso-gen.co\/blog\/#website","url":"https:\/\/namso-gen.co\/blog\/","name":"Namso Gen Blog - Free Credit Card Generator [100% Valid]","description":"In Namso gen blog you can get many tips regarding to Credit cards, VCC, Credit card security etc. You can generate credit cards by using Namso-gen.co","publisher":{"@id":"https:\/\/namso-gen.co\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/namso-gen.co\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/namso-gen.co\/blog\/#organization","name":"Namso Gen Blog - Free Credit Card Generator [100% Valid]","url":"https:\/\/namso-gen.co\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png","contentUrl":"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png","width":500,"height":164,"caption":"Namso Gen Blog - Free Credit Card Generator [100% Valid]"},"image":{"@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/synchronyfinancial","https:\/\/twitter.com\/synchrony","https:\/\/www.youtube.com\/synchronyfinancial","https:\/\/www.instagram.com\/synchrony","https:\/\/www.linkedin.com\/company\/synchrony-financial"]},{"@type":"Person","@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/4938663f06a1cff2dff5c1af38d151c0","name":"Jamie Steele","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","caption":"Jamie Steele"},"description":"Guest author Jamie Steele has meticulously crafted and revised this article to the best of their knowledge and understanding. Readers are strongly advised to exercise caution, verify information independently, and rely on their own judgment when considering the information provided. Read more articles on Namso Gen here."}]}},"_links":{"self":[{"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/posts\/261586","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/users\/66"}],"replies":[{"embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/comments?post=261586"}],"version-history":[{"count":0,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/posts\/261586\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/media\/107420"}],"wp:attachment":[{"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/media?parent=261586"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/categories?post=261586"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/tags?post=261586"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}