You are on page 1of 7

CSE 2050 Assignment-4

Submitted To: Mr. Munish Kumar

Submitted by: Gaurav Sharma RB6803A24 10800582

Part A: Q1: Following is the incidence matrix M of an undirected graph G: 0 0 1 0 1 0 0 1 1 1 1 0 1 0 0 1 0 0 1 1 0 0 0 0

0 0 0 0 1 0 0 1 1 1 0 0 1 1 0 0 Draw G and find its adjacency matrix A. Ans: The graph G is as follows: 0 2 4 5

6 1

7 3

(2 & 3 are connected. A straight line made this graph look confusing so I used a discontinuous line.) The adjacency matrix is as:

1 0 1 0 1 1 1 1

0 1 0 1 1 0 1 0

1 0 1 1 0 0 0 0

0 1 1 1 0 0 0 1

1 1 0 0 1 1 0 0

1 0 0 0 1 1 0 0

1 1 0 0 0 0 1 0

1 0 0 1 0 0 0 1

Q2: Consider the weighted graph G, and assume the nodes are stored in an array DATA as follows: DATA:X, Y, S, T 7 3 1 6 4 2

5 (i) Find indegree and outdegree of each node. (ii) Find the weight matrix W of G.

Ans: Node X Y S T Indegree 2 2 1 2 Outdegree 1 2 3 1

Matrix W is: 0 W= 3 6 0 7 0 1 0 0 0 0 5 0 2 4 0

Q3: Find the matrix Q of shortest paths using Warshalls algorithm for the graph given in Q3. Ans: Warshalls algorithm matrix for this question is

0 3 0 0

7 0 0 0

0 0 0 5

0 0 4 0

Part-B 4. 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: The web can be modeled as a directed graph in so many ways. The first example is the surfing techniques of the net. When we open the single website there are a number of pages in a single website, for example: We take example of Facebook. This is a website, where each user is on social networking. This website has a number of pages like profile info, wall posts, Photos etc. when we move from one page to other, we are directed from one page to the other of the web. This represents a directed graph of the web. There are other security features which block some certain users from accessing the other users data. This, in a way is a restricted direction graph. As such, some users can be blocked access to some parts of the web. In a way, we are connecting unidirectional to the web. When we click a link, the web page opens. So, we are redirected from hyperlink to the page. As such, this is a directional graph. So we can say that the web is a directed graph.

5. Consider this graph: v0 ----- v2 /\ / \ -> v1 <-/ / / / / / \ \ \->v3 -------> v5 / / \-> v4

v6 <---------/ In what order are the vertices visited for a depth-first search that starts at v0? In what order are the vertices visited for a breadth-first search that starts at v0? Ans: a. When we apply depth first search, the order is:v0,v1,v3,v6,v5,v4,v2

b. When we apply breadth first search:v0, v1, v4, v2, v3, v6, v5,

6. Following is the adjacency matrix M of an undirected graph G: 01010 A= 10011 00011 11101 01110 Draw a graph G and find its incidence matrix M. Ans: The graph is: 0 1 4 3

2 The incidence matrix is: 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

7. 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
Ans: The address of 9614 is 37*9614=355718 5882- 5882*97= 570554 6713- 6713*97=651161 4409- 4409*97= 427673

You might also like