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
Give a complete implementation of the queue ADT using a singly linked list that includes a...
Give a complete implementation of the queue ADT using a singly linked list that includes a header sentinel (in Python).
Write C++ programs to implement Queue ADT data structure using Linked List.
Write C++ programs to implement Queue ADT data structure using Linked List.
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...
Using Python provide the implementation of a function called "isAdjacent" that accepts a string.   The function...
Using Python provide the implementation of a function called "isAdjacent" that accepts a string.   The function checks if two adjacent characters in the string are the same; if they are the same, then return True otherwise return False.   The function should ignore case and check for non-empty string.  If it's an empty string, then return the message 'Empty string'. Sample runs: print( isAdjacent('ApPle')) # True print( isAdjacent('Python')) # False print( isAdjacent('')) # Empty string
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT