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

1.  Definition: Given an undirected graph G with positive edge weights (connected). A spanning tree of G is a subgraph T that is connected and acyclic. A minimum spanning tree is a min weight spanning tree.

 

2.  Applications:

    --  Dithering

    --  Cluster analysis

    --  Max bottleneck paths.

    --  Real-time face verification.

    --  LDPC codes for error correction.

    --  Image registration with Renyi entropy.

    --  Find road networks in satellite and aerial imagery.

    --  Model locality of particle interactions in turbulent fluid flows.

    --  Reducing data storage in sequencing amino acids in a protein.

    --  Autoconfig protocol for Ethernet bridging to avoid cycles in a network.

    --  Network design (communication, electrical, hydraulic, computer, road).

    --  Approximation algorithms for NP-hard problems (e.g., TSP, Steiner tree).

 

3.  Cut Property:

    --  A cut in a graph is a partition of its vertices into two (nonempty) sets.

    --  A crossing edge connects a vertex in one set with a vertex in the other.

    --  Cut property. Given any cut, the crossing edge of min weight is in the MST.

    --  Pf. Suppose min-weight crossing edge e is not in the MST.

        a)  Adding e to the MST creates a cycle.

        b)  Some other edge f in cycle must be a crossing edge.

        c)  Removing f and adding e is also a spanning tree.

        d)  Since weight of e is less than the weight of f, that spanning tree is lower weight.



 

4.  Greedy MST algorithm:

    --  Start with all edges colored gray.

    --  Find cut with no black crossing edges; color its min-weight edge black.

    --  Repeat until V - 1 edges are colored black.

      Pf.

    --  Any edge colored black is in the MST (via cut property).

    -- Fewer than V - 1 black edges ⇒ cut with no black crossing edges.

    (consider cut whose vertices are one connected component)

 

5.  Weighted edge API

 

public class Edge implements Comparable<Edge>
{
    private final int v, w;
    private final double weight;
    public Edge(int v, int w, double weight)
    {
        this.v = v;
        this.w = w;
        this.weight = weight;
    }
    public int either()
    { return v; }
    public int other(int vertex)
    {
        if (vertex == v) return w;
        else return v;
    }
    public int compareTo(Edge that)
    {
        if (this.weight < that.weight) return -1;
        else if (this.weight > that.weight) return +1;
        else return 0;
    }
    public double weight() {
        return this.weight
    }
    public String toString() {
        return this.v + "-" + this.w;
    }
}

 

 

6.  Edge-weighted graph: adjacency-lists implementation

 

public class EdgeWeightedGraph
{
    private final int V;
    private final Bag<Edge>[] adj;
    
    public EdgeWeightedGraph(int V)
    {
        this.V = V;
        adj = (Bag<Edge>[]) new Bag[V];
        for (int v = 0; v < V; v++)
            adj[v] = new Bag<Edge>();
    }
    public void addEdge(Edge e)
    {
        int v = e.either(), w = e.other(v);
        adj[v].add(e);
        adj[w].add(e);
    }
    public Iterable<Edge> adj(int v)
    {  
        return adj[v]; 
    }
    Iterable<Edge> edges() {}  //all edges in this graph
    int V() {}  //number of vertices
    int E() {}  //number of edges
    String toString() {} //string representation
}

 

7.  Minimum spanning tree API:

 

public class MST {
    public MST(EdgeWeightedGraph G) {} //constructor
    
    public Iterable<Edge> edges() {} //edges in MST
  
    double weight() {} //weight of MST
}

 

 

8.  Kruskal's algorithm:

    -- Algorithm :

        a)  Consider edges in ascending order of weight.

        b)  Add next edge to tree T unless doing so would create a cycle.

    --  Pf. Kruskal's algorithm is a special case of the greedy MST algorithm.

        a)  Suppose Kruskal's algorithm colors the edge e = v–w black.

        b)  Cut = set of vertices connected to v in tree T.

        c)  No crossing edge is black.

        d)  No crossing edge has lower weight.


    --  Implementation challenge :

        Would adding edge v–w to tree T create a cycle? If not, add it.

    --  Efficient solution. Use the union-find data structure:

        a)  Maintain a set for each connected component in T.

        b)  if v and w are in same set, then adding v–w would create a cycle.

        c)  To add v–w to T, merge sets containing v and w.

    --  Java Implementation :

 

public class KruskalMST
{
    private Queue<Edge> mst = new Queue<Edge>();
    public KruskalMST(EdgeWeightedGraph G)
    {
        MinPQ<Edge> pq = new MinPQ<Edge>();
        for (Edge e : G.edges())
            pq.insert(e);
        UF uf = new UF(G.V());
        while (!pq.isEmpty() && mst.size() < G.V()-1)
        {
            Edge e = pq.delMin();
            int v = e.either(), w = e.other(v);
            if (!uf.connected(v, w))
            {
                uf.union(v, w);
                mst.enqueue(e);
             }
        }
    }
    public Iterable<Edge> edges()
    { return mst; }
}

     --  Running Time :

 

    Kruskal's algorithm computes MST in time proportional to E log E (in the worst case).



 

9.  Prim's algorithm:

    -- Algorithm

        a)  Start with vertex 0 and greedily grow tree T.

        b)  Add to T the min weight edge with exactly one endpoint in T.

        c)  Repeat until V - 1 edges.

    --  Pf. Prim's algorithm is a special case of the greedy MST algorithm.

        a)  Suppose edge e = min weight edge connecting a vertex on the tree to a vertex not on the tree.

        b)  Cut = set of vertices connected on tree.

        c)  No crossing edge is black.

        d)  No crossing edge has lower weight.

    --  Challenge. Find the min weight edge with exactly one endpoint in T.

    --  Lazy solution: Maintain a PQ of edges with (at least) one endpoint in T.

        a)  Key = edge; priority = weight of edge.

        b)  Delete-min to determine next edge e = v–w to add to T.

        c)  Disregard if both endpoints v and w are in T.

        d)  Otherwise, let w be the vertex not in T :

            – add to PQ any edge incident to w (assuming other endpoint not in T)

            – add w to T


     --  Java Implementation

 

public class LazyPrimMST
{
    private boolean[] marked; // MST vertices
    private Queue<Edge> mst; // MST edges
    private MinPQ<Edge> pq; // PQ of edges
    public LazyPrimMST(WeightedGraph G)
    {
        pq = new MinPQ<Edge>();
        mst = new Queue<Edge>();
        marked = new boolean[G.V()];
        visit(G, 0);
        while (!pq.isEmpty() && mst.size() < G.V() - 1)
        {
            Edge e = pq.delMin();
            int v = e.either(), w = e.other(v);
            if (marked[v] && marked[w]) continue;
            mst.enqueue(e);
            if (!marked[v]) visit(G, v);
            if (!marked[w]) visit(G, w);
        }
    }
    
    private void visit(WeightedGraph G, int v)
    {
        marked[v] = true;
        for (Edge e : G.adj(v))
            if (!marked[e.other(v)])
                pq.insert(e);
    }
    
    public Iterable<Edge> mst()
    { return mst; }
}

     --  Running Time

 

        Lazy Prim's algorithm computes the MST in time proportional to E log E and extra space proportional to E (in the worst case).

    
     --  Eager solution: Maintain a PQ of vertices connected by an edge to T

        a)  where priority of vertex v = weight of shortest edge connecting v to T.

        b)  Delete min vertex v and add its associated edge e = v–w to T.

        c)  Update PQ by considering all edges e = v–x incident to v

            – ignore if x is already in T

            – add x to PQ if not already on it

            – decrease priority of x if v–x becomes shortest edge connecting x to T

 
     --  Indexed priority queue

    Associate an index between 0 and N - 1 with each key in a priority queue.

        - Client can insert and delete-the-minimum.

        - Client can change the key by specifying the index.

 

public class IndexMinPQ<Key extends Comparable<Key>> {

