Question: Implement function Distance(V, L, a, b). Given graph with vertex data V, and adjacency list L, this function will return the (shortest) distance between vertices
Implement function Distance(V, L, a, b). Given graph with vertex data V, and adjacency list L, this function will return the (shortest) distance between vertices a and b.
# Implement this function def Distance(V, L, a, b): pass
# This is the class used for vertex data. # Don't modify the class, it is good enough for # what we are doing. class Vertex: pass
# Below is some code to help you test the function # Feel free to modify it and/or add your own testing code:
# A graph with six vertices VertexData = [Vertex() for i in range(6)] # Adjacency list defining edges in the graph
AdjList = [[1], [0,2,3], [1,4], [1,4], [2,3,5], [4]]
assert Distance(VertexData, AdjList, 0, 5) == 4 assert Distance(VertexData, AdjList, 2, 3) == 2 assert Distance(VertexData, AdjList, 3, 1) == 1 assert Distance(VertexData, AdjList, 5, 1) == 3
PYTHON
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
