Connected Components for Undirected Graphs - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Connected Components for Undirected Graphs

Description:

Minimal Spanning Tree ... graph can have more that one minimal spanning tree. ... The local decisions are which edge to add to the spanning tree being formed. ... – PowerPoint PPT presentation

Number of Views:269
Avg rating:3.0/5.0
Slides: 21
Provided by: IRE62
Category:

less

Transcript and Presenter's Notes

Title: Connected Components for Undirected Graphs


1
Connected Components for Undirected Graphs
  • Irena Pevac

2
Connected Components
  • Def Connected component of an undirected graph
    is a subgraph such that any two vertices within
    it are connected with a path.
  • Relation P is defined as uPv iff u is connected
    with a path to v.
  • P is an equivalence relation.
  • P is reflexive For every node u uPu
  • P is symmetric For every two nodes u,v
    uPvgtvPu
  • P is transitive For every three nodes u,v,w
  • uPv AND vPw gt uPw

3
Equivalence Relation P
  • Equivalence relation P partitions the set of
    vertices into equivalence classes.
  • The class containing node u is the set of all
    nodes v uPv.
  • Example G(V,E) V 1,2,3,4,5,67,8,9
  • E1,2, 2,4, 2,6, 4,6, 3,5, 3,9,
    5,9, 7,8
  • G has 3 connected components.

4
Find Connected Components
  • Initially, all nine nodes are in components of
    their own.
  • If u and v are in the same component Gi then Gi1
    has the same set of connected components as Gi
  • If u and v are in different components, we merge
    the components containing u and v to get
    connected components for Gi1. Whenever we merge
    two trees, the root of a lesser child becomes a
    child of the root with greater height.

5
(No Transcript)
6
(No Transcript)
7
Running Time for Connected Components
  • Let graph G(V,E)
  • Let V n, and m be the greater of the number
    of edges and the number of nodes.
  • The policy of merging lower trees into higher
    ones guarantees that path from any node to its
    root is less than log n.
  • Total time is O(m log n).

8
Minimal Spanning Tree
  • A spanning tree for an undirected graph G is all
    the nodes of G together with a subset of edges of
    G such that
  • There is a path between any two nodes using only
    the edges in the spanning tree.
  • There are no cycles. (It forms an unrooted
    unordered tree.)
  • A minimal spanning tree is a spanning tree with
    minimal sum of edges labels.

9
Applications
  • Find the cheapest way to connect
  • a set of cities by roads
  • A set of terminals by wires
  • A set of computers by telephone lines
  • One undirected connected weighted (labeled)
    graph can have more that one minimal spanning
    tree.

10
Kruskals Algorithm
  • Kruskals Algorithm for finding minimal spanning
    tree is slight modification of the algorithm to
    find connected components
  • At the beginning each node is in its own
    component.
  • We consider the edges in the order of their
    labels. (smallest label first)
  • If an edge has its ends in different components
    we select that edge for the spanning tree and
    merge components. Otherwise , we do not select
    that edge for the spanning tree.

11
Graph G(V,E)
12
Edges Ordered by Weight
  • Select edge B D
  • Select edge C D
  • Select edge D F
  • Select edge A B
  • Do not select edge B C
  • Select D E
  • Do not select C F
  • Do not select E F

13
Graph G(V,E)
14
Select A B
15
Select C D
16
Select D F
17
Select A B
18
Resulting Minimal Spanning Tree
19
Greedy Algorithm
  • Kruskals algorithm is an example of a greedy
    algorithm.
  • In a greedy algorithm we make series of
    decisions, each one doing what seems best at the
    time.
  • The local decisions are which edge to add to the
    spanning tree being formed. We pick up edge with
    the least label that does not violate the
    definition of the spanning tree.
  • In this algorithm local optimum is also globally
    optimal.

20
Running Time for Kruskals Algorithm
  • Let graph G(V,E)
  • Let V n, and m be the greater of the number
    of edges and the number of nodes. (Typically, the
    number of edges is larger.)
  • If graph is represented with adjacency lists, we
    can find edges in O(m) time.
  • To sort edges we need at least O(m log m) time.
  • To do the algorithm we need O(m logn) time.
  • Overall time is O( m(lognlogm) )
  • Since mltn2 (there are at most n(n-1) /2 edges)
    it follows log m lt2 log n gt m(lognlogm) lt
    3mlogn
  • So, time for Kruskal algorithm is O(m logn).
Write a Comment
User Comments (0)
About PowerShow.com