{"id":1408,"date":"2016-08-04T08:49:22","date_gmt":"2016-08-04T08:49:22","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=1408"},"modified":"2016-08-04T08:49:22","modified_gmt":"2016-08-04T08:49:22","slug":"search","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/search\/","title":{"rendered":"Search"},"content":{"rendered":"<p>Binary search is faster then linear search if the collection is sorted and does not contains duplicated Values<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic static void BinarySearch(int searchVal)\r\n{\r\n  int lowerIndex = 0;\r\n  int higherIndex = arrNumbers.length;\r\n  int searchIndex = 0;\r\n  \r\n  while(lowerIndex &lt; higherIndex)\r\n  {\r\n\tint middleIndex = (lowerIndex + higherIndex)\/2;\r\n\t\r\n\tif(searchVal &lt; arrNumbers&#x5B;middleIndex])\r\n\t{\r\n\t\thigherIndex = middleIndex + 1; \r\n\t}\r\n\telse if(searchVal &gt; arrNumbers&#x5B;middleIndex])\r\n\t{\r\n\t\tlowerIndex = middleIndex - 1;\r\n\t}  \r\n\telse\r\n\t{\r\n\t\tsearchIndex = middleIndex+1;\t\t\t\r\n\t\tSystem.out.println(&quot;The element is Found at Index &quot; + searchIndex);\r\n\t\treturn;\r\n\t}\r\n  }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Binary search is faster then linear search if the collection is sorted and does not contains duplicated Values public static void BinarySearch(int searchVal) { int lowerIndex = 0; int higherIndex = arrNumbers.length; int searchIndex = 0; while(lowerIndex &lt; higherIndex) { int middleIndex = (lowerIndex + higherIndex)\/2; if(searchVal &lt; arrNumbers&#x5B;middleIndex]) { higherIndex = middleIndex + 1;&hellip; <a href=\"https:\/\/codethataint.com\/blog\/search\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[185],"tags":[],"class_list":["post-1408","post","type-post","status-publish","format-standard","hentry","category-search"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1408","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=1408"}],"version-history":[{"count":1,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1408\/revisions"}],"predecessor-version":[{"id":1409,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1408\/revisions\/1409"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=1408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=1408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=1408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}