    IndexMinPQ(int N) {} //create indexed priority queue with indices 0, 1, …, N-1
    void insert(int i, Key key) {} //associate key with index i
    void decreaseKey(int i, Key key) {} //decrease the key associated with index i
    boolean contains(int i) {} //is i an index on the priority queue?
    int delMin() {} //remove a minimal key and return its associated index
    boolean isEmpty() {} //is the priority queue empty?
    int size() {} //number of entries in the priority queue
}

    --  Indexed Priority Queue Implementation:

 

        a)  Start with same code as MinPQ.

        b)  Maintain parallel arrays keys[], pq[], and qp[] so that:

            – keys[i] is the priority of i

            – pq[i] is the index of the key in heap position i

            – qp[i] is the heap position of the key with index i

         c)  Use swim(qp[i]) implement decreaseKey(i, key)



 

10.  Single-link clustering

    --  k-clustering. Divide a set of objects classify into k coherent groups.

    --  Distance function. Numeric value specifying "closeness" of two objects.

    --  Single link. Distance between two clusters equals the distance between the two closest objects (one in each cluster).

    --  Single-link clustering. Given an integer k, find a k-clustering that maximizes the distance between two closest clusters.

    --  Solution: Kruskal's algorithm stopping when k connected components:

        1)  Form V clusters of one object each.

        2)  Find the closest pair of objects such that each object is in a different cluster, and merge the two clusters.

        3)  Repeat until there are exactly k clusters.

    --  Alternate solution. Run Prim's algorithm and delete k-1 max weight edges.


 

 

 

  • 大小: 16.2 KB
  • 大小: 33.5 KB
  • 大小: 18.3 KB
  • 大小: 22 KB
  • 大小: 9.6 KB
  • 大小: 15.9 KB
  • 大小: 16.9 KB
  • 大小: 15.5 KB
分享到:
评论

