CSE- 2050
DATA STRUCTURE
ANS.1
INCIDENCE MATRIX:- incidence matrix is defined as a matrix in which we assign value 1 if
node Vi belongs to edge Ej otherwise zero. Mathematically.
Now from above graph we can find adjency matrix which is given by:
1 1 1 1 1
1 1 1 0 1
1 1 1 0 1
1 0 0 1 1
1 1 1 1 1
2. Consider the weighted graph G, and assume the nodes are stored in an array
DATA as follows:
DATA:X, Y, S, T
7
X 3 Y
1
6 2
4
T S
5
(i) Find indegree and outdegree of each node.
ANS.2
0 7 0 0
W= 3 0 0 2
6 1 0 4
0 0 5 0
Q3.) Find the matrix Q of shortest paths using Warshall’s algorithm for the
graph given in Q2.
Ans.
Using warshall’s algorithm we get shortest path between node X and S as
follows:
7 2 5
X Y T S
Is the required shortest path which traverse all nodes of the given graph.
Part-B
Q4.) The Web can be modeled as a directed graph. Come up with a graph
traversal algorithm. Make the algorithm non-recursive and breadth-first.
Ans.4 Many real-world problems can be modeled using graphs. For example,
search engines model the Internet as a graph, where Web pages are the nodes in
the graph and the links among Web pages are the edges. Programs like
Microsoft MapPoint that can generate driving directions from one city to
another use graphs, modeling cities as nodes in a graph and the roads
connecting the cities as edges.
The edges of a graph provide the connections between one node and another.
By default, an edge is assumed to be bidirectional. That is, if there exists an
edge between nodes v and u, it is assumed that one can travel from v to u and
from u to v. Graphs with bidirectional edges are said to be undirected graphs,
because there is no implicit direction in their edges.
For some problems, though, an edge might infer a one-way connection from
one node to another. For example, when modeling the Internet as a graph, a
hyperlink from Web page v linking to Web page u would imply that the edge
between v to u would be unidirectional. That is, that one could navigate
from v to u, but not from u to v. Graphs that use unidirectional edges are said to
be directed graphs.
When we traverse above graph in depth first search with node v0 as root
then we get following order. We first traverse depth wise inspite of
complete level.
Ans, 6
1) Graph is
1
2 4
5 3
Incidence matrix-:
0 1 0 1 0
1 0 0 0 1
0 0 0 1 1
1 0 1 0 1
0 1 1 1 0
Q7.) Consider the following 4-digit employee number:
9614, 5882,6713,4409,1825
Find 2-digit hash address of each using
a) the division method with m=97;
b)midsquare method c)the folding method without reversing.
b) Mid-square method
i) 9614 = (61)^2
= 3721
Hence, 3721 is the location
ii) 5882 = (88)^2
= 7744
Hence, 7744 is the location
iii) 6713 = (71)^2
= 5041
Hence, 5041 is the location
iv) 4409 = (40)^2
= 1600
Hence, 1600 is the location
vi) 1825 = (82)^2
= 6724
Hence, 6724 is the location