Discrrete mathematics for computer science prim

19 27 0
Discrrete mathematics for computer science prim

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Minimum Spanning Trees Subgraph • A graph G is a subgraph of graph H if – The vertices of G are a subset of the vertices of H, and – The edges of G are a subset of the edges of H Spanning Tree • A spanning tree of a graph G is a subgraph of G that is a tree and includes all the vertices of G • Every connected graph has a spanning tree – Start with G If G is a tree then it is a ST of G If not, G has a cycle Remove any edge of the cycle The result is a connected subgraph of G Repeat Process must terminate since the number of edges is finite Spanning Trees Spanning Trees a spanning tree Spanning Trees another spanning tree (can have many) Weighted Graphs • A weighted graph is a graph with a mapping of edges to R+ assigning a weight to each edge • A minimum spanning tree of a weighted graph is a spanning tree of minimum total weight (sum of the weights of the edges in the tree) Minimum Spanning Trees 4 Minimum Spanning Trees 4 1 Choose any vertex Minimum Spanning Trees 4 2 Choose minimum weight edge connected to that vertex Minimum Spanning Trees 4 Choose minimum weight edge connected to chosen vertices Minimum Spanning Trees 4 Choose minimum weight edge connected to chosen vertices Minimum Spanning Trees 4 Choose minimum weight edge connected to chosen vertices without creating a Minimum Spanning Trees 4 Choose minimum weight edge connected to chosen vertices without creating a Prim’s algorithm • To find a MST of a connected weighted graph G, we build a tree one edge at a time – Start with T being any node of G – Pick a minimum weight edge that does not create a cycle and that connects a node in T to a node not in T Add that edge to T – Repeat until all nodes of G have been added to T • A “Greedy algorithm” Proof that Prim’s algorithm works • Invariant: At every stage, T is a subgraph of a MST • True initially since T is just a single node • The algorithm runs until all nodes have been added to T, so in the end the invariant says that T is a MST • So we just need to show that each stage of the algorithm preserves the invariant Proof that the algorithm maintains the invariant • Proof by contradiction Suppose there is a stage at which the invariant is true before and false after • Let e be the edge added when the invariant is first violated Suppose e joins node v in T to node w not in T • So T is a subgraph of a MST but T+e is not • Let T’ be a MST of which T is a subgraph • Edge e is not in T’ Proof that the algorithm maintains the invariant • Since T’ is a spanning tree, there is a path p from v to w in T’ Path p does not go through e since e is not part of T’ So p+e is a cycle consisting of two different paths from u to v • Path p must include an edge f which has one end in T and the other not in T • Edge f must have weight ≥ the weight of e, otherwise the algorithm would have chosen to add edge f to T instead of e • Removing f from T’ and adding e results in a spanning tree of weight ≤ the weight of T’ and including T as a subgraph, contradicting the assumption that T+e was not a subgraph of a MST ✔ Finis ... Minimum Spanning Trees 4 Choose minimum weight edge connected to chosen vertices without creating a Prim s algorithm • To find a MST of a connected weighted graph G, we build a tree one edge at a... edge to T – Repeat until all nodes of G have been added to T • A “Greedy algorithm” Proof that Prim s algorithm works • Invariant: At every stage, T is a subgraph of a MST • True initially since... the invariant • Proof by contradiction Suppose there is a stage at which the invariant is true before and false after • Let e be the edge added when the invariant is first violated Suppose e joins

Ngày đăng: 22/03/2019, 11:44

Mục lục

    Proof that Prim’s algorithm works

    Proof that the algorithm maintains the invariant

    Proof that the algorithm maintains the invariant

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan