Greedy Algorithms
Greedy Algorithms
1 1
2 3 2 3i
4 5 6 4
3o
5 6
The Problem Statement
• The Tree Vertex Splitting Problem is to identify a
set X V of minimum cardinality for which
d (T / X )
2 3
1 3
2
4 5 6
2 3
1 4
7 9 10
8
Example
1
4 2
2 3
1 3
2
4 5 6
2 3
1 4
7 9 10
8
Let δ = 5.
For each leaf node 5, 7,8, 9, 10 delay is 0.
Computing Delay
• Let C(u) be the children of u.
• Then d(u) is given by
2 3
1 3
2
4 5 6
2 3
1 4
7 9 10
8
d(4) = 4
Since d(4) + w(2,4) = 6 > δ=5, Node 4 has to be split.
Example (after splitting node 4)
1
4 2
2 3
1 3
2
4o 4i 5 6
2 3
1 4
7 9 10
8
Example (after splitting node 4)
1
4 2
2 3
1 3
2
4o 4i 5 6
2 3
1 4
7 9 10
8
d(4) = 0
d(2) = 2
Since d(2) + w(1,2) = 6 > δ=5, Node 2 has to be split.
Example (after splitting node 2)
1
4 2
2i 2o 3
1 3
2
4o 4i 5 6
2 3
1 4
7 9 10
8
Example (after splitting node 2)
1
4 2
2i 2o 3
1 3
2
4o 4i 5 6
2 3
1 4
7 9 10
8
d(6) = 3
Since d(6) + w(3,6) = 6 > δ=5, Node 6 has to be split.
Example (after splitting node 6)
1
4 2
2i 2o 3
1 3
2
6i
4o 4i 5
1 4 6o
2 3
7 8
9 10
Example (after splitting node 6)
1
4 2
2i 2o 3
1 3
2
6i
4o 4i 5
1 4 6o
2 3
7 8
9 10
d(3) = 3
d(1) = 5
No further split is required.
Algorithm
TVS(T, δ)
//Determine and output the nodes to be split
//w() is the weighting function for the edges
{
If ( T ≠ 0) then
{
d[T] = 0;
For each child v of T do
{
TVS(v, δ);
d[T] = max{d[T], d[v] + w(T,v)};
}
If((T is not the root) and
(d[T] + w(parent(T),T) > δ)) then
{
Write(T); d[T] = 0;
}
}
}
• Theorem: Algorithm TVS outputs a minimum cardinality set U such
that d(T/U) ≤δ on any tree T, provided no edge of T has weight > δ.
• Proof:
• Base case. If the tree has only one node, the theorem is true.
• Induction hypothesis. Assume that the theorem is true for all
trees of size n.
• Induction step. Consider a tree T of size n + 1
• – Let U be the set of nodes split by TVS.
• – Let W be a minimum cardinality set such that d(T/W) ≤δ
• – We need to show that |U| ≤ |W|
• – If |U|= 0, the above is indeed true
• Otherwise
• Let x be the first vertex split by TVS
• Let Tx be the subtree rooted at x.
• Let T’ = T - Tx + x (Delete Tx from T except for x)
• W has to have at least one node, y, from Tx
• Let W’ = W – {y}.
• If there exists W* such that |W*| < |W’| and d(T’/W*) ≤δ, then since
d(T/(W*+{x})) ≤δ, W is not minimum cardinality split set for T.
• Thus W’ has to be minimum cardinality split set such that d(T’/W’) ≤δ.
• If TVS is run on tree T’, the set of split nodes output is U – {x}
• – Since T’ has ≤ n nodes, U – {x} is a minimum cardinality set split for T’.
• – This means that |W’| ≥ |U| -1, or |W| ≥ |U|
Reference
• E Horowitz, S Sahni, S. Rajsekaran,
Fundamental of Computer Algorithms , 2nd Ed,
University Press.
• http://www.cis.upenn.edu/~matuszek/cit594-
2005/Lectures/36-greedy.ppt
• http://www.cs.umsl.edu/~sanjiv/classes/
cs5130/lectures/gm.pdf