《算法入门》(英文版)Lecture 20 Prof. Erik Demaine

Introduction to algorithms 6.046J/18,401J/SMA5503 Lecture 20 Prof erik demaine
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 20 Prof. Erik Demaine

Disjoint-set data structure (Union-Find) Problem: Maintain a dynamic collection of pairwise-disjoint sets= {S1, S2, .. S } Each set S; has one element distinguished as the representative element, rep[]. Must support 3 operations: MAKE-SET(x): adds new set {x} to S with rep[{x}]= for any x S; for all). UNION(x, y): replaces sets S, with y in for any x, y in distinct sets,. FIND-SET(x): returns representative rep[Sx. of set S, containing element x. 2001 by Erik D. Demaine Introduction to Algorithms Day33L20.2
© 2001 by Erik D. Demaine Introduction to Algorithms Day 33 L20.2 Disjoint-set data structure (Union-Find) Problem: Maintain a dynamic collection of pairwise-disjoint sets S = { S 1, S2, …, Sr }. Each set Si has one element distinguished as the representative element, rep [ Si ]. Must support 3 operations: • MAKE-SET (x ): adds new set { x } to S with rep[{ x}] = x (for any x ∉ Si for all i). • UNION (x, y ): replaces sets Sx, Sy with Sx ∪ Sy in S for any x, y in distinct sets Sx, Sy . • FIND-SET (x ): returns representative rep [ Sx ] of set Sx containing element x

Simple linked -list solution Store each set s; = 2…2k}asan( unordered doubly linked list. Define representative element reps,i to be the front of the list,x x十 re MAKE-SET(x) initializes x as a lone node. -o() FIND-SET(x) walks left in the list containing x until it reaches the front of the list ⊙(n) UNION(, y) concatenates the lists containing x and y, leaving rep. as FIND-setx -(n) c 2001 by erik D. Demaine Introduction to Agorithms Day33L20.3
© 2001 by Erik D. Demaine Introduction to Algorithms Day 33 L20.3 Simple linked-list solution Store each set Si = {x1, x2, …, xk} as an (unordered) doubly linked list. Define representative element rep[Si] to be the front of the list, x1. Si : x … 1 x2 xk rep[Si] • MAKE-SET(x) initializes x as a lone node. • FIND-SET(x) walks left in the list containing x until it reaches the front of the list. • UNION(x, y) concatenates the lists containing x and y, leaving rep. as FIND-SET[x]. – Θ(1) – Θ(n) – Θ(n)

Simple balanced -tree solution Store each set si=(x1, x2,.,xk as a balanced tree (ignoring keys). Define representative element replsii to be the root of the tree MAKE-SET(x) initializes x S={x12x2,x32x42x5} as a lone node. -O(1) rep[Six FIND-SET() walks up the tree containing x until it reaches the root. -o(g n UNION(, y) concatenates the trees containing x and changing rep o(g n) c 2001 by erik D. Demaine Introduction to Agorithms Day33L20.4
© 2001 by Erik D. Demaine Introduction to Algorithms Day 33 L20.4 Simple balanced-tree solution Store each set Si = {x1, x2, …, xk} as a balanced tree (ignoring keys). Define representative element rep[Si] to be the root of the tree. x1 x4 x3 x2 x5 • MAKE-SET(x) initializes x as a lone node. • FIND-SET(x) walks up the tree containing x until it reaches the root. • UNION(x, y) concatenates the trees containing x and y, changing rep. Si = {x1, x2, x3, x4, x5} rep[Si] – Θ(1) – Θ(lg n) – Θ(lg n)

Plan of attack We will build a simple disjoint-union data structure that, in an amortized sense performs significantly better than o(g n) per op, even better than o(glg n),o( Glg n), etc, but not quite O(1) To reach this goal, we will introduce two key tricks Each trick converts a trivial o(n) solution into a simple o(g n) amortized solution. Together, the two tricks yield a much better solution First trick arises in an augmented linked list Second trick arises in a tree structure c 2001 by erik D. Demaine Introduction to Agorithms Day33L20.5
© 2001 by Erik D. Demaine Introduction to Algorithms Day 33 L20.5 Plan of attack We will build a simple disjoint-union data structure that, in an amortized sense, performs significantly better than Θ(lg n) per op., even better than Θ(lg lg n), Θ(lg lg lg n), etc., but not quite Θ(1). To reach this goal, we will introduce two key tricks. Each trick converts a trivial Θ(n) solution into a simple Θ(lg n) amortized solution. Together, the two tricks yield a much better solution. First trick arises in an augmented linked list. Second trick arises in a tree structure

Augmented linked-list solution Store set S=x1,x2,.,xk as unordered doubly linked list. Define reps i to be front of list, x Each element x, also stores pointer rep[x, to reps rep S:[[…口 reps FiND-SEtX returns repx ⊙(1) UNION(x, y) concatenates the lists containing x and y, and updates the rep pointers for all elements in the list containing y ⊙(n) c 2001 by erik D. Demaine Introduction to Agorithms Day33L20.6
© 2001 by Erik D. Demaine Introduction to Algorithms Day 33 L20.6 Augmented linked-list solution Si : x … 1 x2 xk rep[Si] rep Store set Si = {x1, x2, …, xk} as unordered doubly linked list. Define rep[Si] to be front of list, x1. Each element xj also stores pointer rep[xj] to rep[Si]. • FIND-SET(x) returns rep[x]. • UNION(x, y) concatenates the lists containing x and y, and updates the rep pointers for all elements in the list containing y. – Θ(n) – Θ(1)

Example of augmented linked-list solution Each element x, stores pointer reply] to rep[si UNION(x, y) concatenates the lists containing x and y and updates the rep pointers for all elements in the list containing y reD rep P [十 reps, c 2001 by erik D. Demaine Introduction to Ago orns Day33L20.7
© 2001 by Erik D. Demaine Introduction to Algorithms Day 33 L20.7 Example of augmented linked-list solution Sx : x1 x2 rep[Sx] rep Each element xj stores pointer rep[xj] to rep[Si]. UNION(x, y) • concatenates the lists containing x and y, and • updates the rep pointers for all elements in the list containing y. Sy : y1 y2 y3 rep[Sy] rep

Example of augmented linked-list solution Each element x, stores pointer reply] to rep[si UNION(x, y) concatenates the lists containing x and y and updates the rep pointers for all elements in the list containing y reD 囗口s rep P 凹[ reps, c 2001 by erik D. Demaine Introduction to Ago orns Day33L20.8
© 2001 by Erik D. Demaine Introduction to Algorithms Day 33 L20.8 Example of augmented linked-list solution Sx ∪ Sy : x1 x2 rep[Sx] rep Each element xj stores pointer rep[xj] to rep[Si]. UNION(x, y) • concatenates the lists containing x and y, and • updates the rep pointers for all elements in the list containing y. y1 y2 y3 rep[Sy] rep

Example of augmented linked-list solution Each element x, stores pointer reply] to rep[si UNION(x, y) concatenates the lists containing x and y and updates the rep pointers for all elements in the list containing y reD 囗口s repS, 凹[[口 c 2001 by erik D. Demaine Introduction to Ago orns Day33L20.9
© 2001 by Erik D. Demaine Introduction to Algorithms Day 33 L20.9 Example of augmented linked-list solution Sx ∪ Sy : x1 x2 rep[Sx ∪ Sy] Each element xj stores pointer rep[xj] to rep[Si]. UNION(x, y) • concatenates the lists containing x and y, and • updates the rep pointers for all elements in the list containing y. y1 y2 y3 rep

Alternative concatenation UNION(X, y)could instead concatenate the lists containing y and x, and update the rep pointers for all elements in the list containing x rep :x十 rep reps s:[ reps, c 2001 by erik D. Demaine Introduction to Agorithms Day33L20.10
© 2001 by Erik D. Demaine Introduction to Algorithms Day 33 L20.10 Alternative concatenation Sx : x1 x2 rep[Sy] UNION(x, y) could instead • concatenate the lists containing y and x, and • update the rep pointers for all elements in the list containing x. y1 y2 y3 rep rep[Sx] rep Sy :
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 《算法入门》(英文版)Lecture 19 Prof. Erik Demaine.pdf
- 《算法入门》(英文版)Lecture 18 Prof. Erik Demaine.pdf
- 《算法入门》(英文版)Lecture 17 Prof. Erik Demaine.pdf
- 《算法入门》(英文版)Lecture 16 Prof. Charles E. Leiserson.pdf
- 《算法入门》(英文版)Lecture 15 Prof. Charles E. Leiserson.pdf
- 《算法入门》(英文版)Lecture 14 Prof. Charles E. Leiserson.pdf
- 《算法入门》(英文版)Lecture 13 Prof. Erik Demaine.pdf
- 《算法入门》(英文版)Lecture 12 Prof. Erik Demaine.pdf
- 《算法入门》(英文版)Lecture 11 Prof. Erik Demaine.pdf
- 《算法入门》(英文版)Lecture 10 Prof. Erik Demaine.pdf
- 《算法入门》(英文版)Lecture 9 Prof. Charles E. Leiserson.pdf
- 《算法入门》(英文版)Lecture 8 Prof. Charles E. Leiserson.pdf
- 《算法入门》(英文版)Lecture 7 Prof. Charles E. Leiserson.pdf
- 《算法入门》(英文版)Lecture 6 Prof. Erik Demaine.pdf
- 《算法入门》(英文版)Lecture 5 Prof. Erik Demaine.pdf
- 《算法入门》(英文版)Lecture 4 Prof. Charles E. Leiserson.pdf
- 《算法入门》(英文版)Lecture 3 Prof. Erik Demaine.pdf
- 《算法入门》(英文版)Lecture 2 Prof. Erik Demaine.pdf
- 《算法入门》(英文版)Lecture 1 Prof. Charles E. Leiserson.pdf
- 《城市设计实例—步行商业》杭州湖滨旅游商贸特色街区.ppt
- 《算法入门》(英文版)Lecture 21 Prof. Charles E. Leiserson.pdf
- 《算法入门》(英文版)Lecture 22 Prof. Charles E. Leiserson.pdf
- 《算法入门》(英文版)Lecture 23 Prof. Charles E. Leiserson.pdf
- 《加快林业建设—缓解气候变化》讲义.ppt
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)Alkene/Alkyne Hydrozirconation.pdf
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)Olefin functionalization via metal promoted Nu attack.pdf
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)Murai has described the synthesis.pdf
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)π-Trimethylenemethane cyclization.pdf
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)Functionalization of terminal olefins.pdf
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)Course Overviewweek1.pdf
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)Ligand Exchange Mechanisms.pdf
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)C-C Bond Formation.pdf
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)Sonogashira:in situ, metal assisted deprotonation.pdf
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)Wilkinson's original.pdf
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)Substrate-directed hydrogenations with.pdf
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)Monohydride catalysts.pdf
- 哈佛大学:《有机过渡金属化学》英文教学资源(讲义)The Holy Grail of Catalysis.pdf
- 《建筑施工图的绘制》第五讲 建筑图纸的表达.ppt
- 21 世纪高职高专会计专业主干课程:《管理会计》PPT教学课件(共十章).ppt
- 西安电子科技大学:《多媒体通信技术》课程电子教案(PPT教学课件)第1章 多媒体通信技术概论.ppt