相关推荐

    MinimumSpanningTree_minimumspanningtree_

    最小生成树(Minimum Spanning Tree, MST)是图论中的一个重要概念,特别是在计算机科学和网络设计中有着广泛应用。它指的是在一个加权无向图中找到一个边的集合,这个集合构成一棵树,连接了图中所有顶点,并且总...

    matlab开发-MinimumSpanningTree

    本项目以"matlab开发-MinimumSpanningTree"为主题,展示了如何利用Matlab这一强大的数学计算工具来解决最小生成树问题。Matlab提供了丰富的工具箱,如Particle Swarm Optimization(PSO,粒子群优化)、Independent ...

    Dijkstra Floyed MinimumSpanningTree

    在计算机科学中,图论是解决复杂问题的一个重要领域,其中Dijkstra算法、Floyd算法和Minimum Spanning Tree(最小生成树)算法是经典且实用的图算法,它们广泛应用于网络设计、路径寻找、最短路径计算等多个场景。...

    Genetic algorithm approach on multi-criteria minimum spanning tree problem

    多目标最小生成树(Multi-Criteria Minimum Spanning Tree, mc-MST)问题是在传统最小生成树(Minimum Spanning Tree, MST)的基础上引入多个评价标准或目标函数,从而更贴近实际应用中的复杂需求。传统的网络优化...

    2019-2区-Unsupervised Anomaly Detection Minimum Spanning Tree Hydropower

    2019-2区-Unsupervised Anomaly Detection Based on Minimum Spanning Tree Approximated Distance Measures and Its Application to Hydropower Turbines

    ypap116-minimum-spanning-tree.zip_minimum spanning_spanning tree

    在计算机科学领域,特别是图论和网络流问题中,最小生成树(Minimum Spanning Tree, MST)是一个重要的概念。它用于寻找连接所有顶点的加权无向图的边集合,使得这些边的总权重最小。这个过程通常应用于解决资源分配...

    Minimum Spanning Tree with ICA.rar_ICA_mst_religious72p_slip72t_

    在图论和计算机科学中,最小生成树(Minimum Spanning Tree, MST)是一个经典的问题,它的目标是寻找一个无环加权图的所有边中,使得所有顶点都连通,且总权重最小的子集。这个子集称为最小生成树。最小生成树的应用...

    MinimumSpanningTree:最小生成树(使用 Brute Force、Kruskal 和 Prim 算法)

    最小生成树 使用邻接列表的图的最小生成树 (MST) 实现。 许可 Apache V2.0。 注意:我使用 Robert Sedgewick 的算法实现作为参考 - 非常感谢他的精彩教程。 此外,使用的编译器选项是 -std=c99。

    Visual_Minimum_Spanning_Tree.zip_VB TREE_tree

    《Visual Minimum Spanning Tree - VB 实现与理解》 在计算机科学中,树形结构是一种基本的数据组织形式,广泛应用于各种领域,如操作系统、数据库、网络设计等。Visual Minimum Spanning Tree (VMST) 是一个关于树...

    Assignment_Prim.cs.txt.zip_Science For All_spanning tree

    In computer science, Prim s algorithm is a greedy algorithm that finds a minimum spanning tree for a connected weighted undirected graph. This means it finds a subset of the edges that forms a tree ...

    Java_MinimumSpanningTree:Java中的MST算法

    在Java_MinimumSpanningTree-master项目中,可能包含了这两个算法的实现代码,供开发者参考学习。通过这些代码,开发者可以更好地理解这两种算法的逻辑,并将其应用于实际问题中,比如在网络设计中寻找成本最低的...

    minimum_spanning_tree.zip_分类

    最小生成树(Minimum Spanning Tree, MST)是图论中的一个重要概念,特别是在计算机科学和数据挖掘领域有着广泛应用。在这个“minimum_spanning_tree.zip_分类”压缩包中,包含了一个名为"minimum_spanning_tree.m...

    Kruskal_MATLAb.zip

    如果是带权值的无向图,那么权值之和最小的生成树,我们就称之为最小生成树(MST, Minimum Spanning Tree)。Kruskal algorithm implements a given undirected graph. If any two vertices are connected and a tree,...

    DNA Tile Assembly for Degree-Constrained Minimum Spanning Tree

    DNA Tile Assembly for Degree-Constrained Minimum Spanning Tree是一篇研究论文,主要探讨了如何使用DNA瓦片自组装模型来解决具有度约束的最小生成树问题。该问题在给定图中,限定每个顶点的度数为2的情况下,寻找...

    Graph-theory-Kruskal-minimum-spanning-tree-algori_graph theory_m

    Graph theory Kruskal minimum spanning tree algorithm and Paint program

    计算模型与算法技术:9-Greedy Technique.ppt

    * minimum spanning tree问题:Prim’s MST algorithm使用Greedy Technique来解决minimum spanning tree问题。 * traveling salesman problem和knapsack problem:Greedy Technique可以提供快速的近似解决方案。 ...

    perl programing to generate spanning tree

    最小生成树(Minimum Spanning Tree, MST)的目标是在一个加权无向图中找到一个边的集合,这些边连接了所有的顶点,且总权重最小。 Kruskal算法是解决这个问题的一种经典方法,由约瑟夫·克拉克·克鲁斯卡尔于1956...

    Prim-minimum-spanning-tree-algorithm.zip_prim_prim matlab

    最小生成树(Minimum Spanning Tree, MST)是图论中的一个重要概念,主要应用于网络设计、数据传输优化等领域。Prim算法是解决此问题的一种经典方法,由捷克数学家Vojtěch Jarník在1930年提出,后经美国计算机科学...

    最小生成树(MATLAB) (3).docx

    minimum spanning tree (MATLAB) 在计算机科学和信息技术领域中,minimum spanning tree(最小生成树)是图论中的一种概念。它是指在一个加权图中,寻找一个子图,使得该子图仍然是一个连通图,并且该子图的所有边...

    第1周-1B-基础拓展1

    本资源摘要信息涵盖了数据结构的基础拓展知识点,包括 BST、BBST、Hashtable、Priority Queue、Minimum Spanning Tree 等高级数据结构。同时,篇中还包括了对这些知识点的详细解释和示例,帮助读者更好地理解和掌握...

Global site tag (gtag.js) - Google Analytics