Dynamic Programming--notes

Introduction, and WIS in Path Graphs
1. Problem Statement
1.1 Input: A path graph G=(V,E) G = ( V , E ) with nonnegative weight on vertices.
1.2 Desired output: Subset of nonadajacent vertices -an independent set –of maximmum total weight.
Next: Iterate through our algorithm design principles.
Brute-force search: Requires exponential time.
2. A Greedy Approach
2.1 Greedy: Iteratively choose the max-weight vertex not adjacent to any previously chosen vertex.
2.2 A Divide & Conquer Approach
Idea: Recursively compute the max-weight IS of 1st half, ditto(同上) for 2nd half, then combine the solutions.
3. Optimal Substructure
3.1 Critical step: Reason about structure of an optimal solution.
[In terms of optimal solutions of smaller subproblems]
3.2 Motivation: This thought experiment narrows down the set of candidate for the optimal solution; can search through the small set using brute-force-search
Notation: Let SV S ⊆ V be a max-weight independent set(IS). Let vn= v n = last vertex of path.
3.2 A Case Analysis
case1: Suppose vnS v n ∉ S . Let G=G G ′ = G with vn v n deleted.
Note: S S also an IS of G.
Note: S S must be a max-weight IS of G.
Case2: Suppose vnS v n ∈ S .
Note: Previous vertex vn1S v n − 1 ∉ S [by definition of an IS]. Let G′′=G G ″ = G with vn1,vn v n − 1 , v n deleted.
Note: S{vn} S − { v n } is an IS of G′′ G ″ .
Note: Must in fact be a max-weight IS of G′′ G ″ .
4. Toward an Algorithm
Upshot: A max-weight IS must be either
(i) a max-weight IS of G G ′ or.
(ii) vn v n + a max-weight IS of G′′ G ″ .
Corollary: f we knew whether or not vn v n was in the max-weight IS, could recursively compute the max-weight IS of G′′ G ″ and be done.
(Crazy ?) idea: Try both possibilities + return the better solution.
5. The Story So far
5.1 Uprshot: If we know whether or not vn v n is in the max-weight IS, then could recursively compute the max-weight IS of G G ′ or G′′ G ″ and be done.
Proposed algorithm:
Recursively compute S1 = max-weight IS of G G ′ .
Recursively compute S2 = max-weight IS of G′′ G ″ .
Return S1 or S2{vn} S 2 ∪ { v n } ,whichever is better.
Good news: Correct.
Bad news: Exponential time.
5.2 Eliminating Redundancy
Obvious fix: The first time you solve a subproblem cache its solution in a global table for O(1) O ( 1 ) -time lookup later on.[memoization]
Even better: Reformulate as a bottom-up iterative algorithm. Let Gi G i = 1st vertices of G.
Plan: Populate array A left to right with A[i] = value of max-weight IS of Gi G i .
Initialization: A[0] = 0, A[1] = w1 w 1
Main loop: For i=2,3,...,n i = 2 , 3 , . . . , n :
A[i] A [ i ] = max {A[i1],A[i2]+wi} { A [ i − 1 ] , A [ i − 2 ] + w i }
Run time: Obviously O(n) O ( n ) .

A Reconstruction Algorithm
Let A = filled-in array.
Let S=
While i1
− − If A[i1]A[i2]+wi A [ i − 1 ] ≥ A [ i − 2 ] + w i
− − − Decrease i i by 1
Else
− − − − Add vi v i to S S , decrease i by 2
Return S
Claim: Final output S is a max-weight IS of G.
Principles of Dynamic Programming
Fact: Our WIS algorithm is a dynamic programming algorithm!
Key ingredients of dynamix programming:
(1) Identify a small number of subroblems.
[e..g., compute the max-weight IS of Gi G i for i=0,1,,,,n i = 0 , 1 , , , , n ]
(2) Can quickly + correctly solve “larger” subproblems given the solutions to “smaller subproblems”.
[Usually via a recurrence such as A[i] = max {A[i-1], A[i-2] + Wi W i }]
(3) After solving all subproblems, can quickly compute the final solution.
[Usually, it’s just the answer to the “biggest” subproblem].

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值