Upload
lewis-carroll
View
230
Download
0
Embed Size (px)
DESCRIPTION
Definition: Graph G is an ordered triple G:=(V, E, f) –V is a set of nodes, points, or vertices. –E is a set, whose elements are known as edges or lines. –f is a function maps each element of E to an unordered pair of vertices in V.
Citation preview
Introduction to Introduction to Graph TheoryGraph Theory
By: Arun KumarBy: Arun Kumar (Asst. Professor)(Asst. Professor)
What is a Graph?What is a Graph?
Informally a Informally a graphgraph is a set of nodes joined by is a set of nodes joined by a set of lines or arrows.a set of lines or arrows.
1 12 3
4 45 56 6
2 3
Definition: GraphDefinition: Graph
G is an ordered triple G:=(V, E, f)G is an ordered triple G:=(V, E, f)– V is a set of nodes, points, or vertices. V is a set of nodes, points, or vertices. – E is a set, whose elements are known as edges or E is a set, whose elements are known as edges or
lines. lines. – f is a function f is a function
maps each element of E maps each element of E to an unordered pair of vertices in V. to an unordered pair of vertices in V.
DefinitionsDefinitions
VertexVertex– Basic ElementBasic Element– Drawn as a Drawn as a nodenode or a or a dotdot..– VVertex setertex set of of GG is usually denoted by is usually denoted by VV((GG), or ), or VVEdgeEdge– A set of two elementsA set of two elements– Drawn as a line connecting two vertices, called Drawn as a line connecting two vertices, called
end vertices, or endpoints. end vertices, or endpoints. – The edge set of G is usually denoted by E(G), or E.The edge set of G is usually denoted by E(G), or E.
ExampleExample
V:={1,2,3,4,5,6} V:={1,2,3,4,5,6} E:={{1,2},{1,5},{2,3},{2,5},{3,4},{4,5},{4,6}} E:={{1,2},{1,5},{2,3},{2,5},{3,4},{4,5},{4,6}}
Simple Graphs Simple Graphs
Simple graphsSimple graphs are graphs without multiple are graphs without multiple edges or self-loops.edges or self-loops.
PathPath
1 2 3
4 5 6
Cycle
Simple path from 1 to 5 = [ 1, 2, 4, 5 ]Our text’s alternates the verticesand edges.
A
D E F
B C
Unreachable
Cycle
If there is path If there is path pp from from uu to to vv then we then we say say vv is is reachablereachable from from uu via via pp. .
A A pathpath is a sequence of vertices such that there is an is a sequence of vertices such that there is an edge from each vertex to its successor. edge from each vertex to its successor. A path is A path is simplesimple if each vertex is distinct. if each vertex is distinct.
CycleCycle
A path from a vertex to itself is called a A path from a vertex to itself is called a cyclecycle. . A graph is called A graph is called cycliccyclic if it contains a cycle; if it contains a cycle; – otherwise it is called otherwise it is called acyclicacyclic
1 2 3
4 5 6
Cycle
A
D E F
B C
Unreachable
Cycle
ConnectivityConnectivity
is is connectedconnected if if – you can get from any node to any other by following a you can get from any node to any other by following a
sequence of edges OR sequence of edges OR – any two nodes are connected by a path.any two nodes are connected by a path.
A directed graph is A directed graph is strongly connectedstrongly connected if there is a if there is a directed path from any node to any other node.directed path from any node to any other node.
Sparse/DenseSparse/Dense
A graph is A graph is sparsesparse if | if | EE | | | | VV | |A graph is A graph is densedense if | if | EE | | | | VV | |2.2.
A A weighted graphweighted graph
1 2 3
4 5 6
.5
1.2
.2
.5
1.5.3
1
4 5 6
2 32
1 35
is a graph for which each edge has an associated is a graph for which each edge has an associated weightweight, usually given by a , usually given by a weight functionweight function w: Ew: E RR..
Directed Graph (digraph)Directed Graph (digraph)
Edges have directionsEdges have directions– An edge is an An edge is an ordered ordered pair of nodespair of nodes
BipartiteBipartite graphgraphVV can be partitioned into 2 can be partitioned into 2 sets sets VV11 and and VV22 such that (such that (uu,,vv))EE implies implies – either either uu VV11 and and vv VV2 2
– OR OR vv VV1 1 and and uuVV2.2.
Special TypesSpecial Types
Empty Graph / Edgeless graphEmpty Graph / Edgeless graph– No edgeNo edge
Null graphNull graph– No nodesNo nodes– Obviously no edgeObviously no edge
Complete GraphComplete Graph
Denoted KDenoted Knn
Every pair of vertices are adjacentEvery pair of vertices are adjacentHas n(n-1) edgesHas n(n-1) edges
Complete Bipartite GraphComplete Bipartite Graph
Bipartite Variation of Complete GraphBipartite Variation of Complete GraphEvery node of one set is connected to every Every node of one set is connected to every other node on the other setother node on the other set
Planar GraphPlanar Graph
Can be drawn on a plane such that no two edges intersectCan be drawn on a plane such that no two edges intersectKK44 is the largest complete graph that is planar is the largest complete graph that is planar
Dual GraphDual Graph
Faces are considered as Faces are considered as nodesnodesEdges denote face Edges denote face adjacencyadjacency
Dual of dual is the Dual of dual is the original graphoriginal graph
TreeTree
Connected Acyclic GraphConnected Acyclic Graph
Two nodes have Two nodes have exactlyexactly one one path between thempath between them
Generalization: HypergraphGeneralization: Hypergraph
Generalization of a graph, Generalization of a graph, – edges can connect any number of vertices. edges can connect any number of vertices.
Formally, an hypergraph is a pair (X,E) where Formally, an hypergraph is a pair (X,E) where – X is a set of elements, called nodes or vertices, and X is a set of elements, called nodes or vertices, and – E is a set of subsets of X, called hyperedges. E is a set of subsets of X, called hyperedges.
Hyperedges are arbitrary sets of nodes, Hyperedges are arbitrary sets of nodes, – contain an arbitrary number of nodes.contain an arbitrary number of nodes.
DegreeDegree
Number of edges incident on a nodeNumber of edges incident on a node
A
D E F
B C
The degree of B is 2.
Degree (Directed Graphs)Degree (Directed Graphs)
In degree: Number of edges enteringIn degree: Number of edges enteringOut degree: Number of edges leavingOut degree: Number of edges leaving
Degree = indegree + outdegreeDegree = indegree + outdegree
1 2
4 5
The in degree of 2 is 2 andthe out degree of 2 is 3.
Degree: Simple FactsDegree: Simple Facts
If If G G is a digraph with is a digraph with mm edges, then edges, then
indeg( indeg(vv) = ) = outdeg( outdeg(vv) = ) = m = |Em = |E | |
If If G G is a graph with is a graph with mm edges, then edges, then
deg( deg(vv) = 2) = 2mm = 2 | = 2 |EE | |
– Number of Odd degree Nodes is evenNumber of Odd degree Nodes is even
SubgraphsSubgraphs
SubgraphSubgraph
Vertex and edge sets are subsets of those of GVertex and edge sets are subsets of those of G– a a supergraphsupergraph of a graph G is a graph that contains of a graph G is a graph that contains
G as a subgraph. G as a subgraph.
A graph G contains another graph H if some A graph G contains another graph H if some subgraph of G subgraph of G – is H or is H or – is isomorphic to H.is isomorphic to H.
H is a H is a proper subgraphproper subgraph if H!=G if H!=G
Spanning subgraphSpanning subgraph
Subgraph H has the same vertex set as G. Subgraph H has the same vertex set as G. – Possibly not all the edgesPossibly not all the edges– ““H spans G”.H spans G”.
Induced SubgraphInduced Subgraph
For any pair of vertices x and y of H, xy is an For any pair of vertices x and y of H, xy is an edge of H if and only if xy is an edge of G.edge of H if and only if xy is an edge of G.– H has the most edges that appear in G over the H has the most edges that appear in G over the
same vertex set.same vertex set.
Induced Subgraph (2)Induced Subgraph (2)
If H is chosen based on a vertex subset S of If H is chosen based on a vertex subset S of V(G), then H can be written as G[S]V(G), then H can be written as G[S]– ““induced by S”induced by S”
A graph that does not contain H as an induced A graph that does not contain H as an induced subgraph is said to be subgraph is said to be H-freeH-free
ComponentComponent
Maximum Connected sub graphMaximum Connected sub graph
IsomorphismIsomorphism
IsomorphismIsomorphism
Bijection, i.e., a one-to-one mapping:Bijection, i.e., a one-to-one mapping:f : V(G) -> V(H) f : V(G) -> V(H)
u and v from G are adjacent if and only if f(u) u and v from G are adjacent if and only if f(u) and f(v) are adjacent in H.and f(v) are adjacent in H.If an isomorphism can be constructed between If an isomorphism can be constructed between two graphs, then we say those graphs are two graphs, then we say those graphs are isomorphicisomorphic..
Isomorphism ProblemIsomorphism Problem
Determining whether two Determining whether two graphs are isomorphicgraphs are isomorphicAlthough these graphs look Although these graphs look very different, they are very different, they are isomorphic; one isomorphism isomorphic; one isomorphism between them isbetween them isf(a) = 1 f(b) = 6 f(c) = 8 f(d) = 3 f(a) = 1 f(b) = 6 f(c) = 8 f(d) = 3 f(g) = 5 f(h) = 2 f(i) = 4 f(j) = 7 f(g) = 5 f(h) = 2 f(i) = 4 f(j) = 7
Graph Graph Abstract Data TypeAbstract Data Type
Graph ADTGraph ADT
In computer science, a graph is an abstract In computer science, a graph is an abstract data type (ADT) data type (ADT) that consists of that consists of – a set of nodes and a set of nodes and – a set of edges a set of edges
establish relationships (connections) between the nodes. establish relationships (connections) between the nodes.
The graph ADT follows directly from the The graph ADT follows directly from the graph concept from mathematics.graph concept from mathematics.
Representation (Matrix)Representation (Matrix)
Incidence MatrixIncidence Matrix– E x VE x V– [edge, vertex] contains the edge's data [edge, vertex] contains the edge's data
Adjacency MatrixAdjacency Matrix– V x VV x V– Boolean values (adjacent or not)Boolean values (adjacent or not)– Or Edge WeightsOr Edge Weights
Representation (List)Representation (List)
Edge ListEdge List– pairs (ordered if directed) of verticespairs (ordered if directed) of vertices– Optionally weight and other data Optionally weight and other data
Adjacency ListAdjacency List
Implementation of a Graph.Implementation of a Graph.
Adjacency-list representation Adjacency-list representation – an array of |an array of |VV | lists, one for each vertex in | lists, one for each vertex in VV. . – For each For each uu VV , , ADJADJ [ [ uu ] points to all its adjacent ] points to all its adjacent
vertices.vertices.
Adjacency-list representation for a Adjacency-list representation for a directed graph.directed graph.
1
5
122
54 4
3 3
2 5
5 3 4
4
5
5
Variation: Can keep a second list of edges coming into a vertex.
Adjacency listsAdjacency lists
Advantage: Advantage: – Saves space for sparse graphs. Most graphs are Saves space for sparse graphs. Most graphs are
sparse.sparse.– Traverse all the edges that start at v, in Traverse all the edges that start at v, in
(degree(v))(degree(v))
Disadvantage:Disadvantage:– Check for existence of an edge (v, u) in worst Check for existence of an edge (v, u) in worst
case time case time (degree(v))(degree(v))
Adjacency ListAdjacency List
StorageStorage– For a directed graph the number of items areFor a directed graph the number of items are
(out-degree ((out-degree (vv)) = | )) = | EE | |
So we need So we need ( ( V + V + EE ) )
– For undirected graph the number of items areFor undirected graph the number of items are
(degree ((degree (vv)) = 2 | )) = 2 | EE | | Also Also ( ( V + V + EE ) )
Easy to modify to handle weighted graphs. How?Easy to modify to handle weighted graphs. How?
v V
v V
Adjacency matrix representationAdjacency matrix representation
1
5
2
43
1 2 3 4 5
12345
0 1 0 0 11 0 1 1 10 1 0 1 00 1 1 0 11 1 0 1 0
||VV | x | | x |V |V | matrix matrix A A = ( = ( aaijij ) ) such that such that aaijij = 1 if ( = 1 if (i, ji, j ) ) EE and 0 otherwise. and 0 otherwise.
We We arbitrarily uniquely assign the numbers 1, arbitrarily uniquely assign the numbers 1, 2, . . . , | 2, . . . , | VV | to each vertex. | to each vertex.
Adjacency Matrix Representation Adjacency Matrix Representation for a Directed Graphfor a Directed Graph
1 2 3 4 5
12345
0 1 0 0 10 0 1 1 10 0 0 1 00 0 0 0 10 0 0 0 0
1
5
2
43
Adjacency Matrix RepresentationAdjacency Matrix Representation
Advantage:Advantage:– Saves space for:Saves space for:
Dense graphs. Dense graphs. Small unweighted graphs using 1 bit per edge.Small unweighted graphs using 1 bit per edge.
– Check for existence of an edge in Check for existence of an edge in (1)(1)
Disadvantage:Disadvantage:– Traverse all the edges that start at v, in Traverse all the edges that start at v, in (|V|)(|V|)
Adjacency Matrix RepresentationAdjacency Matrix Representation
Storage Storage ( | ( | VV | |22) ( We usually just write, ) ( We usually just write, ( ( VV 22) )) )– For undirected graphs you can save storage (only For undirected graphs you can save storage (only
1/2(V1/2(V22)) by noticing the adjacency matrix of an )) by noticing the adjacency matrix of an undirected graph is symmetric. How?undirected graph is symmetric. How?
Easy to handle weighted graphs. How?Easy to handle weighted graphs. How?
Graph AlgorithmsGraph Algorithms
Graph AlgorithmsGraph Algorithms
Shortest PathShortest Path– Single SourceSingle Source– All pairs (Ex. Floyd Warshall)All pairs (Ex. Floyd Warshall)
Network FlowNetwork FlowMatchingMatching– BipartiteBipartite– WeightedWeighted
Topological OrderingTopological OrderingStrongly ConnectedStrongly Connected
Graph AlgorithmsGraph Algorithms
Biconnected Component / Articulation PointBiconnected Component / Articulation PointBridgeBridgeGraph ColoringGraph ColoringEuler TourEuler TourHamiltonian TourHamiltonian TourCliqueCliqueIsomorphismIsomorphismEdge CoverEdge CoverVertex CoverVertex CoverVisibilityVisibility
Thank youThank you