贪心算法

if the problem cannot be solved by greedy algorithm then we can try to use depth-first search

1. beneath every greedy algorithm there is almost always a more cumbersome dynamic programming solution.
2. greedy algorithm usually will cast optimization problem into one where we make one choice and produces a subproblem
3. when the problem has properties of optimal substructure and overlapping subproblem then it can be solved by dynamic programming but it also could be solved by greedy algorithm possibly.
4. prove the problem can be solved by greedy algorithm.
  a. Prove the greedy choice is included in the globally optimal solution.
  b. proof method. contradiction method. prove by assuming that the greedy choice is not included in the globally optimal solution. then we can create a solution by replacing the choice with greedy choice and compare the solution with the globally optimal solution. if the solution is better than the globally optimal solution then we prove that greedy choice is included in the optimal solution and the problem can be solved by greedy algorithm.

huffman tree:
optimal substructure: T' is optimal tree for C' = C- {x,y} + {z} where x,y are chars with minimum frequency in C and z is new added character with f[z]=f[x]+f[y]. T obtained from T' by replacing leaf node z with an internal node having x and y as children, represents the optimal tree for C.
greedy choice property: always choose two chars with minimum frequency to merge as  a new char.
method to prove:
contradictory method(greedy algorithm)
induction method (recursion, tree, )

Fibonacci numbers:
F(n)=F(n-1)+F(n-2)
F(1)=1,F(2)=1
theorem: F(n)>F(10+F(2)+....F(n-2)

Proof: F(3)=F(1)+F(2)=2>a1=1
assume that F(n) > F(1)+F(2)+....F(n-2)
then F(n+1)=F(n)+F(n-1)> F(1) + F(2) + ... F(n-2) + F(n-1). proved.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值