`
leonzhx
  • 浏览: 793552 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论
阅读更多

1.  MST Review :

    a) Input : Undirected graph G = (V; E), edge costs ce.

    b) Output : Min-cost spanning tree (no cycles, connected).

    c) Assumptions : G is connected

    d) Cut Property : If e is the cheapest edge crossing some cut (A , B), then e belongs to the MST.

 

2.  Kruskal's MST Algorithm

    - Sort edges in order of increasing cost

    (Rename edges 1, 2, ... , m so that c1 < c2 < ... < cm)

    - T = empty set;

    - For i = 1 to m

        - If T U {i} has no cycles

        - Add i to T

    - Return T

 

3.  Correctness of Kruskal's algorithm

    Let T* = output of Kruskal's algorithm on input graph G.

    (1) Clearly T* has no cycles.

    (2) T* is connected. 

        - By Empty Cut Lemma, only need to show that T crosses every cut.

        - Fix a cut (A , B). Since G is connected, so at least one of its edges crosses (A , B).

        - Kruskal will include first edge crossing (A , B) that it sees,

          by Lonely Cut Corollary, cannot create a cycle.

    (3) Every edge of T satisfied by the Cut Property. (Implies T is the MST)

        - Consider iteration where edge (u , v) added to current set T. Since T U { (u, v)} has no cycle, T has no u - v path.

        - exists empty cut (A , B) separating u and v. (As in proof of Empty Cut Lemma)

        - no edges crossing (A , B) were previously considered by Kruskal's algorithm.

        - (u , v) is the first ( hence the cheapest!) edge crossing (A , B).

        - (u , v) justified by the Cut Property.

 

4.  Running Time of Kruskal's Algorithm

    - Sorting edges : O(m log n) , because m = O(n^2) assuming nonparallel edges

    - O(m) iterations and O(n) time to check for cycle (Use BFS or DFS in the graph (V , T) which contains <= n - 1 edges)

    Plan : Data structure for O(1)-time cycle checks ==> overall algorithm has O(m log n) running time.

 

5.  The Union-Find Data Structure

    - Maintain partition of a set of objects.

    - FIND(X): Return name of group that X belongs to.

    - UNION(Ci , Cj ): Fuse groups Ci , Cj into a single one.

 

6.  Applied Union-Find Data Structure in Kruskal's Algorithm:

    - Groups = Connected components w.r.t. chosen edges T.x

    - Adding new edge (u , v) to T <==> Fusing connected components of u, v.

 

7. Union-Find Data Structure Implementation:

    - Maintain one linked structure per connected component of (V , T).

    - Each component has an arbitrary leader vertex. 

    - Invariant : Each vertex points to the leader of its component.

    - Given edge (u , v), can check if u & v already in same component in O(1) time : FIND(u) = FIND(v)

    - Maintain the invariant : When two components merge, have smaller one inherit the leader of the larger one.

    A single vertex v have its leader pointer updated at most O(log n) times over the course of Kruskal's algorithm. Because : Every time v's leader pointer gets updated, population of its component at least doubles ==> Can only happen log2 n times. (the total number of vertices is n)

 

 

分享到:
评论

相关推荐

    MST_Kruskal

    克鲁斯卡尔算法(Kruskal's Algorithm)是求解最小生成树的著名算法之一,由约瑟夫·克鲁斯卡尔在1956年提出。它的主要思想是按照边的权重从小到大进行选择,并在选择过程中避免形成环路。以下是克鲁斯卡尔算法的...

    mst.7z

    常见的MST算法有Kruskal's Algorithm和Prim's Algorithm: 1. **Kruskal's Algorithm**:这个算法基于贪心策略,按边的权重从小到大依次考虑。每次选择一条不形成环的新边加入到当前的生成树中。这个过程持续到所有...

    MST.rar_mst_mst java_最大生成树

    最大生成树的构建通常基于贪心策略,其中最著名的算法之一是Kruskal's Algorithm和Prim's Algorithm。在本例中,描述提到的是一个针对最大生成树的算法实现,但并未明确指出具体使用了哪种算法。Kruskal's Algorithm...

    MinimalSpanningTree.py_最小生成树_源码

    这里我们将深入探讨“Kruskal's Algorithm”,这是求解最小生成树的一种著名算法。 **Kruskal's Algorithm**是由Joseph Kruskal在1956年提出的,它主要针对加权无向图。算法的核心思想是逐步选择边,同时确保不会...

    kruskal最小生成树实现

    std::vector&lt;Edge&gt; kruskalMST(const std::vector&lt;Edge&gt;& edges, int V) { std::vector&lt;Edge&gt; mst; UnionFind uf(V); std::sort(edges.begin(), edges.end()); for (const Edge& edge : edges) { if (!uf.same...

    Kruskal_MATLAb.zip

    Kruskal algorithm implements a given undirected graph. If any two vertices are connected and a tree, then we call it a spanning tree. If it is a undirected graph with weights, then the spanning tree ...

    MST.rar_mst_实现MST

    在本压缩包文件"**MST.rar**"中,包含了两种经典的MST算法的实现:克鲁斯卡尔(Kruskal's Algorithm)和普里姆(Prim's Algorithm)。 首先,我们来看克鲁斯卡尔算法。这是一种基于边的贪心策略,它按照边的权重...

    数据结构英文教学课件:21_Graph_04.pdf

    在本教学课件“21_Graph_04.pdf”中,主要讨论了图(Graph)的一个重要应用——最小生成树(Minimum Spanning Tree,MST),以及求解最小生成树的两种经典算法:Kruskal's Algorithm 和 Prim's Algorithm。...

    kruskal.rar_数据结构_matlab_

    这里提到的"kruskal.rar"压缩包包含了一个使用MATLAB实现的最小生成树算法,特别是Kruskal's Algorithm。 Kruskal's Algorithm是求解加权连通图最小生成树的经典算法之一。最小生成树是一棵包含图中所有顶点的树,...

    KruskalMST:用Java实现的Kruskal最小生成树算法

    项目介绍使用查找无向加权图的(MST)的Java程序。项目特色以最有效的形式使用。 使用通过命令行从输入文件中读取无向加权图。 输入文件包含以下内容(请参见testUF.txt): 零个或多个以'c'开头的注释行后面跟一个...

    kruscal 与Prim算法求解最小生成树

    在`KruskalMST`文件中,可以找到实现克鲁斯卡尔算法的C++代码,包括边的结构体定义、并查集的实现以及算法的主逻辑。 **2. Prim's Algorithm(普里姆算法)** 普里姆算法从一个顶点开始,逐步添加边,使得每次添加...

    python graph algorithm_python_graph_shutszh_zip_algorithm_

    5. Kruskal's算法和Prim's算法:用于计算图的最小生成树,前者基于边的贪心策略,后者基于节点的贪心策略。`nx.kruskal_mst(G)` 和 `nx.prim_mst(G)` 分别对应这两个算法。 6. 强连通分量:找出图中所有相互可达的...

    最小生成树要点和难点具体应用.zip

    - Kruskal's Algorithm:克鲁斯卡尔算法,通过按边的权重升序排序,逐步选择不形成环的边来构造最小生成树。关键在于并查集(Disjoint Set)的数据结构,用于判断添加的边是否会形成环。 - Prim's Algorithm:...

    a算法源码java-Kruskal-Algorithm-Java-Source-code:Kruskal算法Java源代码

    public List&lt;Edge&gt; kruskalMST(Edge[] edges) { //... sort the edges, initialize disjoint set, and build MST... } } ``` 4. **性能分析**: - 时间复杂度:Kruskal算法的时间主要消耗在边的排序上,因此...

    ft-mst

    Kruskal's Algorithm和Prim's Algorithm是两种常用的解决MST问题的算法。 Fibonacci树是一种特殊的树结构,由Fibonacci序列定义,通常用于数据结构和算法的教学与研究。将Fibonacci树与最小生成树相结合,可能是...

    数据结构常用算法c++实现

    Kruskal MST Directed/Undirected graph ops Breadth First Search Depth First Search Dijkstra's algorithm Bellman-Ford algorithm Edmonds-Karp Maximal Flow Push–Relabel algorithm Huffman Coding Word ...

    最小生成树的kruskal算法(c++源码)

    void kruskalMST() { sort(edges.begin(), edges.end()); parent.resize(vertices); // 初始化parent数组 makeSet(); // 初始化集合 for (Edge e : edges) { if (!findCycle(e.u, e.v)) { addEdge(e.u, e.v);...

    数学建模-最小生成树-kruskal算法及各种代码之欧阳道创编.pdf

    克鲁斯卡尔算法(Kruskal's Algorithm)是一种用于寻找加权无向图中的最小生成树的经典算法。它的核心思想是采用贪婪策略,即每次选择当前未被选中且增加后不形成环路的最小权值边。在算法执行过程中,会不断尝试...

    华南理工大学计算机全英班算法设计实验

    (1) Given a undirected Graph G=(V, E) like below, to calculate the minimum spanning tree using Kruskal’s algorithm and Prim’s algorithm. 4. Experimental Requirement 1)The template should be ...

    MST_Parallel

    常见的并行MST算法有Kruskal's算法和Prim's算法的并行版本。下面我们将深入探讨这两种算法及其并行化策略。 1. **Kruskal's Algorithm 并行化** Kruskal's算法是基于贪心策略的,它按边的权重从小到大选择边,并...

Global site tag (gtag.js) - Google Analytics