Minimum spanning tree for [Data Structure & Algrithom] without graphs

Source: Internet
Author: User

Min Spanning tree (Minimum Spanning tree)-the smallest of the weights that connect the edges of all vertices

Prim algorithm
    • Basic idea-Set the vertex set of the graph to V; the vertex set of the minimum spanning tree is U
      1. Place a vertex into u
      2. In one vertex belonging to u, the other vertex belongs to all the edges of the v-u, and the least weighted edge is found
      3. The vertex that will be found does not belong to u, put in U, repeat 2 until you include all vertices in u
    • Specific implementation
      • Introduce auxiliary array edge[], length equals the number of vertices
        • Node structure-data field vertex (another vertex connected to the vertex) | weight cost (weight of this edge)
        • For nodes in U i-edge[i].cost = 0
        • For node J-edge[j in V-u] represents the least-weighted edge of the node J
      • Time complexity O (n2) (independent of the number of edges)
    • Suitable for edge-dense graphs
Kruskal algorithm
    • Basic ideas
      1. Select the edge with the least weight in the diagram
      2. If this edge does not form a loop, select this edge; otherwise, find the edge of the next weighted value
    • Time complexity (independent of vertex count)
      • O (n2)-already sorted by the weight of the edge
      • O (ELOG2E)-not sorted by the weight of the edge
    • Graphs for edge coefficients

Minimum spanning tree for [Data Structure & Algrithom] without graphs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.