Question

In: Computer Science

Please provide Python 3.7 implementation of Graph ADT using in-built structure List only (not using dict)....

Please provide Python 3.7 implementation of Graph ADT using in-built structure List only (not using dict).

Basic structure of graph will be:

Node = []

Edges = [ [ ] , [ ] ]

Also provide method to print the graph along with all path

Solutions

Expert Solution

Please note that we ave implemented ge graph in the form o adjacency lst

#graph class

class Graph:

nodes = [] #holds nodes

edges = [] #holds edges

#utility to add vertex to the nodes list

def addVertex(self, v):

self.nodes.append(v)

self.edges.append([])

#utility to add an edge into the Graph#that actually mean inserting (u,v) mean inserting v in neighbour list of u

def addEdge(self, u, v):

#fin the index o the node u in the nodes

idx = self.nodes.index(u)

#checks the validity of index

if idx in range(len(self.nodes)):

self.edges[idx].append(v)

#utility to print the graph in the adjacency list

def print(self):

for i in range(len(self.nodes)):

print("{}: ".format(self.nodes[i]), end="")

for j in range(len(self.edges[i])):

print("{}->".format(self.edges[i][j]), end="")

print()

def main():

graph = Graph()

graph.addVertex(10)

graph.addVertex(20)

graph.addVertex(30)

graph.addVertex(40)

graph.addEdge(10, 20)

graph.addEdge(10, 30)

graph.addEdge(20, 40)

graph.addEdge(40, 20)

graph.addEdge(20, 30)

graph.addEdge(40, 10)

graph.print()

if __name__ == main():

main()


Related Solutions

1. Implement the graph ADT using the adjacency list structure. 2. Implement the graph ADT using...
1. Implement the graph ADT using the adjacency list structure. 2. Implement the graph ADT using the adjacency matrix structure. LANGUAGE IS IN JAVA Comment for any questions Data structures and algorithms
Java The List ADT has an interface and a linked list implementation whose source code is...
Java The List ADT has an interface and a linked list implementation whose source code is given at the bottom of this programming lab description. You are to modify the List ADT's source code by adding the method corresponding to the following UML: +hasRepeats() : boolean hasRepeats() returns true if the list has a value that occurs more than once in the list hasRepeats() returns false if no value in the list occurs more than once in the list For...
Java The List ADT has an interface and a linked list implementation whose source code is...
Java The List ADT has an interface and a linked list implementation whose source code is given at the bottom of this programming lab description. You are to modify the List ADT's source code by adding the method corresponding to the following UML: +hasRepeats() : boolean hasRepeats() returns true if the list has a value that occurs more than once in the list hasRepeats() returns false if no value in the list occurs more than once in the list For...
Write an array-based implementation of the ADT list that expands the size of the array of...
Write an array-based implementation of the ADT list that expands the size of the array of list entries as needed so that the list can always accommodate a new entry. Also reduce the size of the array as needed to accommodate several removals. When the size of the array is greater than 20 and the number of entries in the list is less than half the size of the array, reduce the size of the array so that it is...
In C++ write an implementation of the ADT sorted list that uses a resizable array (vector...
In C++ write an implementation of the ADT sorted list that uses a resizable array (vector class of C++ STL) to represent the list items.
Focuses on the design, development, implementation, and testing of a Python program using Jupyter Notebook only...
Focuses on the design, development, implementation, and testing of a Python program using Jupyter Notebook only to solve the problem described below. You will write a program that simulates an Automatic Teller Machine (ATM). For this program, your code can have of user-defined functions only. However, the program must not call on any external functions or modules to handle any of the input, computational, and output requirements. Note, the program can be completed without the use of user-defined functions. Requirements:...
Question: Write an implementation of the ADT sorted list that uses a resizable array (vector class...
Question: Write an implementation of the ADT sorted list that uses a resizable array (vector class of C++ STL) to represent the list items. Anytime the list becomes full, double the size of the array.
Python we need to create a game using only the library graphic.py and use only Structure...
Python we need to create a game using only the library graphic.py and use only Structure Functions only.
Implement a Bag ADT using Dynamic Array structure as underlying data storage for Bag ADT. RESTRICTIONS:...
Implement a Bag ADT using Dynamic Array structure as underlying data storage for Bag ADT. RESTRICTIONS: Not allowed to use ANY built-in Python data structures and their methods. You must solve by importing the DynamicArray class and using class methods to write solution. Also not allowed to directly access any variables of the DynamicArray class (like self.size, self.capacity and self.data in part 1). All work must be done by only using class methods. Below is the Bag ADT starter code...
LANGUAGE PYTHON 3.7 Write a collection class named "Jumbler". Jumbler takes in an optional list of...
LANGUAGE PYTHON 3.7 Write a collection class named "Jumbler". Jumbler takes in an optional list of strings as a parameter to the constuctor with various strings. Jumbler stores random strings and we access the items based on the methods listed below. Jumbler supports the following methods: add() : Add a string to Jumbler get() : return a random string from Jumbler max() : return the largest string in the Jumbler based on the length of the strings in the Jumbler....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT