Docsity

Understanding Graphs: Definition, Terminology, and Representations, Slides of Data Structures and Algorithms

Partial preview of the text

Download Understanding Graphs: Definition, Terminology, and Representations and more Slides Data Structures and Algorithms in PDF only on Docsity!

1

Algorithm & Data Structures

gy,

a E^ lExample:^ An edge e = (u,v) is a pair of verticesE: set of edges connecting the vertices in VV: set of vertices^ A graph G = (V,E) is composed of:^ What is a Graph?

{( (^) b) ( E= V= {a,b,c,d,e}b^ ) ( (^) d)

d (^) e c

docsity.co (d,e)}(b,e),(c,d),(c,e),{(a,b),(a,c),(a,d),

3

Applications

CS

electronic circuits

CS

communications) networks (roads, flights, karachi Maree^ LAXIslamabad Abbott

Lahore rabad Muza-

the in-degree of a vertex^ For directed graph,that vertex^ The degree of a vertex is the number of edges to Degree of a Vertex^ Terminology:

(^) v (^) is the number of edges

the out-degree of a vertexthat have (^) v (^) as the headthat have (^) v (^) as the head (^) v (^) is the number of edges

that have (^) v (^) as the tail

docsity.co

7

2 1^ Graphs: Example

(^376)

Legend 54 8

Directional path Bi-directional paths

simple path: no repeated vertices More Terminology

a c (^) b e c b

the first vertex cycle: (^) simple path, except that the last vertex is the same as d e

a c a c d ab d e

docsity.co

9

below has 3 connected components. connected component: maximal connected subgraph. E.g., the graph subgraph: subset of vertices and edges forming a graph connected path^ connected graph: any two vertices are connected by some•connected graph: any two vertices are connected by some Even More Terminology

not connected

d^ More…

h (^) h (^) l

forest - collection of treestree - connected graph without cycles for (^) est tree tree tree for (^) est

docsity.co^ tree

13

An undirected graph Directed vs. Undirected Graph

(^) is one in which the pair

An (^) undirected graph (^) is one in which the pair

of vertices in a edge is unordered, (v (^0) , v (^1) ) =

a directed pair of vertices <v A directed graph is one in which each edge is(v (^1) ,v (^0) ) (^) v > !=

a directed pair of vertices, <v head^ tail^0 , v^1 > != <v (^1) ,v (^0) >

Adjacency Lists Adjacency Matrix^ Graph Representations

docsity.co

15

If the edge (v i, vn by n array, say adj_mat The adjacency matrix of G is a two-dimensional Let G=(V,E) be a graph with n vertices.^ Adjacency Matrix

j ) is in E(G), adj_mat[i][j]=

need not be symmetricsymmetric; the adjacency matrix for a digraphsymmetric; the adjacency matrix for a digraph The adjacency matrix for an undirected graph is If there is no such edge in E(G), adj_mat[i][j]=

1 0^ Examples for Adjacency Matrix ⎣⎦ 1110 ⎢⎥ 1101 ⎢⎥ 00 ⎢⎥ 101110 ⎢⎥ 01 ⎡⎤ (^01113120) G 2 ⎣⎦ 0 ⎢⎥⎢⎥ 1 ⎢⎥ 0 ⎡⎤

G 123

docsity.co G^2