树中的最大独立集。审查算法,需要证明
伪代码:
void recursive('k'){ // 'k' and 'i' vertices
sumA = 0;
sumB = 0;
for each non visited 'i' neighbor do{
recursive('i');
sumA = sumA + b['i'];
sumB = sumB + max(a['i'], b['i']);
}
a['k'] = 1 + sumA;
b['k'] = sumB;
}
void main(){
a = b = 0; //initialize tables with 0 (zeros)
recursive('X'); //let 'X' be an arbitrary root
cout<<max(a['X'], b['X']);
}
需要证明 max(a['X'], b['X']) 是树中最大独立集的基数。 我缺少什么?
先感谢您。
pseudocode:
void recursive('k'){ // 'k' and 'i' vertices
sumA = 0;
sumB = 0;
for each non visited 'i' neighbor do{
recursive('i');
sumA = sumA + b['i'];
sumB = sumB + max(a['i'], b['i']);
}
a['k'] = 1 + sumA;
b['k'] = sumB;
}
void main(){
a = b = 0; //initialize tables with 0 (zeros)
recursive('X'); //let 'X' be an arbitrary root
cout<<max(a['X'], b['X']);
}
need proof that max(a['X'], b['X'])
is the cardinal of the maximum independent set in the tree.
What am I missing ?
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
元素a[i]是以i为根、包含i的子树中最大独立集的大小。
元素b[i]是以i为根且不包含i的子树中最大独立集的大小。
该算法递归地计算这些,然后在根处选择两者中的最大值。
The element a[i] is the size of the maximal independent set in the subtree rooted in i which contains i.
The element b[i] is the size of the maximal independent set in the subtree rooted in i which doesn't contain i.
The algorithm computes these recursively, and then chooses the maximal of the two at the root.