当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

香港中文大学:《Design and Analysis of Algorithms》课程教学资源(辅导课件)tutorial 03

资源类别:文库,文档格式:PPTX,文档页数:36,文件大小:154.95KB,团购合买
点击下载完整版文档(PPTX)

CSCI 3160 Design and Analysis of Algorithms Tutorial 3 Chengyu Lin ● ●

CSCI 3160 Design and Analysis of Algorithms Tutorial 3 Chengyu Lin

Outline Union-find data structure Minimum spanning tree (MST) ·Kruskal''s algorithm ● ●

Outline • Union-find data structure • Minimum spanning tree (MST) • Kruskal’s algorithm

Union-find A data structure for disjoint sets n number of members,forming disjoint groups Two members are in the same group if and only if they have a common leader 。Operations: o Union:merge two groups o Find:name the leader of the group We do not really care about who the leader is;we only want to tell one group from another ●

Union-find • A data structure for disjoint sets • n = number of members, forming disjoint groups • Two members are in the same group if and only if they have a common leader • Operations: o Union: merge two groups o Find: name the leader of the group • We do not really care about who the leader is; we only want to tell one group from another

Union-find Idea:use a forest (collection of trees) o a group→a free o leader-root of the tree 。Example: o Group 1:Alice,Bob o Group 2:Carol,Dave,Eve Store the height of each tree A 1 D 1 at the root B C E ● ●

Union-find • Idea: use a forest (= collection of trees) o a group → a tree o leader → root of the tree • Example: o Group 1: Alice, Bob o Group 2: Carol, Dave, Eve • Store the height of each tree at the root A B C D E 1 1

Union-find Find:return the root of the group Union:make the leader of one group the boss of the other o Our heuristic:make the root of the shorter tree point to the root of the other tree o If both trees are of the same height h,then the resulting tree has height h+1 ● ●

Union-find • Find: return the root of the group • Union: make the leader of one group the boss of the other o Our heuristic: make the root of the shorter tree point to the root of the other tree o If both trees are of the same height h, then the resulting tree has height h+1

Union-find in action 。Initialize o Everyone is his/her own boss A B D E 0 0 0 0 ●

Union-find in action • Initialize o Everyone is his/her own boss A B C D E 0 0 0 0 0

Union-find in action 。Union(A,B o Find(A)returns A and Find(B)returns B o Make Alice the boss of Bob o Increase the height of the tree A B C D E 1 0 0 0 0 ● ●

Union-find in action • Union(A, B) o Find(A) returns A and Find(B) returns B o Make Alice the boss of Bob o Increase the height of the tree A B C D E 1 0 0 0 0

Union-find in action 。Union(C,D) o Find(C)returns C and Find(D)returns D o Make Carol the boss of Dave o Increase the height of the tree X A B C ← D E 1 0 1 0 ● ●

Union-find in action • Union(C, D) o Find(C) returns C and Find(D) returns D o Make Carol the boss of Dave o Increase the height of the tree A B C D E 1 0 1 0 0

Union-find in action 。Union(B,D】 o Find(B)returns A and Find(D)returns C o Make Alice the boss of Carol o Increase the height of the tree B C D E 2 0 ● ●

Union-find in action • Union(B, D) o Find(B) returns A and Find(D) returns C o Make Alice the boss of Carol o Increase the height of the tree A B C D E 2 0 1 0 0

Your turn 。Find(C? A B C D E 2 0 ●

Your turn • Find(C)? A B C D E 2 0 1 0 0

点击下载完整版文档(PPTX)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共36页,可试读12页,点击继续阅读 ↓↓
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有