Presentation is loading. Please wait.

Presentation is loading. Please wait.

GRAPHS.

Similar presentations


Presentation on theme: "GRAPHS."— Presentation transcript:

1 GRAPHS

2 Definition A graph is an abstract data type that is meant to implement the undirected graph and directed graph concepts from mathematics. A graph data structure consists of a finite (and possibly mutable) set of vertices or nodes or points, together with a set of unordered pairs of these vertices for an undirected graph or a set of ordered pairs for a directed graph. These pairs are known as edges, arcs, or lines for an undirected graph and as arrows, directed edges, directed arcs, or directed lines for a directed graph. The vertices may be part of the graph structure, or may be external entities represented by integer indices or references.

3 Definition A graph G = (V, E) is composed of:
V: set of vertices E: set edges connecting the vertices in V An edge e=(u, v) is a pair of vertices V = {a,b,c,d,e} E = {(a,b), (a,c), (a,d), (b,e), (c,d), (c,e), (d,e)} a c d b e

4 Applications Electric circuits Networks Roads Flights Communications

5 Basic Operations Basic primary operations of a Graph −
Add Vertex − Adds a vertex to the graph. Add Edge − Adds an edge between the two vertices of the graph. Display Vertex − Displays a vertex of the graph.

6 Graph Representations
Graphs are represented using following representations: Adjacency Matrix Incidence Matrix Adjacency List

7 Adjacency Matrix

8 Adjacency Matrix

9 Incidence Matrix

10 Adjacency List

11 Adjacent and Incident If (v0, v1) is an edge in an undirected graph,
v0 and v1 are adjacent The edge (v0, v1) is incident on vertices v0 and v1 If < v0, v1 > is an edge in a directed graph v0 is adjacent to v1, and v1 is adjacent from v0 The edge < v0, v1 > is incident on v0 and v1

12 Degree of Vertex The degree of a vertex is the number of edges incident to that vertex For directed graph, The in-degree of a vertex v is the number of edges that have v as the head The out-degree of a vertex v is the number of edges that have v as the tail If di is a degree of a vertex i in a graph G with n vertices and e edges, the number of edges is 𝑒 =( 𝑘=0 𝑛−1 𝑑𝑖 )/2

13 Path Sequence of vertices v1, v2, v3,… vn such that consecutive vertices vi and vi+1 are adjacent simple path : no repeated vertices cycle path : simple path, except that the last vertex is the same as the first vertex a c d b e

14 Graph types connected graph : any two vertices are connected by some path sub graph : subset of vertices and edges forming a graph connected component : maximal connected subgraph tree : connected graph without cycles forest : collection of trees

15 Connectivity Let n = # of vertices and m = # of edges
A complete graph one in which all pairs of vertices are adjacent Each of n vertices incident to n-1 edges, however each edge counted twice. Therefore m=n(n-1)/2 If a graph is not complete m<n(n-1)/2 If m<n-1 Graph is not connected

16 Directed vs. Undirected
An undirected graph is one which the pair of vertices are not ordered, (v0, v1)=(v1, v0) A directed graph is one which each edge is a directed pair of vertices, < v0, v1 > != < v1, v0 >

17 Dijktra’s shortest path Algorithm

18 Dijktra’s algorithm between 2 nodes

19 Dijkstra’s algorithm based on Euclidean distance


Download ppt "GRAPHS."

Similar presentations


Ads by Google