The below program contains error please help to solve it.   from collections import deque   def find_shortest_paths(graph): paths = {} vertices = graph.keys()   for start_vertex in vertices: visited = set() distances = {vertex: float('inf') for vertex in vertices} distances[start_vertex] = 0 queue = deque([(start_vertex, [])])   while queue: current_vertex, path = queue.popleft() visited.add(current_vertex)   for neighbor in graph[current_vertex]: if neighbor not in visited: distances[neighbor] = min(distances[neighbor], distances[current_vertex] + 1) queue.append((neighbor, path + [current_vertex]))   for end_vertex in vertices: paths[(start_vertex, end_vertex)] = set(path + [end_vertex] for path in paths[(start_vertex, end_vertex)] + [path] if len(path) == distances[end_vertex])   return paths   def find_largest_set(paths): largest_set = set() for u, v in paths: for w in paths: if u != v and u != w and v != w and len(paths[u, v]) != len(paths[u, w]) + len(paths[w, v]): break else: if len(paths[u, v]) > len(largest_set): largest_set = paths[u, v]   return largest_set   # Example 1 graph1 = { 'A': ['B', 'C', 'D', 'F'], 'B': ['A', 'C', 'D', 'F'], 'C': ['A', 'B', 'D', 'F'], 'D': ['A', 'B', 'C', 'E', 'F'], 'E': ['D', 'F'], 'F': ['A', 'B', 'C', 'D', 'E'] }   paths1 = find_shortest_paths(graph1) largest_set1 = find_largest_set(paths1)   print("The largest set is:") print(largest_set1) print("The cardinality is:", len(largest_set1)) print()   # Example 2 graph2 = { '1': ['2', '5', '6'], '2': ['1', '3', '7'], '3': ['2', '4', '8'], '4': ['3', '5', '9'], '5': ['1', '4', '10'], '6': ['1', '8', '9'], '7': ['2', '9', '10'], '8': ['3', '6', '10'], '9': ['4', '6', '7'], '10': ['5', '7', '8'] }   paths2 = find_shortest_paths(graph2) largest_set2 = find_largest_set(paths2)   print("The largest set is:") print(largest_set2) print("The cardinality is:", len(largest_set2))

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

The below program contains error please help to solve it.

 

from collections import deque

 

def find_shortest_paths(graph):

paths = {}

vertices = graph.keys()

 

for start_vertex in vertices:

visited = set()

distances = {vertex: float('inf') for vertex in vertices}

distances[start_vertex] = 0

queue = deque([(start_vertex, [])])

 

while queue:

current_vertex, path = queue.popleft()

visited.add(current_vertex)

 

for neighbor in graph[current_vertex]:

if neighbor not in visited:

distances[neighbor] = min(distances[neighbor], distances[current_vertex] + 1)

queue.append((neighbor, path + [current_vertex]))

 

for end_vertex in vertices:

paths[(start_vertex, end_vertex)] = set(path + [end_vertex] for path in paths[(start_vertex, end_vertex)] + [path] if len(path) == distances[end_vertex])

 

return paths

 

def find_largest_set(paths):

largest_set = set()

for u, v in paths:

for w in paths:

if u != v and u != w and v != w and len(paths[u, v]) != len(paths[u, w]) + len(paths[w, v]):

break

else:

if len(paths[u, v]) > len(largest_set):

largest_set = paths[u, v]

 

return largest_set

 

# Example 1

graph1 = {

'A': ['B', 'C', 'D', 'F'],

'B': ['A', 'C', 'D', 'F'],

'C': ['A', 'B', 'D', 'F'],

'D': ['A', 'B', 'C', 'E', 'F'],

'E': ['D', 'F'],

'F': ['A', 'B', 'C', 'D', 'E']

}

 

paths1 = find_shortest_paths(graph1)

largest_set1 = find_largest_set(paths1)

 

print("The largest set is:")

print(largest_set1)

print("The cardinality is:", len(largest_set1))

print()

 

# Example 2

graph2 = {

'1': ['2', '5', '6'],

'2': ['1', '3', '7'],

'3': ['2', '4', '8'],

'4': ['3', '5', '9'],

'5': ['1', '4', '10'],

'6': ['1', '8', '9'],

'7': ['2', '9', '10'],

'8': ['3', '6', '10'],

'9': ['4', '6', '7'],

'10': ['5', '7', '8']

}

 

paths2 = find_shortest_paths(graph2)

largest_set2 = find_largest_set(paths2)

 

print("The largest set is:")

print(largest_set2)

print("The cardinality is:", len(largest_set2))

Q
ננו
LD
5
$
C
C
JS
GO
php
main.py
38
39 # Example 1
40 graph1 = {
41
42
43
44
45
46
47 }
48
49
paths1 = find_shortest_paths (graph1)
50 largest set1 = find_largest_set(paths1)
51
52 print("The largest set is:")
53 print (largest_set1)
54 print("The cardinality is:", len(largest_set1))
55 print()
56
T
'A':
['B', 'C', 'D', 'F'],
'B': ['A', 'C', 'D', 'F'],
'C': ['A', 'B', 'D', 'F'],
'D': ['A', 'B', 'C', 'E', 'F'],
'E': ['D', 'F'],
'F': ['A', 'B', 'C', 'D', 'E']
57 # Example 2
58 graph2 = {
59
60
'1': ['2', '5', '6'],
['1'
॥੨॥
-יכי
וידי
c
Run
Shell
^ ERROR!
Traceback (most recent call last):
File "<string>", line 49, in <module>
File "<string>", line 23, in find_shortest_paths
KeyError: ('F', 'A')
Clear
Transcribed Image Text:Q ננו LD 5 $ C C JS GO php main.py 38 39 # Example 1 40 graph1 = { 41 42 43 44 45 46 47 } 48 49 paths1 = find_shortest_paths (graph1) 50 largest set1 = find_largest_set(paths1) 51 52 print("The largest set is:") 53 print (largest_set1) 54 print("The cardinality is:", len(largest_set1)) 55 print() 56 T 'A': ['B', 'C', 'D', 'F'], 'B': ['A', 'C', 'D', 'F'], 'C': ['A', 'B', 'D', 'F'], 'D': ['A', 'B', 'C', 'E', 'F'], 'E': ['D', 'F'], 'F': ['A', 'B', 'C', 'D', 'E'] 57 # Example 2 58 graph2 = { 59 60 '1': ['2', '5', '6'], ['1' ॥੨॥ -יכי וידי c Run Shell ^ ERROR! Traceback (most recent call last): File "<string>", line 49, in <module> File "<string>", line 23, in find_shortest_paths KeyError: ('F', 'A') Clear
Expert Solution
steps

Step by step

Solved in 5 steps with 3 images

Blurred answer
Knowledge Booster
Mergesort
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education