GRAPH
What is a Graph?
•
•
•
A graph G = (V,E) is composed of:
V: set of vertices
E: set of edges connecting the vertices in V
An edge e = (u,v) is a pair of vertices
Example:
a b
c
d e
V= {a,b,c,d,e}
E= {(a,b),(a,c),
(a,d),
(b,e),(c,d),(c,e),
(d,e)}
Applications
• electronic circuits
• networks (roads, flights, communications)
CS16
JFK
LAX STL
HNL
DFW
FTL
Terminology
Adjacency
Adjacent Vertices : if
there is an edge
between two vertices.
Adjacent edges : If the
is a common vertex
between two edges
Terminology
Degree
Is a Undirected
Graph number of
Vertices adjacent
To the vertex is
Known as degree
Terminology
Path
The path is a
Sequence of distinct
Vertices such that
Two consecutive
Vertices are adjacent
a b e d c
a b
c
d e
a b
c
d e
b e d c
Terminology
Cycle
A path that has
Only one repeated
Vertices are the first
and last vertices
a b
c
d e
a c d a
More…
•
•
tree - connected graph without cycles
forest - collection of trees
tree
forest
tree
tree
tree
Types of graph
finite Graph
A graph is said to
be finite where the
number of vertices
and edges are finite
in number
A
C D
B
E
Types of graph
Infinite Graph
In an infinite graph
the number of
vertices and
numbers of edges is
infinite
A B
C
E
D
F
Types of graph
Trivial Graph
The graph is said
to be trivial if there
is only a single
vertex without any
edges
A
Types of graph
Simple Graph
A graph is said to
be simple if there is
only one and one
edge between each
vertex
A
C D
B
Types of graph
Null Graph
The graph is said
to be a null graph If
there are only
vertices exits, not
edges
A B
C D
Types of graph
Complete Graph
The graph is a complete
graph where each vertex
must be connected with
other vertices using the
edges
A
C D
B
Types of graph
Directed Graph
The directed graph is a
graph where each edge
has a direction
associated with it
A
C D
B
Types of graph
Dis connected
Graph
A graph is said to be
disconnected where
each pair in the graph is
not connected
A
C
B
D
E
F
Graph representaion in data structure
There are two types of graph representation
1). Adjacency matrix representation
2). Adjacency list representation
1). Adjacency matrix representation
An adjacency matrix is used to represent adjacent
nodes in the graph. Two nodes are said to be adjacent
if there is an edge connecting them. We represent
graph in the form of matrix in Adjacency matrix
representation. For a graph G, if there is an edge
between two vertices a and b then we denote it 1 in
matrix. If there is no edge then denote it with 0 in
Continue
For Un-Directed graph
Mi,j = 1 if there is an edge between vertex i and j.
The direction does not matter here.
and Mi,j = 0 if there is no edge between vertex i and
j.
Mi,j not equal to Mj,i
Matrix Representation of Above Graph
Direct graph
Directed graph
Directed graph
Matrix representation of direct graph
Adjacency list representation
An adjacency list is another way to represented a
graph in the computer’s memory. This structure
consists of a list of all nodes in G. Every node is in
turn linked to its own list that contains the names of
all other nodes that are adjacent to it.

graphs presentation .pptx

  • 1.
  • 3.
    What is aGraph? • • • A graph G = (V,E) is composed of: V: set of vertices E: set of edges connecting the vertices in V An edge e = (u,v) is a pair of vertices Example: a b c d e V= {a,b,c,d,e} E= {(a,b),(a,c), (a,d), (b,e),(c,d),(c,e), (d,e)}
  • 4.
    Applications • electronic circuits •networks (roads, flights, communications) CS16 JFK LAX STL HNL DFW FTL
  • 5.
    Terminology Adjacency Adjacent Vertices :if there is an edge between two vertices. Adjacent edges : If the is a common vertex between two edges
  • 6.
    Terminology Degree Is a Undirected Graphnumber of Vertices adjacent To the vertex is Known as degree
  • 7.
    Terminology Path The path isa Sequence of distinct Vertices such that Two consecutive Vertices are adjacent a b e d c a b c d e a b c d e b e d c
  • 8.
    Terminology Cycle A path thathas Only one repeated Vertices are the first and last vertices a b c d e a c d a
  • 9.
    More… • • tree - connectedgraph without cycles forest - collection of trees tree forest tree tree tree
  • 10.
    Types of graph finiteGraph A graph is said to be finite where the number of vertices and edges are finite in number A C D B E
  • 11.
    Types of graph InfiniteGraph In an infinite graph the number of vertices and numbers of edges is infinite A B C E D F
  • 12.
    Types of graph TrivialGraph The graph is said to be trivial if there is only a single vertex without any edges A
  • 13.
    Types of graph SimpleGraph A graph is said to be simple if there is only one and one edge between each vertex A C D B
  • 14.
    Types of graph NullGraph The graph is said to be a null graph If there are only vertices exits, not edges A B C D
  • 15.
    Types of graph CompleteGraph The graph is a complete graph where each vertex must be connected with other vertices using the edges A C D B
  • 16.
    Types of graph DirectedGraph The directed graph is a graph where each edge has a direction associated with it A C D B
  • 17.
    Types of graph Disconnected Graph A graph is said to be disconnected where each pair in the graph is not connected A C B D E F
  • 18.
    Graph representaion indata structure There are two types of graph representation 1). Adjacency matrix representation 2). Adjacency list representation 1). Adjacency matrix representation An adjacency matrix is used to represent adjacent nodes in the graph. Two nodes are said to be adjacent if there is an edge connecting them. We represent graph in the form of matrix in Adjacency matrix representation. For a graph G, if there is an edge between two vertices a and b then we denote it 1 in matrix. If there is no edge then denote it with 0 in
  • 19.
    Continue For Un-Directed graph Mi,j= 1 if there is an edge between vertex i and j. The direction does not matter here. and Mi,j = 0 if there is no edge between vertex i and j. Mi,j not equal to Mj,i Matrix Representation of Above Graph
  • 20.
  • 21.
  • 22.
    Adjacency list representation Anadjacency list is another way to represented a graph in the computer’s memory. This structure consists of a list of all nodes in G. Every node is in turn linked to its own list that contains the names of all other nodes that are adjacent to it.