Top Banner
Introduction to Introduction to Graph Theory Graph Theory By: Arun Kumar By: Arun Kumar (Asst. Professor) (Asst. Professor)
48

Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

Jan 19, 2018

Download

Documents

Lewis Carroll

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.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

Introduction to Introduction to Graph TheoryGraph Theory

By: Arun KumarBy: Arun Kumar (Asst. Professor)(Asst. Professor)

Page 2: Introduction to Graph Theory By: 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

Page 3: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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.

Page 4: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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.

Page 5: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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}}

Page 6: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

Simple Graphs Simple Graphs

Simple graphsSimple graphs are graphs without multiple are graphs without multiple edges or self-loops.edges or self-loops.

Page 7: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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.

Page 8: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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

Page 9: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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.

Page 10: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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.

Page 11: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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..

Page 12: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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

Page 13: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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.

Page 14: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

Special TypesSpecial Types

Empty Graph / Edgeless graphEmpty Graph / Edgeless graph– No edgeNo edge

Null graphNull graph– No nodesNo nodes– Obviously no edgeObviously no edge

Page 15: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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

Page 16: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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

Page 17: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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

Page 18: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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

Page 19: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

TreeTree

Connected Acyclic GraphConnected Acyclic Graph

Two nodes have Two nodes have exactlyexactly one one path between thempath between them

Page 20: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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.

Page 21: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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.

Page 22: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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.

Page 23: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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

Page 24: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

SubgraphsSubgraphs

Page 25: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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

Page 26: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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”.

Page 27: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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.

Page 28: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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

Page 29: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

ComponentComponent

Maximum Connected sub graphMaximum Connected sub graph

Page 30: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

IsomorphismIsomorphism

Page 31: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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..

Page 32: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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

Page 33: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

Graph Graph Abstract Data TypeAbstract Data Type

Page 34: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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.

Page 35: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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

Page 36: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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

Page 37: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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.

Page 38: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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.

Page 39: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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))

Page 40: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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

Page 41: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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.

Page 42: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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

Page 43: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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|)

Page 44: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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?

Page 45: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

Graph AlgorithmsGraph Algorithms

Page 46: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

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

Page 47: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

Graph AlgorithmsGraph Algorithms

Biconnected Component / Articulation PointBiconnected Component / Articulation PointBridgeBridgeGraph ColoringGraph ColoringEuler TourEuler TourHamiltonian TourHamiltonian TourCliqueCliqueIsomorphismIsomorphismEdge CoverEdge CoverVertex CoverVertex CoverVisibilityVisibility

Page 48: Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)

Thank youThank you