西安电子科技大学:《数据结构与算法分析 Data Structure and Algorithm Analysis》课程教学资源(PPT课件讲稿)05 Disjoint Set ADT

The Disjoint Set ADT In this part,we describe an efficient data structure to solve the eguivalence problem. ■ Relations:A relation R is defined on a set Sif for every pair of elements (a,b),a,bes,a Rb is either true or false.If a R b is true,then we say that a is related to 6
The Disjoint Set ADT ◼ In this part, we describe an efficient data structure to solve the equivalence problem. ◼ Relations: A relation R is defined on a set S if for every pair of elements (a, b), a, bS, a R b is either true or false. If a R b is true, then we say that a is related to b

The Disjoint Set ADT Equivalence Relations:An equivalence relation is a relation R that satisfies three properties: Reflexive:a R a,for all aeS; Symmetric:a R b if and only if b R a; Transitive:a R b and b R cimplies that a R c The relationship is not an equivalence relationship. Two cities are related if they are in the same country.This relation is an equivalence relation if all the roads are two-way
The Disjoint Set ADT ◼ Equivalence Relations: An equivalence relation is a relation R that satisfies three properties: ✓ Reflexive: a R a, for all aS; ✓ Symmetric: a R b if and only if b R a; ✓ Transitive: a R b and b R c implies that a R c; ◼ The relationship is not an equivalence relationship. ◼ Two cities are related if they are in the same country. This relation is an equivalence relation if all the roads are two-way

The Disjoint Set ADT Given an equivalence relation ~the natural problem is to decide,for any a and b,if ab. The equivalence class of an element aeSis the subset of S that contains all the elements that are related to a. Notice that the equivalence classes from a partition of S:Every member of S appears in exactly one equivalence class
The Disjoint Set ADT ◼ Given an equivalence relation ~, the natural problem is to decide, for any a and b, if a~b. ◼ The equivalence class of an element aS is the subset of S that contains all the elements that are related to a. ◼ Notice that the equivalence classes from a partition of S: Every member of S appears in exactly one equivalence class

The Disjoint Set ADT To decide if ab,we need only to check whether a and b are in the same equivalence class.This provides our strategy to solve the equivalence problem. The input is initially a collection of Nsets,each with one element.Each set has a different element. There are two permissible operations
The Disjoint Set ADT ◼ To decide if a~b, we need only to check whether a and b are in the same equivalence class. This provides our strategy to solve the equivalence problem. ◼ The input is initially a collection of N sets, each with one element. Each set has a different element. ◼ There are two permissible operations

The Disjoint Set ADT The first is Find,which returns the name of the set (that is,the equivalence class)containing a given element. The second operation adds relations.If we want to add the relation a~b,then we first see if a and b are already related.This is done by performing Findson both a and b and checking whether they are in the same equivalence class. If they are not,then we apply Union.This operation merges the two equivalence classes containing a and b into a new equivalence class
The Disjoint Set ADT ◼ The first is Find, which returns the name of the set (that is, the equivalence class) containing a given element. ◼ The second operation adds relations. If we want to add the relation a~b, then ✓ we first see if a and b are already related. This is done by performing Finds on both a and b and checking whether they are in the same equivalence class. ✓ If they are not, then we apply Union. This operation merges the two equivalence classes containing a and b into a new equivalence class

The Disjoint Set ADT Notice that we do not perform any operations comparing the relative values of elements,but merely require knowledge of their location. For this reason,we can assume that all the elements have been numbered sequentially from 1 to M.Thus,initially we have s=for /1 through M
The Disjoint Set ADT ◼ Notice that we do not perform any operations comparing the relative values of elements, but merely require knowledge of their location. ◼ For this reason, we can assume that all the elements have been numbered sequentially from 1 to N. Thus, initially we have Si={i} for i=1 through N

The Disjoint Set ADT Our second observation is that the name of the set returned by Find is actually fairly arbitrary.All that really matters is that Find(a)=Find(b)if and only if a and b are in the same set. Thus,one idea might be to use a tree to represent each set,since each element in a tree has the same root.Therefore,the root can be used to name the set
The Disjoint Set ADT ◼ Our second observation is that the name of the set returned by Find is actually fairly arbitrary. All that really matters is that Find(a)=Find(b) if and only if a and b are in the same set. ◼ Thus, one idea might be to use a tree to represent each set, since each element in a tree has the same root. Therefore, the root can be used to name the set

The Disjoint Set ADT We will represent each set by a tree.Initially,each set contains one element. ■ The representation of the trees is easy,because the only information we will need is a parent pointer. Since only the name of the parent is required,we can assume that this tree is stored implicitly in an array: each entry Ai]in the array represents the parent of element i.If /is a root,then Ail=0
The Disjoint Set ADT ◼ We will represent each set by a tree. Initially, each set contains one element. ◼ The representation of the trees is easy, because the only information we will need is a parent pointer. ◼ Since only the name of the parent is required, we can assume that this tree is stored implicitly in an array: each entry P[i] in the array represents the parent of element i. If i is a root, then P[i]=0

The Disjoint Set ADT ooo56086 Eight elements,initially in different sets 00000000 12345678
The Disjoint Set ADT 1 2 3 4 5 6 7 8 Eight elements, initially in different sets 0 0 0 0 0 0 0 1 2 3 4 5 6 7 0 8

