Data Structure Lecture Notes

Page 1

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 a node:

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


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.

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.


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:

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.

Any node which has an outdegree zero is called a terminal node or a leaf. All other nodes are called branch nodes.

• 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.

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:




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


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 – A Closed List – empty Step 1: Open List – B, C Closed List – A Step 2: Open List – C, D Closed List – A, B Step 3: Open List – D, E, F Closed List – A, B, C


Step 4: Open List – E, F Closed List – A, B, C, D Step 5: Open List – F, G, H Closed List – A, B, C, D, E Step 6: Open List – G, H Closed List – A, B, C, D, E, F Step 7: Open List – H Closed List – A, B, C, D, E, F, G Step 8: Open List – I Closed List – A, B, C, D, E, F, G, H Step 9: Open List – empty Closed 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.


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.