Can Binary Search be / Is Binary Search a greedy algorithm? -
i'm reading different materials binary search, , it's not clear me greedy binary (which looks me it's not) or, can greedy algorithm specific implementation?
and if can greedy, how make sense? if global optimum obtained selecting local optimum, without reconsidering previous choices, can't guarantee correct results binary search.
consider looking element @ index 100 in 8 bit value range (1-256). binary search progress consider following indices:
- 128 ? big
- 64 ? small
- 64 + 32 ? small
- 64 + 32 + 16 ? big
- 64 + 32 + 8 ? big
- 64 + 32 + 4 ? found
it easy to notice in every step testing significant bit not tested yet , if not overflow result added partial solution until final result found.
so following characteristics of greedy choice can pointed:
- there candidate set composed of 8 bits of number find.
- greedy selection considering in every step significant bit not used yet.
- checking if bit can added final solution locally looking @ bit , result assembled far.
- if sum not overflow bit makes part of final solution.
- the final solution can identified when composed sum equal searched one.
of course no backtracking ever needed perfect greedy algorithm.
Comments
Post a Comment