View the step-by-step solution to:

Question

# Build a class MyGraph to implement a Graph ADT(Abstract Data Type) using Adjacency Matrix with the following

functions. I would encourage to use numpy library for matrix operations:

a.Make construction which takes a parameter n. The function should make an adjacency matrix of n x n

size.

b. Make function AddUndirectEdge which takes two parameters src and dst and make an undirected edge

between src and dst.

c. Make function AddDirectedEdge which takes two parameters src and dst and make a directed edge

between src and dst.

d. Make function AddUndirectWegihtEdge which takes three parameters src , dst, and w and make an

undirected edge between src and dst with weight w.

e. Make function AddDirectedWegihtEdge which takes three parameters src , dst, and w and make a

directed edge between src and dst with weight w.

f. Make function IsEdge which takes two parameters src and dst and returns True if there is an edge

between src and dst, otherwise returns false.

g. Make function IsPath which takes two parameters src and dst and returns True if there is a path

between src and dst, otherwise returns False.

h. Make function ReadGraph which takes a parameter filename to read the graph from the file and returns

an object of MyGraph instance to represent that graph.

The format of file is given below:

The first line of the file contains one integer N. The next N lines contain N integers separated by space

Example 1: A graph with three vertices

3

0 1 1

1 0 1

1 1 0

Example 2: A graph with 2 vertices

2

0 1

1 0

Example 3: a graph with three vertices

3

0 5 0

4 0 2

3 2 0

@@@@@@@@@@@   Code Template:  @@@@@@@@@@@@

import numpy as np

class MyGraph:

def __initialize__(self, n):

pass

pass

pass

pass

pass

def IsEdge(self, src, dst):

pass

def IsPath(self, src, dst):

pass

pass

### Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

• ### -

Study Documents

Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

Browse Documents