Top Banner
Graphs Part-II
28
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: Graph data structure

Graphs Part-II

Page 2: Graph data structure

Topics in discussion

Introduction to graphs Directed and undirected graphs Paths Connected graphs Trees Degree Isomorphic graphs Cut set Labeled graphs Hamiltonian circuit

Page 3: Graph data structure

Introduction to graphs

• Graph is a mathematical structure used to model pair wise relations between objects from a certain collection.

Vertices

Edges

Page 4: Graph data structure

Directed and undirected graphs

• A graph is said as directed graph whose definition makes reference to edges which are directed. Ie, edges which are ordered pair of vertices.

• A graph is said as undirected graph whose definition makes reference to unordered pairs of vertices as edges is known as an undirected graph.

Page 5: Graph data structure

Paths• A path in a graph is a sequence of vertices such that from each of its vertices there is an edge to the next vertex in the sequence.

• The length of a path is the number of edges on it. The length can be zero for the case of a single vertex.

Page 6: Graph data structure

• A path may be infinite.• A finite path always has a first vertex, called its start vertex, and a last vertex, called its end vertex. • Both of them are called terminal vertices of the path.• The other vertices in the path are internal vertices. A

Path= A B D C E

C A- Start vertex E- End vertex

B

D

E

Page 7: Graph data structure

Simple path• A graph with no loops or multiple edges is called a simple graph. • A path with no repeated vertices is called a simple path.• The path from v1 to v4 is said to be simple path as

vertices is touched more than once.• The path from v1 to v4 is not simple as v1 is touched twice or looped.

cycle: • Simple path, except that the last vertex is the same as the first vertex. Its also known as a circuit or circular path.

Path= A E C A

A B

C D

E

Page 8: Graph data structure

Connected graph• Two vertices vi, vj in a graph G is said to be connected only if

there is a path in G between vi and vj.

• A undirected graph is said to be connected graph if every pair of distinct vertices vi, vj are connected.

Connected undirected graph

Page 9: Graph data structure

• In the case of an undirected graph, which is not connected,the

maximal connected subgraph is called as a connected component or simply a component.

The graph below has 3 connected components.

Page 10: Graph data structure

Connected directed graph

• A directed graph is said to be strongly connected only if every pair of distinct vertices vi, vj are connected. • If there is a directed path from vi to vj then there must be a directed path from vj to vi.

A strongly connected directed graph

Page 11: Graph data structure

• Strongly connected components of directed graph

• The below graph is not strongly connected but is said to possess two strongly connected components.

Page 12: Graph data structure

Trees

• A tree is defined to be a connected acyclic graph. The following properties are satisfied by a tree:

There exist a path between any two vetices of the treeNo cycles must be present in the tree ie, trees are

acyclic.

A Tree Not a tree

Page 13: Graph data structure

• Terms like parent, child, ancestors,level are missing but both the definitions of tree in datastructures and in graph share the same properties of connectedness and acyclicity.

Both have the same properties of connectedness and acyclicity.

Page 14: Graph data structure

Degree• The degree of vertex in an undirected graph is the number of edges incident to that vertex. • A vertex with degree one is called pendent vertex or end vertex.• A vertex with degree zero and hence has no incident edges is called an isolated vertex.

In the undirected graph vertex v3 has the degree 3And vertex v2 has the degree 2

V1

B

A

Pendent vertexIsolated vertex

Page 15: Graph data structure

Degree in directed graph

• Degree of directed graph has two types i. Indegree

No of edges with their head towards the vertex.ii. Outdegree

No of edges with their tail towards the vertex.

Indegree of vertex v2 is 2

and

Outdegree of vertex v1 is 1.

Page 16: Graph data structure

Example: 0

1 2

3 4 5 6

G1 G2

32

3 3

1 1 1 1

Directed graph

in-degreeout-degree

0

1

2

G3

in:1, out: 1

in: 1, out: 2

in: 1, out: 0

0

1 2

3

33

3

Page 17: Graph data structure

Isomorphic graphs

• Isomorphism– Two graphs are isomorphic, if they are structurally

identical, Which means that they correspond in all structural details.

– Formal vertex-to-vertex and edge –to-edge correspondence is called isomorphism.

• Two graph are said to be isomorphic if They have the same no of vertices. They have the same number of edges. They have an equal number of vertices with a given

degree.

Page 18: Graph data structure

Verifying Isomorphic graph

Vertices(A) : a b c d e

Vertices(B): q p r s t

Degree of vertices:

2 3 3 3 1

Edges(A): e1 e2 e3 e4 e5 e6

Edges(B): e’1 e’4 e’3 e’2 e’5 e’6

Graph A

Graph B

Page 19: Graph data structure

Examples for non isomorphic graphs :

i)

1st graph has more edges than 2nd.

u1

u2

u3

u5u4

v1

v2

v3

v4

Page 20: Graph data structure

ii) 2nd graph has vertex of degree 1, 1st graph doesn't.

u1

u2

u3

u5u4

v1

v2

v3

v5v4

Page 21: Graph data structure

iii) 1st graph has 2 degree 1 vertices, 4 degree 2 vertex and 2 degree 3 vertices. 2nd graph has 3 degree 1 vertices, 3 degree 2 vertex and 3 degree 3 vertices.

u1 u2 u3 u6u4 u5

u7 u9

v1 v2 v3 v6v4 v5

v7 v8 v9u8

Page 22: Graph data structure

Cut set• Cut set is a connected graph G is the set of edges whose removal from G leaves G disconnected, Provided the removal of no proper sebset of these edges disconnects the graph G.• Cut set are also called proper cut set or minimal cut set.

Page 23: Graph data structure

• If one can remove a vertex (and all incident edges) and produce a graph with more components, the vertex is called a cut vertex or articulation point.• Similarly if removal of an edge creates more components the edge is called a cut edge or bridge.• The cut-set of the cut is the set of edges whose end points are in different subsets of the partition. Edges are said to be crossing the cut if they are in its cut-set.

Page 24: Graph data structure

Labeled graph• A graph G is called a labeled graph if its edges and/or vertices are assigned some data.

• A graph labeling is the assignment of labels, traditionally represented by integers, to the edges or vertices, or both, of a graph.

• If the edge e is assigned a non-negative number then it is called the weight or length of the edge e.

Page 25: Graph data structure

• Vertex-labeled graph• If all the vertices in a graph are given a label then it is

vertex-labeled graph

• Edge-labeled graph• If all the Edges in a graph are given a label then it is

Edge-labeled graph

Page 26: Graph data structure

Hamiltonian circuit• Hamiltonian paths and circuits are named after the mathematician ,William Rowan Hamilton.• A Hamiltonian circuit in a connected graph is defined as a closed walk that traverses every vertex of G exactly once. also called Hamiltonian cycles.• It is called as circuit if it includes every vertex of G. If any edge

is removed then it is Hamiltonian path.

The above is a Hamiltonian circuit as each and every vertex is traversed once

And completes the circuit by ending in starting point.

Hamiltonian circuit:{v1,v3,v4,v2,v6,v5,v1}

Page 27: Graph data structure

• A Hamiltonian path or traceable path is a path that visits each vertex exactly once. Its also called as a traceable graph.

• A graph is Hamiltonian-connected if for every pair of vertices there is a Hamiltonian path between the two vertices.

a b

cd

Hamiltonian path

Page 28: Graph data structure

Thank you