Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Graph  A graph consists of a set of vertices, and a set of edges that link together the vertices.  A graph can be: Directed: Edges are.

Similar presentations


Presentation on theme: "Introduction to Graph  A graph consists of a set of vertices, and a set of edges that link together the vertices.  A graph can be: Directed: Edges are."— Presentation transcript:

1 Introduction to Graph  A graph consists of a set of vertices, and a set of edges that link together the vertices.  A graph can be: Directed: Edges are directed. Undirected: Edges are undirected Data Structure and Algorithm

2 Undirected Graph A graph G = (V, E) V: vertices
E : edges, unordered pairs of vertices from V  V (u,v) is same as (v,u) Thus |E| <= |V| (|V|-1)/2 A O N M L K J E F G H D C B I P Data Structure and Algorithm

3 Directed Graph A graph G = (V, E) V: vertices
E : edges, ordered pairs of vertices from VV (u,v) is different from (v,u) Thus |E| <= |V| (|V|-1) A E F G H D C B I Data Structure and Algorithm

4 Graph in Application Internet: web graphs Each page is a vertex
Each edge represent a hyperlink Directed GPS: highway maps Each city is a vertex Each freeway segment is an undirected edge Undirected Data Structure and Algorithm

5 Using Adjacency Matrix Using Adjacency List
Representing Graphs Using Adjacency Matrix Using Adjacency List Data Structure and Algorithm

6 Adjacency Matrix Representation
Example: A 1 2 3 4 1 2 4 3 a d b c An adjacency matrix represents the graph as a n x n matrix A: A[i, j] = 1 if edge (i, j)  E (or weight of edge) = 0 if edge (i, j)  E Space Complexity: O(V2) Data Structure and Algorithm

7 Adjacency List Representation
1 2 3 4 2 3 1 2 4 3 a d b c 3 3 Space Complexity: O(V+E) Data Structure and Algorithm


Download ppt "Introduction to Graph  A graph consists of a set of vertices, and a set of edges that link together the vertices.  A graph can be: Directed: Edges are."

Similar presentations


Ads by Google