0% found this document useful (0 votes)
40 views

Graphs I

A graph is a data structure consisting of vertices and edges that connect vertices. Graphs can represent relationships between entities. There are different types of graphs including directed and undirected graphs. Properties of graphs include vertices, edges, degrees of vertices, adjacency, and neighborhoods. Graphs can model real-world networks and relationships.

Uploaded by

Tayyab Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Graphs I

A graph is a data structure consisting of vertices and edges that connect vertices. Graphs can represent relationships between entities. There are different types of graphs including directed and undirected graphs. Properties of graphs include vertices, edges, degrees of vertices, adjacency, and neighborhoods. Graphs can model real-world networks and relationships.

Uploaded by

Tayyab Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 32

GRAPHS

Chapter 10
Graphs and Graph Models

• Suppose that a network is made up of data centers


and communication links between computers.
• We can represent the location of each data center by
a vertex and each communications link by a line
segment (edge)
What is a graph?
• A structure that consists of a set of nodes (vertices) and a set of edges
that relate the nodes to each other.
• The set of edges describes relationships among the vertices.

Data Structure
Introduction
• A graph G consist of
1. Set of vertices V (called nodes), V = {v1, v2, v3, v4......} and
2. Set of edges E={e1, e2, e3......}
• A graph can be represented as G = (V, E), where V is a finite
and non empty set of vertices and E is a set of pairs of vertices
called edges
• Each edge ‘e’ in E is identified with a unique pair (a, b) of
nodes in V, denoted by e = {a, b}

Data Structure
Formal definition of graphs
• A graph G is :
G=(V,E)
V(G): a finite, nonempty set of vertices
E(G): a set of edges (pairs of vertices)

Data Structure
• Consider the following graph, G
• Then the vertex V and edge E can be represented as:
V = {v1, v2, v3, v4, v5, v6} and E = {e1, e2, e3, e4, e5, e6}
G = {(v1, v2) (v2, v3) (v1, v3) (v3, v4),(v3, v5) (v5, v6)}
• There are six edges and vertex in the graph

Data Structure
Applications
• Computer networks
– Local area network
– Wide area network
– Internet

• Databases
– Entity-relationship diagram

Data Structure
Applications
• Transportation networks
– Highway network
– Flight network

JFK

LAX STL
HNL
DFW
FTL
Data Structure
• Graphs can be classified as:

– Directed graphs
– Undirected graphs

Data Structure
Directed vs. Undirected Graphs
• When the edges in a graph have no direction,
the graph is called undirected

Data Structure
Directed vs. Undirected Graphs
• When the edges in a graph have a direction, the
graph is called directed (or digraph)

if the graph is directed,


the order of the vertices
in each edge is
important !!

E(Graph2) = {(1,3), (3,1), (5,9), (9,11), (5,7), (11,1),


Data(9,9)
Structure
Types of Undirected Graphs

Multigraphs
Simple Graphs
Simple Graph
• Definition: A graph in which each edge
connects two different vertices and where no
two edges connects the same pair of vertices
is called a “Simple Graph”.
Detroit
New York
San Francisco
Chicago
Denver Washington
Los Angeles
Multigraph
• A multigraph can have multiple edges (two or
more edges connecting the same pair of
vertices).
Detroit
New York
San Francisco
Chicago
Denver Washington
Los Angeles

There can be multiple telephone lines between two


computers in the network.
Loop
• A graph (not simple) may contain loops. An
edge e is a loop if e = {v, v} for some vV.
• Graph with multiple edges and loops is called
pseudo graph
Directed Graph
• A directed graph or digraph consists of a non-
empty set of vertices V and a set of “directed”
edges E.
• Each directed edge is associated with an
ordered pair of vertices
• The directed edge associated with the ordered
pair (u, v) is said to start at u and end at v.
Types of Directed Graphs

Directed
Multigraphs
Directed Graphs
Directed Graph
• When a directed graph has no loops and no
multiple directed edges, it is called simple
directed graph
Directed Multigraph
• A directed multigraph is a directed graph with
multiple edges between the same two distinct
vertices
• It may contain loops as well.
Graph Models
• Graphs can be used to model structures,
sequences, and other relationships.
• Example: the Web graph
• The World Wide Web can be modeled as a
directed graph where:
– Each Web page is represented by a vertex
– An edge starts at the Web page a and ends at
the Web page b if there is a link on a pointing
to b.
Precedence Graphs
• Computer programs can be executed more
rapidly by executing certain statements
concurrently
• It is important not to execute a statement that
requires results of statements not yet executed
– Each statement is represented by a vertex,
– There is an edge from one statement to a second
statement if the second statement cannot be
executed before the first statement
Precedence Graphs
Graph Terminology

• Two vertices, u and v in an undirected graph


G are called adjacent (or neighbors) in G, if
{u,v} is an edge of G.
• The vertices u and v are called endpoints of
edge {u,v}.
Neighborhood
• The set of all neighbors of a vertex v of G = (V ,E),
denoted by N(v), is called the neighborhood of v.

• What are the neighborhood of the vertices in graph


G?
Degree of a Vertex

• The degree of a vertex in an undirected


graph is the number of edges incident with it
• The degree of a vertex v is denoted by
deg(v).
• A vertex with a loop at it has at least degree 2
Example
c d
b

a g f e

• Find the degrees of all the vertices:


deg(a) = 2, deg(b) = 6, deg(c) = 4, deg(d) = 1,
deg(e) = 0, deg(f) = 3, deg(g) = 4
Degree of Vertex
• A vertex of degree zero is called “isolated”
– It is not adjacent to any other vertex
A vertex of degree 1 is called “pendant” vertex
Adjacent Vertices in Directed Graphs

When (u,v) is an edge of a directed graph G,


u is said to be adjacent to v and v is said to
be adjacent from u.

(u, v)

initial vertex terminal/end vertex


Degree of a Vertex
• In-degree of a vertex v
– the number of edges with v as their terminal vertex
– Denoted by deg(v)
• Out-degree of a vertex v
– the number of edges with v as their initial vertex)
– Denoted by deg+(v)
• A loop at a vertex contributes 1 to both the in-
degree and out-degree.
Example
Example
a c
b

e d f

Find the in-degrees and out-degrees of this digraph.


In-degrees: deg-(a) = 2, deg-(b) = 2, deg-(c) = 3,
deg-(d) = 2, deg-(e) = 3, deg-(f) = 0
Out-degrees: deg+(a) = 4, deg+(b) = 1, deg+(c) = 2,
deg+(d) = 2, deg+(e) = 3, deg+(f) = 0

You might also like