Divide and Conquer Algorithms

Definition: 

A divide and conquer algorithm is a strategy of solving a large problem by:

1. breaking the problem into smaller sub-problems

2. solving the sub-problems, and

3. combining them to get the desired output

To use the divide and conquer algorithm, recursion is very importance. 

Time Complexity

The complexity of the divide and conquer algorithm is calculated using the master theorem

Divide and Conquer Vs. Dynamic Approach

- The divide and conquer approach divides a problem into smaller subproblems; these subproblems are further solved recursively. The result of each subproblem is not stored for future reference, whereas, in a dynamic approach, the result of each subproblem is stored for future reference.

- Use the divide and conquer approach when the same subproblem is not solved multiple times. - - Use the dynamic approach when the result of a subproblem is to be used multiple times in the future.

Example: Fibonacci

//Divide and Conquer approach:
fib(n)
    If n < 2, return 1
    Else , return f(n - 1) + f(n -2)
//Dynamic approach:
mem = []
fib(n)
    If n in mem: return mem[n] 
    else,     
        If n < 2, f = 1
        else , f = f(n - 1) + f(n -2)
        mem[n] = f
        return f
//In a dynamic approach, mem stores the result of each subproblem. 

Advantages of Divide and Conquer Algorithm

Application

1. Quick Sort

2. Merge Sort

3. Binary Sort

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值