Professional Documents
Culture Documents
atj1) in M. Then we have Ge STi Se SG +e; Suter, so in M we can instead match 2, to t and match x;41 to t; to have a new perfect matching M', which agrees with the algorithm. M’ agrees with the output of the greedy algorithm on the first ¢ | 1 points, contradicting our choice of é. ‘To bound the running time, note that if we simply enumerate all unmatched intervals in each iteration of the for loop, it will take O(n) time to find the unmatched one that ends carlicat. There are n itcrations, s0 the algorithm takes O(n2) time. Tex8.628.375,‘Lo design an optimal solution, we apply @ general techmique that 1s known as Leferred Merge Fmbedding (DMR) hy researchers in the VEST community. It’s a greedy algorithm that works as follows. Let v denote the root, with v! and v" its two children. Let d’ denote the maximum root-to-leal distance over all leaves that are descendants of v’, and let d” denote the mavimum root-ta-leaf distance over alll leaves that are descendants af 1!” Now elf dl > dl", we add d! — dl" to the length of the v-ten” edge and add nothing to the length of the v-to-v! edge. © If a” > d’, we add a” ~ a’ to the length of the v-to-v' edge and add nothing to the length of the v-to-v" edge. ed! =d" we add nothing to the length of either edge helaw ». We now apply this procedure recursively to the subtrees rooted at each of vf and Let T be he complete bimay (rer in Ue problem, We first develop lwo basic facts about the optimal solution, and then use these in an “exchange” argument to prove that the DMI algorithin is optimal {i) Let w be an internal node in T, and let c',€" be the two edges directly below w. Ifa solution adds non-zero length to both e’ and e“, then it 1s not optimal. Proof. Suppose that s' > 0 and 6” > 0 are added to ¢.r and é.» respectively. Let 6 = min(3', 8”), Then the solution which adds 5" 5 and 4" 4 to the lengtho of these edgea must also have zero skew, and uses less total length. m= (ii) Let w be a node in 1’ that is neither the root nor a leaf. Ifa solution increases the length of every path from w to a leaf below w, then the solution is not optimal. Proof. Suppose that 21,...2r¢ are the leaves below w. Consider edges © in the subtree below w with the followmg property: the solution mereases the length of e, and it does not increase the length af any edge an the path from m tae Tet F he the set af all such edges: wwe observe two facts about *. First, for each leaf zr, the first edge on the w=r; path whose Jength has been mcreased must belong to F, (and no other edge on this path can belong to: F); thus there is evactly one edge from Fan every mr; path Serond, |F| > 2, since a path in the left subtree below w shares no edges with a path in the right subtree below w, and yet each contams an edge of £* Toot 2. he the edge entering m from its parent (recall that wig not the raat) Tet & he the minimum amount of length added to any of the edges in I. If we subtract 6 from the length added to each edge in F’, and add 9 to the edge above w, the length of all root-to-leat paths remains the same, and so the tree remaing zernskew Rut we have eubtracted [F|é > 94 from the total length of the tree, and added only 6, so we get a zero skew tree with less total length. We can now prove a somewhat stronger fact than what is asked for. 171 Texl79(1m) ‘The DM algorithm produces the unique optimal solution: Proof. Consider any other solution, and let v be any node of T at which the solution does not add lengths in the way that DME would. We uac the notation from the problem, and assume without loss of generality that d’ > d’. Suppose the solution adds 4’ to the edge (v,v') and 6" to the edge (v,v") 16" 5! =a a", then it must be that 6" > 0 or clse the solution would do the same thing as DME; in this case, by (i) it is not optimal. If 6"—6’ < d’—d’, then the solution will still have to increase the length of the path from v" to each of its leaves in order to make the tree zcro-skew; 90 by (ii) it is not optimal. Similarly, if 5" 4" > d’—d", then the solution will still have to increase the length of the path from v’ to each of its leaves in order to make the tree zero-skew; so by (ii) it is not optimal. m=(a) ‘The graph on nodes v1,..-,15 with edges (v1, U2), (U1, 05): (02s U5), (Us, M4) and (v4, U5) 1m will return 2. carrespanding ta the path af edges (1,1) is such an example ‘The algari and (v2, v5), while the optimum is 3 using the path (v1, v3), (vg, vs) and (va, v5) (b) ‘The idea is to use dynamic programmmg. ‘Lhe simplest version to think of uses the suhproblems OPT(i] for the length of the longest path from 1 ta, One point ta he careful of is that not all nodes uj necessarily have a path from vy to v;. We will use the value ”— for the U1 [i] value i this case. We use U1 (1) =U as the longest path trom vy to uy has 1 edges Long-path(n) Array M(1...n] Ml) =0 For i M- For all edges (j,i) then if Mi) #-co if M7 for which P[k] > Pij). From & onward, it 1s simply the longest Inereasing subsequence that. starts at P[t]; in ather wards, this part of the sequence has length OPT), so including Plj], the full sequence has length 1-+ OPT(k). We have thus Justified the following recurrence. OPT(j)—1 IPT (k). GD) 1 RE pg PTO) ‘The values of OPT can be built up in order of decreasing j, in time O(n—J) for iteration j, leading to a total runing time of O(n). The value we want is OPT(1), and the subsequence itself can be found by tracing back through the array of OPT values. Tex219-570.316