Basics of Graphs Theory

Post on 17-Feb-2017

13 views 0 download

transcript

GRAPHS

Mariya BohraSYMCAK.K.Wagh Institute of Engineering and Education Research

What’s there in a Graph?

Graphs consist of points called vertices lines called edges

1. Edges connect two vertices.2. Edges only intersect at vertices.3. Edges joining a vertex to itself are called

loops.

Example 1:

The following picture is a graph.List its vertices and edges.

A

E

D

C

B

Why would you use Graph?

Graphs are a structure for describing relationships between objects.

The vertices denote the objects and the edges represent the relationship.

Example 2:This is also a graph.

The vertices just

happen to have

people’s names.

Such a graph could

represent friendships

(or any kind of

relationship).

Ray Mary Suze

Jake Fanny Lulu

Luke

GRAPH TERMINOLOGIES

GRAPHS could be…• UNDIRECTED

Edges do not have a direction.

The edges indicate a two-way relationship.

Each edge can be traversed in both directions.

• DIRECTED

Edges have direction.The edges indicate

a one-way relationship.Each edge can only be

traversed in a single direction

GRAPHS could be…• UNWEIGHTED

Edges have NO weight.

• WEIGHTED

Edges have a weight.

GRAPHS could be…• CYCLIC

Graph contains cycles.

• ACYCLIC

 Graph contains no cycles

A Complete Graph

• A complete graph is a graph where every vertex is adjacent to every other vertex.

• A complete graph on n vertices is denoted by Kn (or sometimes by K(n)).

Example 3 :Which ones are complete graphs?

1. 2.

3. 4.

The word ‘Adjacent’

• Adjacent Vertices are two vertices that are joined by an edge.

• Adjacent Edges are two edges that intersect at a vertex.

Example 4: 1. List out the

pairs of adjacent vertices.

2. List out the pairs of adjacent edges.

Degree of a Vertex

The degree of a vertex is the number of edges incident at that vertex, with loops counted twice.Degree of the Graph

The degree of a graph is the MAXIMUM degree its vertices.

Example 5: 1. Find the degree

of each vertex .2. What is the

degree of the graph?

Odd Degree and Even Degree

• An odd vertex is a vertex of odd degree.

• An even vertex is a vertex of even degree.

Example 6: 1. Find the

vertices with• Odd degree• Even degree

PATH

A path in a graph represents a way to get from an origin to a destination by traversing edges in the graph.

LENGTH

The length of a path is the number of edges that it uses.

EXAMPLE 7: Path from Node 1 to Node 6.What is the length of the path in both the cases?

The red path is ((6,4), (4,3), (3,2), (2,5), (5,1)); it is a path in G from node 6 to node 1

The blue path is ((6,4), (4,5), (5,1)); it is also a path in G from node 6 to node 1

EXAMPLE 8:1. Find the path

from Node 6 to Node 1.

2. Find the path from Node1 to Node 6.

CONNECTED GRAPH

A graph is connected if any two vertices can be joined by a path. If this is not possible then the graph is disconnected.

A bridge is an edge in a connected graph whose removal makes it disconnected.

EXAMPLE 9:Is the graph connected?If yes, find the bridge.

EXAMPLE 10:Is the graph connected?

EXAMPLE 11:Is the graph connected?

Representation of Graphs

1.Adjacency Matrix Representation2.Adjacency List Representation

Adjacency Matrix Representation• A graph may be represented by a two

dimensional adjacency matrix.• If G has n = |V| vertices, let M be an n by n matrix whose entries are defined by

EXAMPLE 12: Find the Adjacency Matrix Representation of the given graph

SOLUTION: Adjacency Matrix Representation of the given graph

Adjacency List Representation

The adjacency list structure is simply a linked version of the adjacency table.

EXAMPLE 13: Find the Adjacency List Representation of the given graph

SOLUTION: Adjacency List Representation of the given graph

Questions?

THANK YOU