Search code examples
recursiondivide-and-conquer

Compare divide and conquer with recursion


When we are talking about divide and conquer ,we always use recursion .I've already known divide and conquer is a technique of algorithm design,but I got one question:

Are all divide and conquer algorithms recursion ,or put it another way ,is the thought of divide and conquer employed in all recursions?

I'm confused .


Solution

  • If I understand your problem correctly.. Are all Divide & Conquer algorithms recursive in nature? Yes!

    By definition

    There are three steps to applying Divide and Conquer algorithm in practice:

    • Divide the problem into one or more subproblems.
    • Conquer subproblems by solving them recursively. If the subproblem sizes are small enough, however, just solve the subproblems in a straightforward manner.
    • Combine the solutions to the subproblems into the solution for the original problem.

    But if you are concerned with the implementation part.. then recursion(though more elegant and simple) is not the only way.

    Binary Search is a well-known instance of divide-and-conquer paradigm and here is the Iterative implementation of the algorithm.

    //binary search for x, in array A[1 .. N]
    
    min := 1;
    max := N;
    repeat
      mid := (min+max) div 2;
      if x > A[mid] then
        min := mid + 1;
      else
        max := mid - 1;
    until (A[mid] = x) or (min > max);