graphs csc 172 spring 2002 lecture 25. structure of the internet europe japan backbone 1 backbone 2...
Post on 21-Dec-2015
212 views
TRANSCRIPT
![Page 1: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/1.jpg)
GRAPHS
CSC 172
SPRING 2002
LECTURE 25
![Page 2: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/2.jpg)
Structure of the Internet
Europe
Japan
Backbone 1
Backbone 2
Backbone 3
Backbone 4, 5, N
Australia
Regional A
Regional B
NAP
NAP
NAP
NAP
SOURCE: CISCO SYSTEMS
![Page 3: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/3.jpg)
GRAPHS
GRAPH G= (V,E)V: a set of verticies (nodes)E: a set of edges connecting
verticies VAn edge is a pair of nodes
Example:V = {a,b,c,d,e,f,g}E = {(a,b),(a,c),(a,d),(b,e),(c,d),(c,e),(d,e),(e,f)}
a b
d
c
e
f g
![Page 4: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/4.jpg)
GRAPHS
Labels (weights) are also possible
Example:
V = {a,b,c,d,e,f,g}
E = {(a,b,4),(a,c,1),(a,d,2),
(b,e,3),(c,d,4),(c,e,6),
(d,e,9),(e,f,7)}
a b
d
c
e
f g
4
1
2 364
9
7
![Page 5: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/5.jpg)
DIGRAPHS
Implicit directions are also possible
Directed edges are arcs
Example:
V = {a,b,c,d,e,f,g}
E = {(a,b),(a,c),(a,d),
(b,e),(c,d),(c,e),
(d,e),(e,f),(f,e)}
a b
d
c
e
f g
![Page 6: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/6.jpg)
Sizes
By convention
n = number of nodes
m = the larger of the number of nodes and edges/arcs
Note : m>= n
![Page 7: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/7.jpg)
Complete Graphs
An undirected graph is complete if it has as many edges as possible.
a
n=1m=0
a b
n=2m=1
a b
a
n=3m=3
a b
a b
n=4m=6
What is the general form? Basis is = 0
Every new node (nth) adds (n-1) new edges
(n-1) to add the nth
![Page 8: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/8.jpg)
In general
12)3()2()1( nnn
2
)1(1
1
nni
n
i
![Page 9: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/9.jpg)
Paths
In directed graphs, sequence of nodes with arcs from each node to the next.
In an undirected graph: sequence of nodes with an edge between two consecutive nodes
Length of path – number of edges/arcs
If edges/arcs are labeled by numbers (weights) we can sum the labels along a path to get a distance.
![Page 10: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/10.jpg)
Cycles
Directed graph: path that begins and ends at the same nodeSimple cycle: no repeats except the ends
The same cycle has many paths representing it, since the beginning/end point may be any node on the cycle
Undirected graphSimple cycle = sequence of 3 or more nodes with the
same beginning/end, but no other repetigions
![Page 11: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/11.jpg)
Representations of Graphs
Adjacency List
Adjacency Matrices
![Page 12: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/12.jpg)
Adjacency Lists
An array or list of headers, one for each nodeUndirected: header points to a list of adjacent (shares
and edge) nodes.Directed: header for node v points to a list of
successors (nodes w with an arc v w)Predecessor = inverse of successor
Labels for nodes may be attached to headersLabels for arcs/edges are attached to the list cellEdges are represented twice
![Page 13: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/13.jpg)
Graph a
b
c
d
a b
d
c
![Page 14: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/14.jpg)
Adjacency Matrices
Node names must be integers [0…MAX-1]
M[k][j]= true iff there is an edge between nodes k and j (arc k j for digraphs)
Node labels in separate array
Edge/arc labels can be values M[k][j]Needs a special label that says “no edge”
![Page 15: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/15.jpg)
a b
d
cGRAPH
1 1 1 1
1 1 0 0
1 0 1 1
1 0 1 1
![Page 16: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/16.jpg)
Connected Components
![Page 17: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/17.jpg)
Connected components
a b
d
c
e
f g
A connected graph
a b
d
c
e
f g
An unconnected graph(2 components)
![Page 18: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/18.jpg)
Why Connected Components?
Silicon “chips” are built from millions of rectangles on multiple layers of silicon
Certain layers connect electrically
Nodes = rectangles
CC = electrical elements all on one current
Deducing electrical ements is essential for simulation (testing) of the design
![Page 19: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/19.jpg)
Minimum-Weight Spanning Trees
Attach a numerical label to the edges
Find a set of edges of minimum total weight that connect (via some path) every connectable pair of nodes
To represent Connected Components we can have a tree
![Page 20: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/20.jpg)
![Page 21: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/21.jpg)
a b
d
c
e
f g
4
1
2 364
9
72
8
![Page 22: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/22.jpg)
a b
d
c
e
f g
4
1
2 364
9
72
8
![Page 23: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/23.jpg)
a b
d
c
e
f g
4
1
2 3
72
![Page 24: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/24.jpg)
Representing Connected Components
Data Structure = tree, at each nodeParent pointer
Height of the subtree rooted at the node
Methods =
Merge/FindFind(v) finds the root of the tree of which graph node v is
a member
Merge(T1,T2) merges trees T1 & T2 by making the root of lesser height a child of the other
![Page 25: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/25.jpg)
Connected Component Algorithm
1. Start with each graph node in a tree by itself
2. Look at the edges in some orderIf edge {u,v} has ends in different trees (use find(u) &
find(v)) then merge the trees
Once we have considered all edges, each remaining tree will be one CC
![Page 26: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/26.jpg)
Run Time Analysis
Every time a node finds itself on a tree of greater height due to a merge, the tree also has at least twice as many nodes as its former tree
Tree paths never get longer than log2nIf we consider each of m edges in O(log n) time
we get O(m log n)Merging is O(1)
![Page 27: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/27.jpg)
Proof
S(h): A tree of height h, formed by the policy of merging lower into higher has at least 2h nodes
Basis: h = 0, (single node), 20 = 1
Induction: Suppose S(h) for some h >= 0
![Page 28: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/28.jpg)
Consider a tree of height h+1
t2
t1Each have height ofAt least h
BTIH: T1 & T2 have at least 2h nodes, each
2h + 2h = 2h+1
![Page 29: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/29.jpg)
Kruskal’s Algorithm
An example of a “greedy” algorithm“do what seems best at the moment”
Use the merge/find MWST algorithm on the edges in ascending order
O(m log m)
Since m <= n2, log m <= 2 log n, so O(m log n) time
![Page 30: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/30.jpg)
Traveling Salesman Problem
Find a simple cycle, visiting all nodes, of minimum weight
Does “greedy” work?
![Page 31: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/31.jpg)
Implementation Classes
Network
Undirected Network
Undirected Tree
Undirected GraphDiGraph
Tree
![Page 32: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/32.jpg)
Network Class Vertex Methods
public boolean containsVertex (Vertex vert)
public boolean addVertex (Vertex vert)
public boolean removeVertex (Vertex vert)
![Page 33: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/33.jpg)
Network Class Edge Methods
public int getEdgeCount();
public double getEdgeWeight (Vertex v1, Vertex v2)
public boolean containsEdge(Vertex v1, Vertex v2)
public boolean addEdge(Vertex v1, Vertex v2,
double weight)
public boolean removeEdge(Vertex v1, Vertex v2)
![Page 34: GRAPHS CSC 172 SPRING 2002 LECTURE 25. Structure of the Internet Europe Japan Backbone 1 Backbone 2 Backbone 3 Backbone 4, 5, N Australia Regional A Regional](https://reader030.vdocument.in/reader030/viewer/2022032521/56649d5e5503460f94a3e014/html5/thumbnails/34.jpg)
General Network Class Methods
public Network()
public Network(int V)
public Network(Network network)
public boolean isEmpty()
public int size()
public Iterator iterator()