树中的最大独立集。审查算法,需要证明

发布于 2024-09-29 22:55:24 字数 498 浏览 0 评论 0原文

伪代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

远昼 2024-10-06 22:55:24

元素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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文