0% found this document useful (0 votes)
112 views

4th Assignment

The document contains a homework assignment with 7 questions related to graph theory and algorithms. The homework includes drawing graphs from incidence and adjacency matrices, finding indegree/outdegree, shortest path matrices, breadth-first search algorithms, and hash functions. The student provided thorough answers to each question, showing work for problems involving matrices, graphs, and algorithms.

Uploaded by

Nitin Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views

4th Assignment

The document contains a homework assignment with 7 questions related to graph theory and algorithms. The homework includes drawing graphs from incidence and adjacency matrices, finding indegree/outdegree, shortest path matrices, breadth-first search algorithms, and hash functions. The student provided thorough answers to each question, showing work for problems involving matrices, graphs, and algorithms.

Uploaded by

Nitin Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 8

Homework Title / No.

: _______4th______________________________Course Code : ____cse205

Course Instructor : ________MR.MANOJ KUMAR___ Course Tutor (if applicable) :


____________

Date of Allotment : _____________________ Date of submission : ____5/07/2010_____________

Student’s Roll No.____A06___________________ Section No. : ____C1803


Declaration:
I declare that this assignment is my individual work. I have not copied from any other
student’s work or from any other source except where due acknowledgment is made
explicitly in the text, nor has any part been written for me by another person.
Student’s Signature :
NITIN
GUPTA
Evaluator’s comments:
_____________________________________________________________________

Marks obtained : ___________ out of ______________________

Content of Homework should start from this page only:


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)

Graph:

Adjacency matrix A:
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

(i) Find indegree and outdegree of each node.


(ii) Find the weight matrix W of G.

Ans) (i) Data Indegree Outdegree


X 2 1
Y 2 2
S 1 3
T 2 1

(ii)

W=

Q3) Find the matrix Q of shortest paths using Warshall’s algorithm for
the graph given in Q2.

Ans
Q0 =

Using A

Q1 =

Using A & B

Q2 =

Using A,B &C

Q3 =

Using A,B,C &D


Q4 =

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) Many graph algorithms require one to systematically examine the nodes and edges
of a graph G. there are two standard ways that this is done. One way is called a breadth-first
search , and the other is called a depth-first search. The breadth-first search will use a queue
as an auxiliary structure to hold for future processing and analogously.

Algorithm for breadth-first:


This algorithm executes a breadth-first search on a graph G beginning at a starting
node A.

1.Initialize all nodes to ready state(STATUS=1).


2.Put the starting node A in QUEUE and change its status to the waiting
state(STATUS=2).
3.Reapeat steps 4 and 5 until QUEUE is empty:
4.Remove the front node N of QUEUE. Process N and change the status of N to the
processed state(STATUS=3).
5.Add to the rear of QUEUE all the neighbors of N that are in the steady state
(STATUS=1), and change their status to the waiting state (STATUS=2).
[end of step 3 loop].
6.Exit.

Q5) Consider this graph:


v0 ----- v2
/\
/ \
-> v1 <-/ \-> v4
/ \
/ \
/ \->v3 -------> v5
/ /
/ /
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) Depth first Search:

Taking v0 as the starting vertex:-

1. Pushing v1, v2 and v4

2. Pushing v3.

3. Pushing v5 and v6.

The result we get is..by poping the above i.e v6, v5, v3, v4, v2 and v1.

Breadth First Search:

In this the transversal is done as in queue.

The traversal would be as- v0, v2, v4,v1, v3, v5 and v6.

Q6)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) Graph:
Incidence matrix:

M =

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)Mid square method c)the folding method without reversing
Ans)
a) 9614%97 = 11
5882%97 = 62
6713%97 = 20
4409%97 = 44
1825%97 = 79

b) 9614*9614 = 92428996 = 28
5882*5882 = 34597924 = 97
6713*6713 = 45064369 = 64
4409*4409 = 19439281 = 39
1825*1825 = 3330625 = 30

c) 9614 = 96+14 = 110 = 10(1(carry) is neglected)


5882 = 58+82 = 140 = 40(1(carry) is neglected)
6713 = 67+13 = 80 = 80
4409 = 44+09 = 53 = 53
1825 = 18+25 = 43 = 43

You might also like