DS Lecture 22 (Intro To Graphs)
DS Lecture 22 (Intro To Graphs)
Lecture # 22
Introduction to graphs
Summiya Alam
INTRODUCTION TO GRAPHS
Graph theory plays an important role in several areas of computer science such as:
• Switching theory and logical design
• Artificial intelligence
• Formal languages
• Computer graphics
• Operating systems
• Compiler writing
• Information organization and retrieval.
GRAPH
A graph is a non-empty set of points called vertices and a set of line segments
joining pairs of vertices called edges.
• An edge connects either one or two vertices called its endpoints (edge e1
connects vertices v1 and v2 described as {v1, v2} i.e. v1 and v2 are the
endpoints of an edge e1).
• An edge with just one endpoint is called a loop. Thus a loop is an edge that
connects a vertex to itself (e.g., edge e6 makes a loop as it has only one
endpoint v3).
• Two vertices that are connected by an edge are called adjacent; and a vertex
that is an endpoint of a loop is said to be adjacent to itself.
SOME TERMINOLOGY
• Define the following graph formally by specifying its vertex set, its edge set,
and a table giving the edge endpoint function.
EXAMPLE
SOLUTION:
• Vertex Set = {v1, v2, v3, v4}
• Edge Set = {e1, e2, e3}
• Edge - endpoint function is:
EXAMPLE
• Draw picture of Graph H having vertex set {v1, v2, v3, v4, v5} and edge set
{e1, e2, e3, e4} with edge endpoint function
e1
v5
v1 v2
v3 v4
DRAWING PICTURE FOR A GRAPH
SIMPLE GRAPH:
EXERCISE
EXERCISE
DEGREE OF A VERTEX
Let G be a graph and v a vertex of G. The degree of v, denoted deg(v), equals the
number of edges that are incident on v, with an edge that is a loop counted twice.
Note:
(i)The total degree of G is the sum of the degrees of all the vertices of G.
(ii) The degree of a loop is counted twice
DEGREE OF A VERTEX
• EXAMPLE:
COMPLETE GRAPH