The Disjoint Set ADT To perform a Union of two sets,we merge the two trees by making the root pointer of one node point to the root node of the other tree.We have adopted the convention that the new root after the Union(X,y)is X. After Union(5,6) (4 00o00500 12345678
The Disjoint Set ADT ◼ To perform a Union of two sets, we merge the two trees by making the root pointer of one node point to the root node of the other tree. We have adopted the convention that the new root after the Union(X, Y) is X. 1 2 3 4 5 6 7 8 After Union(5,6) 0 0 0 0 5 0 0 1 2 3 4 5 6 7 0 8
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 西安电子科技大学:《数据结构与算法分析 Data Structure and Algorithm Analysis》课程教学资源(PPT课件讲稿)04 Priority Queues(Heaps).ppt
- 西安电子科技大学:《数据结构与算法分析 Data Structure and Algorithm Analysis》课程教学资源(PPT课件讲稿)03 Hashing.ppt
- 西安电子科技大学:《数据结构与算法分析 Data Structure and Algorithm Analysis》课程教学资源(PPT课件讲稿)08 Algorithm Design Techniques.ppt
- 西安电子科技大学:《数据结构与算法分析 Data Structure and Algorithm Analysis》课程教学资源(PPT课件讲稿)07 Graph Algorithms.ppt
- 西安电子科技大学:《数据结构与算法分析 Data Structure and Algorithm Analysis》课程教学资源(PPT课件讲稿)06 Algorithm Analysis and Sorting.ppt
- 西安电子科技大学:《算法设计技术 Algorithms Design Techniques》课程教学资源(PPT课件讲稿)Iterative Improvement for Domain-Specific Problems(Chapter 16 Network Flow Chapter 17 Matching).ppt
- 西安电子科技大学:《算法设计技术 Algorithms Design Techniques》课程教学资源(PPT课件讲稿)Coping with Hardness(Chapter 13 Backtracking Chapter 14 Randomized Algorithms Chapter 15 Approximation Algorithms).ppt
- 西安电子科技大学:《算法设计技术 Algorithms Design Techniques》课程教学资源(PPT课件讲稿)First-Cut Techniques(Chapter 8 The Greedy Approach Chapter 9 Graph Traversal).ppt
- 西安电子科技大学:《算法设计技术 Algorithms Design Techniques》课程教学资源(PPT课件讲稿)Techniques Based on Recursion(Chapter 5 Induction Chapter 6 Divide and Conquer Chapter 7 Dynamic Programming).ppt
- 西安电子科技大学:《算法设计技术 Algorithms Design Techniques》课程教学资源(PPT课件讲稿)Chapter 01 Basic Concepts in Algorithmic Analysis(主讲:刘静).ppt
- 《计算机基础》课程教学资源(参考论文)Motif Difficulty(MD):A Predictive Measure of Problem Difficulty for Evolutionary Algorithms using Network Motifs.pdf
- 《计算机基础》课程教学资源(参考论文)An Organizational Evolutionary Algorithm for Numerical Optimization.pdf
- 《计算机基础》课程教学资源(参考论文)A Multiagent Evolutionary Algorithm for Constraint Satisfaction Problems.pdf
- 《计算机基础》课程教学资源(参考论文)Comments on “the 1993 DIMACS Graph Coloring Challenge” and “Energy Function-Based Approaches to Graph Coloring”.pdf
- 《计算机基础》课程教学资源(参考论文)Moving Block Sequence and Organizational Evolutionary Algorithm for General Floorplanning with Arbitrarily Shaped Rectilinear Blocks.pdf
- 《计算机基础》课程教学资源(参考论文)A Multi-Agent Genetic Algorithm for Global Numerical Optimization.pdf
- 《计算机基础》课程教学资源(参考论文)An Organizational Coevolutionary Algorithm for Classification.pdf
- 西安电子科技大学:《大学计算机基础 Fundamentals of Computers》课程教学资源(PPT课件讲稿)Chapter 12,14,15 Lecture_Computer Software(2/2).ppt
- 西安电子科技大学:《大学计算机基础 Fundamentals of Computers》课程教学资源(PPT课件讲稿)Chapter 10-11 Lecture_Computer Software(1/2).ppt
- 西安电子科技大学:《大学计算机基础 Fundamentals of Computers》课程教学资源(PPT课件讲稿)Chapter 1-5 Lecture_Computer Hardware(主讲:刘静).ppt
- 西安电子科技大学:《数据结构与算法分析 Data Structure and Algorithm Analysis》课程教学资源(PPT课件讲稿)02 Trees(主讲:刘静).ppt
- 西安电子科技大学:《数据结构与算法分析 Data Structure and Algorithm Analysis》课程教学资源(PPT课件讲稿)01 Lists, Stacks, and Queues.ppt
- 中国科学技术大学:Robust Speech Recognition with Speech Enhanced Deep Neural Networks.pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(课件讲义)第九章 机器无关的优化.pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(课件讲义)第八章 代码生成.pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(课件讲义)第七章 运行时刻环境.pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(课件讲义)第六章 中间代码生成.pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(课件讲义)第五章 语法制导的翻译.pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(课件讲义)第四章 语法分析.pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(课件讲义)第三章 词法分析.pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(课件讲义)第一章 引论(许畅).pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(课件讲义)编译课程复习(许畅).pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(实验讲义)实验一 词法分析与语法分析.pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(实验讲义)实验二 语义分析.pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(实验讲义)实验三 中间代码生成.pdf
- 南京大学:《编译原理 Principles and Techniques of Compilers》课程教学电子教案(实验讲义)实验四 目标代码生成.pdf
- 《编译原理 Principles and Techniques of Compilers》课程教学资源(学习资料)Assemblers,Linkers,and the SPIM Simulator(MIPS32 and SPIM).pdf
- 南京大学:《软件工程导论 Introduction to Software Engineering Research》课程教学电子教案(课件讲义)04 Conduct Rigorous and Scientific Research(Experiment Design in Software Engineering Research).pdf
- 华中科技大学:《面向对象程序设计》课程教学资源(课件讲稿)课程简介(李瑞轩).pdf
- 华中科技大学:《面向对象程序设计》课程教学资源(课件讲稿)第1章 引论(李瑞轩).pdf