Binary Search In Detail
▻https://hackernoon.com/binary-search-in-detail-914944a1434a?source=rss----3a8144eabfe3---4
I hope we all have some idea about what binary search is and does. But I’m not going to explain the algorithm step by step, rather I’m going to give an insight into how binary search works and can be used.Check out: geeksforgeeks.org/binary-search if you’re unaware of Binary Search.Given a sorted array, we find the middle-most element and check the element with the key. If the middle-most element is equal to key, we’ve found the key. If the middle-most element is greater than the key, we search on the left half of the middle-most element, else we search on the right half.Here’s an iterative code for Binary Search in Java▻https://medium.com/media/da762279033b5bea50f5497a0df94f81/hrefNotice that in line 6, we useint mid = (low + high) / 2;But calculating mid this way is ineffective. Why? Let’s (...)
#binary-search #programming #java #binary-search-details #algorithms