60 likes | 69 Views
Largest Independent Set. INDEPENDENT SET : Given a graph G = (V, E) what is the largest subset of vertices S V such that each edge of E has Ex. Is there an independent set of size 6? Yes. Ex. Is there an independent set of size 7? No. independent set.
E N D
Largest Independent Set • INDEPENDENT SET: Given a graph G = (V, E) what is the largest subset of vertices S V such that each edge of E has • Ex. Is there an independent set of size 6? Yes. • Ex. Is there an independent set of size 7? No. independent set
Largest Independent Set • Intractable problem for general graphs • What happens when the graph G is a tree T=(V,E)?
Largest Independent Set • Select a root r for T • For a node v in T, let T(v) be the subtree of T rooted at node v r r v
Dynamic Programming Equation • OPT(v): Largest independent set forT(v) • We are interested in OPT(r)
Algorithm IS(v) If v has no children M[v]=1 ElseIf M[v] is empty SomaFilhos0;SomaNetos1 Para todo filho w de v SomaFilhos <= SomaFilhos+ IS(w) Para todo neto w de v SomaNetos <= SomaNetos+ IS(w) M[v] max(SomaFilhos,SomaNetos) End if Return M[v]
Análise • Cada nó é chamado no máximo duas vezes, uma vez por seu pai e outra por seu avô. • A primeira chamada tem custo proporcional ao número de filhos mais o número de netos e a segunda chamada custa O(1) . Somando o custo de todas as chamadas obtemos O(|V|)