Why is Binary Search a divide and conquer algorithm?

后端 未结 16 2350
醉话见心
醉话见心 2020-12-14 02:12

I was asked if a Binary Search is a divide and conquer algorithm at an exam. My answer was yes, because you divided the problem into smaller subproblems, until you reached y

16条回答
  •  忘掉有多难
    2020-12-14 02:36

    The informal definition is more or less: Divide the problem into small problems. Then solve them and put them together (conquer). Solving is in fact deciding where to go next (left, right, element found).

    Here a quote from wikipedia:

    The name "divide and conquer" is sometimes applied also to algorithms that reduce each problem to only one subproblem, such as the binary search algorithm for finding a record in a sorted list.

    This states, it's NOT [update: misread this phrase:)] only one part of divide and conquer.

    Update: This article made it clear for me. I was confused since the definition says you have to solve every sub problem. But you solved the sub problem if you know you don't have to keep on searching..

提交回复
热议问题