Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Binary Search be / Is Binary Search a greedy algorithm?

I'm reading different materials about Binary search, and it's not clear to me is it a greedy binary (which looks to me like it's not) or, CAN it be a greedy algorithm with some specific implementation?

And if it can be greedy, how it make sense? If the global optimum is obtained by selecting the local optimum, without reconsidering previous choices, it can't guarantee correct results for the binary search.

like image 713
Johnny Avatar asked Jul 25 '17 12:07

Johnny


People also ask

Is binary tree example of greedy method?

Binary search tree is an example of : Divide and conquer technique. Greedy algorithm.

Which algorithm is known as greedy algorithm?

Kruskal's algorithm and Prim's algorithm are greedy algorithms for constructing minimum spanning trees of a given connected graph. They always find an optimal solution, which may not be unique in general.

What is the algorithm used for binary search?

Binary search is an efficient algorithm for finding an item from a sorted list of items. It works by repeatedly dividing in half the portion of the list that could contain the item, until you've narrowed down the possible locations to just one.

What are the limitations of the binary search algorithm?

Binary Search Algorithm Disadvantages-It employs recursive approach which requires more stack space. Programming binary search algorithm is error prone and difficult. The interaction of binary search with memory hierarchy i.e. caching is poor.


1 Answers

I guess if you squint at it sideways, binary search is greedy in the sense that you're trying to cut down your search space by as much as you can in each step. It just happens to be a greedy algorithm in a search space with structure making that both efficient, and always likely to find the right answer.

I don't tend to so squint.

That said binary search can be used inside of a traditional greedy algorithm. As an example, a greedy algorithm for a packing problem could ask you to next choose "the largest available item that can still fit". A binary search could be used to find that.

Conversely a greedy algorithm can be used to create a data structure that is well-suited to binary search. See for example https://en.wikipedia.org/wiki/Geometry_of_binary_search_trees#Greedy_algorithm

like image 166
btilly Avatar answered Sep 26 '22 01:09

btilly