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:

  1. there candidate set composed of 8 bits of number find.
  2. greedy selection considering in every step significant bit not used yet.
  3. checking if bit can added final solution locally looking @ bit , result assembled far.
  4. if sum not overflow bit makes part of final solution.
  5. the final solution can identified when composed sum equal searched one.

of course no backtracking ever needed perfect greedy algorithm.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -