divide and conquer approach code example
Example 1: Divide and conquer algorithm
DAC(a, i, j)
{
if(small(a, i, j))
return(Solution(a, i, j))
else
m = divide(a, i, j) // f1(n)
b = DAC(a, i, mid) // T(n/2)
c = DAC(a, mid+1, j) // T(n/2)
d = combine(b, c) // f2(n)
return(d)
}
Example 2: divide and conquer algorithm
divide and conquer:
split the problem into sub problems,
solve each sub problem to eventually solve the main problem