addEdges(G, edges, directed = False): This function will take a graph G and a list of edges E as parameters. It will add the edges in the graph G and return the Updated Graph. Format of list of edges: edges = [(u1 , v1 , w1) , (u2 , v2 , w2),.. Here, u = start node, v = end node, w = weight (for un-weighted graph default value of w is 1.) G- {0: [], 1: [], 2: [], 3: [], 4: [], 5: [] G = { e: [(1, 1), (2, 1)], 1: [(2, 1), (3, 1)], 2: [(4, 1)], 3: [(4, 1), (5, 1)], 4: [(5, 1)], 5: [] edge_list = [(0, 1, 1), (8, 2, 1), (1, 2, 1), (1, 3, 1), (2, 4, 1), (3, 4, 1), (3, 5, 1), (4, 5, 1)] G = addEdges(G, edges, True) G- (0: [], 1: [], 2: [], 3: [], 4: [], 5: [] G = { e: [(1, 1), (2, 1)], 1: [(е, 1), (2, 1), (3, 1)], edge_list = [(0, 1, 1), (0, 2, 1), (1, 2, 1), 2: [(0, 1), (1, 1), (4, 1)], (1, 3, 1), (2, 4, 1), (3, 4, 1), (3, 5, 1), |(4, 5, 1)] 3: [(1, 1), (4, 1), (5, 1)], 4: [(3, 1), (2, 1), (5, 1)], 5: [(3, 1), (4, 1)] G - addEdges(G, edges, False) G- (0: [], 1: [], 2: [], 3: [], 4: [], 5: [] G = { e: [(1, 21), (2, 15)], 1: [(2, 10), (3, 70)], edge_list = [(0, 1, 21), (0, 2, 15), (1, 2, 1 2: [(4, 50)], a), (1, 3, 70), (2, 4, 50), (3, 4, 24), (3, 5 3: [(4, 24), (5, 39)], , 39), (4, 5, 99)] 4: [(5, 99)], 5: [] G = addEdges(G, edges, True) {0: [], 1: [], 2: [], 3: [], 4: [), 5: []G = { e: [(1, 21), (2, 15)], 1: [(е, 21), (2, 10), (3, 70)], edge_list = [(0, 1, 21), (0, 2, 15), (1, 2, 1 2: [(0, 15), (1, 10), (4, 50)], e), (1, 3, 70), (2, 4, 50), (3, 4, 24), (3, 5 3: [(1, 70), (4, 24), (5, 39)], , 39), (4, 5, 99)] 4: [(3, 24), (2, 50), (5, 99)], 5: [(3, 39), (4, 99)] G = addEdges(G, edges, False)

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

python 3

 

addEdges(G, edges, directed = False): This function will take a graph G and a list of edges E as
parameters. It will add the edges in the graph G and return the Updated Graph.
Format of list of edges:
edges = [(u1 , v1, w1) , (u2 , v2 , w2),.
Here, u = start node, v = end node, w = weight (for un-weighted graph default value of w is 1.)
%3D
G =
{0: [], 1: [], 2: [], 3: [], 4: [], 5: [] G = {
0: [(1, 1), (2, 1)],
1: [(2, 1), (3, 1)],
2: [(4, 1)],
3: [(4, 1), (5, 1)],
4: [(5, 1)],
5: []
edge_list = [(0, 1, 1), (0, 2, 1), (1, 2, 1),
(1, 3, 1), (2, 4, 1), (3, 4, 1), (3, 5, 1),
(4, 5, 1)]
addEdges (G, edges, True)
G =
G = {0: [], 1: [], 2: [], 3: [], 4: [], 5: []
G = {
0: [(1, 1), (2, 1)],
1: [(0, 1), (2, 1), (3, 1)],
2: [(0, 1), (1, 1), (4, 1)],
3: [(1, 1), (4, 1), (5, 1)],
4: [(3, 1), (2, 1), (5, 1)],
5: [(3, 1), (4, 1)]
edge_list
[ (0, 1, 1), (ө, 2, 1), (1, 2, 1),
(1, 3, 1), (2, 4, 1), (3, 4, 1), (3, 5, 1),
|(4, 5, 1)]
addEdges (G, edges, False)
IG =
G = {0: [], 1: [], 2: [], 3: [], 4: [], 5: []G = {
0: [(1, 21), (2, 15)],
1: [(2, 10), (3, 70)],
2: [(4, 50)],
3: [(4, 24), (5, 39)],
4: [(5, 99)],
5: []
[(0, 1, 21), (0, 2, 15), (1, 2, 1
edge_list
e), (1, 3, 70), (2, 4, 50), (3, 4, 24), (3, 5
, 39), (4, 5, 99)]
addEdges (G, edges, True)
G =
{0: [], 1: [], 2: [], 3: [], 4: [], 5: [] G = {
G =
0: [(1, 21), (2, 15)],
1: [(0, 21), (2, 10), (3, 70)],
2: [(0, 15), (1, 10), (4, 50)],
3: [(1, 70), (4, 24), (5, 39)],
4: [(3, 24), (2, 50), (5, 99)],
5: [(3, 39), (4, 99)]
edge_list =
e), (1, 3, 70), (2, 4, 50), (3, 4, 24), (3, 5
[ (0, 1, 21), (ө, 2, 15), (1, 2, 1
39), (4, 5, 99)]
addEdges (G, edges, False)
G =
Transcribed Image Text:addEdges(G, edges, directed = False): This function will take a graph G and a list of edges E as parameters. It will add the edges in the graph G and return the Updated Graph. Format of list of edges: edges = [(u1 , v1, w1) , (u2 , v2 , w2),. Here, u = start node, v = end node, w = weight (for un-weighted graph default value of w is 1.) %3D G = {0: [], 1: [], 2: [], 3: [], 4: [], 5: [] G = { 0: [(1, 1), (2, 1)], 1: [(2, 1), (3, 1)], 2: [(4, 1)], 3: [(4, 1), (5, 1)], 4: [(5, 1)], 5: [] edge_list = [(0, 1, 1), (0, 2, 1), (1, 2, 1), (1, 3, 1), (2, 4, 1), (3, 4, 1), (3, 5, 1), (4, 5, 1)] addEdges (G, edges, True) G = G = {0: [], 1: [], 2: [], 3: [], 4: [], 5: [] G = { 0: [(1, 1), (2, 1)], 1: [(0, 1), (2, 1), (3, 1)], 2: [(0, 1), (1, 1), (4, 1)], 3: [(1, 1), (4, 1), (5, 1)], 4: [(3, 1), (2, 1), (5, 1)], 5: [(3, 1), (4, 1)] edge_list [ (0, 1, 1), (ө, 2, 1), (1, 2, 1), (1, 3, 1), (2, 4, 1), (3, 4, 1), (3, 5, 1), |(4, 5, 1)] addEdges (G, edges, False) IG = G = {0: [], 1: [], 2: [], 3: [], 4: [], 5: []G = { 0: [(1, 21), (2, 15)], 1: [(2, 10), (3, 70)], 2: [(4, 50)], 3: [(4, 24), (5, 39)], 4: [(5, 99)], 5: [] [(0, 1, 21), (0, 2, 15), (1, 2, 1 edge_list e), (1, 3, 70), (2, 4, 50), (3, 4, 24), (3, 5 , 39), (4, 5, 99)] addEdges (G, edges, True) G = {0: [], 1: [], 2: [], 3: [], 4: [], 5: [] G = { G = 0: [(1, 21), (2, 15)], 1: [(0, 21), (2, 10), (3, 70)], 2: [(0, 15), (1, 10), (4, 50)], 3: [(1, 70), (4, 24), (5, 39)], 4: [(3, 24), (2, 50), (5, 99)], 5: [(3, 39), (4, 99)] edge_list = e), (1, 3, 70), (2, 4, 50), (3, 4, 24), (3, 5 [ (0, 1, 21), (ө, 2, 15), (1, 2, 1 39), (4, 5, 99)] addEdges (G, edges, False) G =
Expert Solution
steps

Step by step

Solved in 2 steps with 4 images

Blurred answer
Knowledge Booster
Introduction to computer system
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