14
GRAPH: Graph: A graph G consists of a non-empty set V called the set of nodes (or vertices) of the graph, a set E which is the set of edges of the graph and a mapping relation V E, of the set of edges E to a set of pairs of elements of V. Both sets V and E are finite. G = (V, E) Isolated Node: In a graph, a node which is not adjacent to any other node is called isolated node. Parallel Edges: If a pair of nodes is joined by more than one edge then these edges are called parallel edges. Ex: Directed Graph: A graph in which every edge is directed is called a directed graph or a digraph Ex:

Data Structure Lecture Notes

Embed Size (px)

DESCRIPTION

Lecture notes of graph theory

Citation preview

Page 1: Data Structure Lecture Notes

GRAPH:

Graph: A graph G consists of a non-empty set V called the set of nodes (or vertices) of the graph, a set E which is the set of edges of the graph and a mapping relation V E, of the set of edges E to a set of pairs of elements of V.

Both sets V and E are finite. G = (V, E)

Isolated Node:

In a graph, a node which is not adjacent to any other node is called isolated node.

Parallel Edges:

If a pair of nodes is joined by more than one edge then these edges are called parallel edges.

Ex:

Directed Graph:

A graph in which every edge is directed is called a directed graph or a digraph

Ex:

Indegree of a node:

In a directed graph, for any node V the number of edges which have V as final node is called indegree of that node.

Outdegree of In a directed graph, for any node V, the number of edges which have V as their initial node is

Page 2: Data Structure Lecture Notes

a node: called the outdegree of a node.

Page 3: Data Structure Lecture Notes

Total Degree of a node:

The sum of outdegree and indegree of a node is called the total degree of a node.

Loop: An edge of a graph which joins a node to itself is called a loop or a sling.

The direction of a loop has no significance, hence it can be considered directed or undirected.

Weighted Graph:

A graph in which weights are assigned to every edge is called a weighted graph.

Path of a graph:

In a sequence of edges of a directed graph, the terminal node of any edge In the sequence is the initial node of the edge appearing next in the sequence.

Simple Path or Edge Simple:

A path in a directed graph in which the all the edges are distinct is called a simple path or edge simple path.

Elementary Path or Node Simple:

A path in which all the nodes through which it traverses are distinct is termed as an elementary path.

Null graph: A graph containing only isolated nodes is called a null graph.

Simple Graph: A graph in which there is no more than one edge between a pair of nodes is called a simple graph.

Mixed Graph: A graph in which some edges are directed and some edges are undirected is called a mixed graph.

Multi Graph: Any graph which contains some parallel edges is termed as a multi graph.

Length of a path:

The number of edges appearing in the sequence of a path is called the length of a path.

Page 4: Data Structure Lecture Notes

Cycle: A path which originates and ends in the same node is called a cycle.

Acyclic Graph:

A simple digraph which does not contain any cycles is called an acyclic graph.

Page 5: Data Structure Lecture Notes

TREE:

Tree: A directed tree is an acyclic digraph which has one node called its root having indegree zero and all other nodes having indegree 1.

Terminal node or Leaf:

Any node which has an outdegree zero is called a terminal node or a leaf.

All other nodes are called branch nodes.

Degree of Tree:

It is defined as the maximum of degree of the nodes in the tree.

M- ary Tree: In a directed tree the outdegree of every node is less than or equal to m then it is called m- ary tree.

Completely m-ary tree:

If the outdegree of a node is exactly equal to m or zero and the number of nodes at level I is mi-1 then the tree is called a complete m-ary tree.

Binary Tree: A binary tree is a finite set of elements that is either empty or it is partitioned into 3 disjoint subsets.

First Subset containing the root of the tree. The other two subsets are themselves binary

trees called left and right subtrees of the original tree.

(These two can be empty.)

Depth of a binary tree:

The depth of a binary tree is the maximum level of any leaf in the tree.

It is denoted by d.

Strictly Binary Tree:

Every non-leaf node in binary tree has non-empty left and right subtree then the tree is called a strictly binary tree.

Completely Binary Tree:

If it is strictly binary tree of depth d and all leaves are at level n for m= 2 the tree is called complete binary tree.

Page 6: Data Structure Lecture Notes

Almost Complete Binary Tree:

A binary tree of depth d is an almost complete binary tree.

Solve the following examples by finding the simple and elementary paths for each of them:

Page 7: Data Structure Lecture Notes
Page 8: Data Structure Lecture Notes
Page 9: Data Structure Lecture Notes

Find the DFS path for the following graphs by first converting them to spanning trees:

Page 10: Data Structure Lecture Notes

Example showing a Breadth First Search Path: Find BFS path from A to I

Using Open and Closed list method we have,

Step 0:

Open List – AClosed List – empty

Step 1:

Open List – B, CClosed List – A

Step 2:

Open List – C, DClosed List – A, B

Step 3:

Open List – D, E, FClosed List – A, B, C

Page 11: Data Structure Lecture Notes

Step 4:

Open List – E, FClosed List – A, B, C, D

Step 5:

Open List – F, G, HClosed List – A, B, C, D, E

Step 6:

Open List – G, HClosed List – A, B, C, D, E, F

Step 7:

Open List – HClosed List – A, B, C, D, E, F, G

Step 8:

Open List – IClosed List – A, B, C, D, E, F, G, H

Step 9:

Open List – emptyClosed List – A, B, C, D, E, F, G, H, I

Hence the BFS path from A to I is {A – B – C – D – E – F – G – H – I}

Ans.