Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What are the answers for this coding? Write a function adjacency_list(graph str) that takes the textual representation of a graph (as a string) and returns

What are the answers for this coding?

image text in transcribed

image text in transcribed

image text in transcribed

Write a function adjacency_list(graph str) that takes the textual representation of a graph (as a string) and returns its adjacency list. The returned adjacency list must be a list of lists. The length of the outer list is equal to the number of vertices. The inner lists have one elements for each edge. The elements are two-tuples where the first element of the tuple is the vertex the edge goes to, and the second element of the tuple is the weight. For unweighted graphs the second element of the tuple is None . The inner lists must be populated as the edge information is read from the graph string. This order is important. Note that for undirected graphs, each edge is stored two times (in opposite directions) Note: In some programming questions in future quizzes you have to include the definition of the adjacency_list function For example Test Result [(1, None), (2, None)], [(0, None)], graph-string = "" D 3 0 1 1 0 0 2 print(adjacency_list(graph_string)) ""' graph-string = 0 1 7 1 0-2 0 2 0 print(adjacency_list(graph_string)) Ci, [(6, None), (2, None), (5, None), [(5, None), (3, None)], [(4, None)l, from pprint import pprint graph-string = """\ D 7 1 6 1 2 1 5 [(4, None)l

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions