documentd

9
CSE 2050 Assignment-4 Submitted To: Submitted by: Mr. Munish Kumar Gaurav Sharma RB6803A24 10800582

Upload: gaurav-sharma

Post on 30-Oct-2014

7 views

Category:

Documents


4 download

DESCRIPTION

s

TRANSCRIPT

Page 1: Documentd

CSE 2050

Assignment-4

Submitted To: Submitted by:

Mr. Munish Kumar Gaurav Sharma

RB6803A24

10800582

Page 2: Documentd

Part A:

Q1:

Following is the incidence matrix M of an undirected graph G:

0 0 1 0 0 1 1 1

0 1 0 1 0 0 1 0

1 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 7

1 3

(2 & 3 are connected. A straight line made this graph

look confusing so I used a discontinuous line.)

The adjacency matrix is as:

Page 3: Documentd

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

6 2

5

(i) Find indegree and outdegree of each node.

(ii) Find the weight matrix W of G.

Ans:

Node Indegree Outdegree

X 2 1

Y 2 2

S 1 3

T 2 1

1

4

Page 4: Documentd

Matrix W is:

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

Ans: Warshall’s algorithm matrix for this question is

0 7 0 0

3 0 0 0

0 0 0 4

0 0 5 0

Page 5: Documentd

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

user’s 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 <-/ \-> v4

/ \

/ \

/ \->v3 -------> v5

/ /

/ /

v6 <---------/

Page 6: Documentd

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:

0 1 0 1 0

A = 1 0 0 1 1

0 0 0 1 1

1 1 1 0 1

0 1 1 1 0

Draw a graph G and find its incidence matrix M.

Ans:

The graph is:

0

1 3

4

2

The incidence matrix is:

Page 7: Documentd

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,1825Find 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