# Graphs: Graph Theory and Vertex

Graphs

1Introduction

We have studied one non-linear data structure so far i.e Trees. A graph is another non-linear data structure that is widely used to solve many real-life computing problems. For example, we need to use a graph to find out whether two places on a road-map are connected and what is the shortest distance between them. Graphs are used in simulating electrical circuits to find out current flows and voltage drops at various points in the circuit. Graphs are widely used in telephone and computer networks. Graphs have great historical significance too. In 1736, the famous mathematician Euler used the concept of a graph to solve the “Koenigsberg problem”. In the small town of Koenisberg in Prussia, the river Pregal flows around the island of Kneiphof and then divides into two. The four land areas ( A, B, C, D) bordering the river are connected by seven bridges ( a,b,c,d,e,f,g). The problem is to find out whether it is possible to start walking from some area, cross each bridge exactly once and return to the starting land area. Euler used graphs to prove that this would not be possible. A walk which achieves this is called an “Eulerian Walk”. {{{ Diagram }}}

In this chapter, we will study this data structure, its implementation and its applications. Before that, we will study some definitions and terminology.

Definitions and Terminology

Graph

A graph G is a collection of two sets V and E. V is a finite non empty set of vertices (or nodes) and E is a finite non empty set of edges (or arcs) connecting a pair of vertices. An edge is represented by two adjacent vertices G is represented as G = (V,E) Example

Some examples of graphs

Undirected Graph

A graph is an undirected graph if the pairs of vertices that make up the edges are unordered pairs.

i.e. an edge(Vi, Vj ) is the same as (Vj, Vi). The graph G1 shown above is an undirected graph.

Directed Graph

In a directed graph, each edge is represented by a pair of ordered vertices i.e. an edge has a specific direction. In such a case, edge (Vi, Vj) (Vj, Vi)

Example

Directed graph

G5=(V,E)

V={ V1, V2, V3, V4}

E ={ (V1, V2 ), (V1,V4), (V2, V4), (V1, V3) }

For an edge (Vi, Vj) in a directed graph, vertex Vi is called the tail and Vj is the head of the edge. Vi is adjacent to Vj and Vj is adjacent from Vi.

Complete Graph

If an undirected graph has n vertices, the maximum number of edges it can have is nC2 = n (n-1) / 2. If an undirected graph G has ‘n’ vertices and nC2 edges, it is called a complete graph. If the graph G is directed and has n vertices, G is complete if it has n(n-1) edges.

Multigraph

A multigraph is a graph in which the set of edges may have multiple occurrences of the same edge. Note that it is not a graph.

Degree of Vertex

The degree of a vertex in an undirected graph is the number of edges incident to that vertex. In the undirected graph G1, the degree of each vertex = 2.

Indegree of a Vertex

If G is a directed graph, the indegree of a vertex is the number of edges for which it is head i.e. the numbers edges coming to it. Example In graph G5,indegree (V4)=2

indegree (V1)=0

A node whose indegree is 0 is called a source node.

Outdegree of a vertex

If G is directed graph, the out degree of a vertex is the number of edges for which it is the tail i.e. the number of edges going out of it. Exampleoutdegree (V1)=3

outdegree (V2)=1

A node whose outdegree is 0 is called a sink node.

Adjacent vertices

If (Vi, Vj) is an edge in G, then we say that Vi and Vj are adjacent and the edge (Vi, Vj) is incident on Vi and Vj.

Path

A path from vertex Vp to Vq exists if there exists vertices Vi1, Vi2, …..Vin such that there exist edges (Vp, Vi1) , (Vi1, Vi2),………(Vin, Vq) Length of a Path

The length of a path is the number of edges on it.

Linear Path

A linear path is a path whose first and last vertices are distinct. Cycle

A cycle is a path...

Please join StudyMode to read the full document