Download presentation
Presentation is loading. Please wait.
1
Graphs By Rajanikanth B
2
Basic Terminology Representation Search BFS & DFS
3
Introduction A graph G is simply a set V of vertices and a collection E of pairs of vertices from V, called edges. Some books use different terminology for graphs and refer to what we call vertices as nodes and what we call edges as arcs.
4
Edges in a graph are either directed or undirected.
An edge (u,v) is said to be directed from u to v if the pair (u,v) is ordered, with u preceding v. An edge (u,v) is said to be undirected if the pair (u,v) is not ordered. Undirected edges are sometimes denoted with set notation, as {u,v}, but for simplicity we use the pair notation (u,v), noting that in the undirected case (u,v) is the same as (v,u).
5
If all the edges in a graph are undirected, then we say the graph is an undirected graph.
a directed graph, also called a digraph, is a graph whose edges are all directed. A graph that has both directed and undirected edges is often called a mixed graph.
6
vertices 1 5 4 3 2 1 5 4 3 2 Edges Directed Edge
7
The two vertices joined by an edge are called the end vertices (or endpoints) of the edge.
If an edge is directed, its first endpoint is its origin and the other is the destination of the edge. Two vertices u and v are said to be adjacent if there is an edge whose end vertices are u and v. An edge is said to be incident on a vertex if the vertex is one of the edge’s endpoints. The outgoing edges of a vertex are the directed edges whose origin is that vertex. The incoming edges of a vertex are the directed edges whose destination is that vertex.
8
1 5 4 3 2 1 5 4 3 2 adjacent Incident 3 Incoming Edges 2
Outgoing Edges 2
9
Degree of 3 is 3 Degree of 4 is 2
The degree of a vertex v, denoted deg(v), is the number of incident edges of v. The in-degree and out-degree of a vertex v are the number of the incoming and outgoing edges of v, and are denoted indeg(v) and outdeg(v), respectively. Degree of 3 is 3 1 5 4 3 2 In Degree of 3 is 2 Out Degree of 3 is 1 Degree of 4 is 2 In Degree of 4 is 1
10
Allowing for two undirected edges to have the same end vertices, and for two directed edges to have the same origin and the same destination. Such edges are called parallel edges or multiple edges. e3 A C B D e4 e5 e1 e2
11
An edge (undirected or directed) is a self-loop if its two endpoints coincide
A graphs do not have parallel edges or self-loops such graphs are said to be simple. A path is a sequence of alternating vertices and edges that starts at a vertex and ends at a vertex such that each edge is incident to its predecessor and successor vertex.
12
e2 A C B D e3 self-loop e4 e5 e1 A C B D simple
13
Graph Representation 1. Adjacency Matrix 2. Incidence Matrix 3. Adjacency List
14
1. Adjacency Matrix A B C D A 1 1 A C B D B 1 1 1 1 1 C D 1 1 1 1
15
1. Adjacency Matrix A B C D A 1 1 A C B D B 1 1 C D 1 1
16
2. Incidence Matrix e1 e2 e3 e4 e5 A 1 1 B -1 1 1 -1 -1 C D -1 -1 1 e1
A C B D B -1 1 1 e3 e5 e2 -1 -1 C e4 D -1 -1 1
17
2. Adjacency List A B D A C B D B C D C D C D
18
2. Adjacency List A B D A D B C B D C A B D D A
19
3. Adjacency List A D B C A B C D B D D A B D A
20
BFS A B C D E F G H I A D E B G C F H I
21
Result of BFS A B C D E F G H I
22
DFS B C A D E F I E H C G F I G H D B A
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.