def addEdge(graph,u,v): if u in graph.keys(): if v not in graph[u]: graph(u].append (v) else : graph[u]-[v] Fv in graph. keys (): if u not in graph[v]: graph[v].append (u) else: graph[v]-[u] print(u," and ",v," are now connected") def renove_Edge(graph, u,v): if u not in graph.keys(): print(u, "not present in graph") return if v not in graph.keys(): print(v, "not present in graph") return if v not in graph[u]: print(u," andv, "is not connected") return graph(u).remove(v) graph[v].remove(u) print (u," and ",v," are now not connected") def renove_node(graph, u): if u not in graph.keys(): print(u, "not present in graph") return for i in graph. keys(): if u in graph[i]: graph(i].renove(u) del graph[u] print(u," deleted from the graph") def display(graph): if graph: print("Adjacency 1ist representaion of graph") print( for i in graph.keys(): print (1," - ".graph[i]) elset print('graph not exists') def check(graph,u,v): if u not in graph.keys(): print(u, "not present in graph") return if v not in graph.keys(): print(v. "not present in graph") return i4 (u in graph[v]) and (v in graph[u]): print(u,' and v,' has edge ) else: print (u, and ,v. is not connected') return #Driver code graph-{} t-1 while t: | print("Select your option:") print("1. Add Node") print("2. Add Edge") print("3. Renove Node") print("4. Renove Edge") print("5. Check presence of a Node") print("6. Check realtion between two node") print("7. Display Graph") print ("8. Exit") opt= input() opt- int (opt) print("Opted Optione ",opt) if opt1: print("Enter Node") n= int (input()) if n in graph.keys(): print("Node already exist") else: Braph(n]-[) print (n," added in graph") elif opt 2: print("Enter Node to be connect seprated by space") x,y input ().split( ) addEdge (graph, int (x), nt (y)) elif opt 3: print("Enter Node to be remove ") n int(input()) remove_node(graph, n) elif opt==4: print("Enter Nlode to be disconnect seprated by space") x,y input (). split( ") remove_Edge(graph, int (x), int (y)) elif opts: print("Enter node") n- int (input ()) If n in greph.keys(): print("Node Present") else: print("Node not present") elif opt-6: print ("Enter node whose connective is to check") x,y input (). split( ") X int (x) y in (y) check(graph, x,y) elif opt-7: display(graph) elif opt8: print(".--..- Terminating-.--") else: print("Incorrect Choice") print( printt
def addEdge(graph,u,v): if u in graph.keys(): if v not in graph[u]: graph(u].append (v) else : graph[u]-[v] Fv in graph. keys (): if u not in graph[v]: graph[v].append (u) else: graph[v]-[u] print(u," and ",v," are now connected") def renove_Edge(graph, u,v): if u not in graph.keys(): print(u, "not present in graph") return if v not in graph.keys(): print(v, "not present in graph") return if v not in graph[u]: print(u," andv, "is not connected") return graph(u).remove(v) graph[v].remove(u) print (u," and ",v," are now not connected") def renove_node(graph, u): if u not in graph.keys(): print(u, "not present in graph") return for i in graph. keys(): if u in graph[i]: graph(i].renove(u) del graph[u] print(u," deleted from the graph") def display(graph): if graph: print("Adjacency 1ist representaion of graph") print( for i in graph.keys(): print (1," - ".graph[i]) elset print('graph not exists') def check(graph,u,v): if u not in graph.keys(): print(u, "not present in graph") return if v not in graph.keys(): print(v. "not present in graph") return i4 (u in graph[v]) and (v in graph[u]): print(u,' and v,' has edge ) else: print (u, and ,v. is not connected') return #Driver code graph-{} t-1 while t: | print("Select your option:") print("1. Add Node") print("2. Add Edge") print("3. Renove Node") print("4. Renove Edge") print("5. Check presence of a Node") print("6. Check realtion between two node") print("7. Display Graph") print ("8. Exit") opt= input() opt- int (opt) print("Opted Optione ",opt) if opt1: print("Enter Node") n= int (input()) if n in graph.keys(): print("Node already exist") else: Braph(n]-[) print (n," added in graph") elif opt 2: print("Enter Node to be connect seprated by space") x,y input ().split( ) addEdge (graph, int (x), nt (y)) elif opt 3: print("Enter Node to be remove ") n int(input()) remove_node(graph, n) elif opt==4: print("Enter Nlode to be disconnect seprated by space") x,y input (). split( ") remove_Edge(graph, int (x), int (y)) elif opts: print("Enter node") n- int (input ()) If n in greph.keys(): print("Node Present") else: print("Node not present") elif opt-6: print ("Enter node whose connective is to check") x,y input (). split( ") X int (x) y in (y) check(graph, x,y) elif opt-7: display(graph) elif opt8: print(".--..- Terminating-.--") else: print("Incorrect Choice") print( printt
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Please send the code text
Thank you.
![print("Adjacency list representaion of graph")
I RunO Dubus Skop e Share
H Save Beaully
Langunge Python 3
e 0
man py
def addEdge(graph, u,v):
if u in graph.keys():
if v not in graph(u]:
graph(u].append (v)
2
3-
4
5-
else :
graph[u)-[v]
if v in graph.keys():
if u not in graph[v]:
graph[v].append (u)
7-
else :
graph[v]-[u]
print (u," and ",v," are now connected")
10
11
12
13
14- def renove_Edge(graph, u,v):
15
if u not in graph.keys():
print(u, "not present in graph")
16
17
return
if v not in graph.keys():
print(v, "not present in graph")
18
19
20
return
if v not in graph[u]:
print(u,"
return
21
2
and "v,"is not connected")
23
graph(u).remove(v)
graph[v].remove(u)
print(u," and ",v." are now not connected")
24
25
26
27
28- def renove_node(graph, u):
29
if u not in graph.keys():
print(u, "not present in graph")
return
for i in graph.keys():
if u in graph[i]:
graph(i].renove(u)
30
31
32
33-
34
35
del graph(u)
print(u," deleted from the graph")
36
37
38- def display(graph):
if graph:
print("Adjacency 1ist representaion of graph")
print("
for i in graph.keys():
39
40
41
_")
42
43
print(i,"-- ".graph[i])
44
45
46
else:
47
print('graph not exists')
49- def check(graph,u,v):
sa
if u not in graph.keys():
print(u, "not present in graph")
51
52
return
53
54
if v not in graph.keys():
print(v, "not present in graph")
return
55
56
if (u in graph[v]) and (v in graph[u]):
print(u,' and ,v,' has a edge )
else:
print(u,' and ',v,' is not connected')
57
58
59
61
return
62
63 #Driver code
64 graph-()
65 t-1
66 - while t:I
67
print("Select your option:")
68
print("1. Add Node")
print("2. Add Edge")
print("3. Renove Node")
print("4. Renove Edge")
print ("5. Check presence of a Node")
print("6. Check realtion between two node")
print ("7. Display Graph")
print ("8. Exit")
opt= input()
opt= int (opt)
print("Opted Optione ",opt)
if opt1:
print("Enter Node")
n int (input(0)
if n in graph.keys():
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
print("Node already exist")
asto
graph[n]-[)
print(n," added in graph")
85
86
87
elif opt== 2:
print("Enter Node to be connect seprated by space")
x,y- input (). split(" ")
addEdge (graph,int (x), nt (y))
elif opt 3:
print("Enter Node to be remove ").
n= int(input ())
remove_node(graph, n)
elif opt4:
print("Enter Nlode to be disconnect seprated by space")
X.y input ().split(" ")
remove_Edge(graph, int (x), int (y))
elif opt5:
print("Enter node")
n- int (input ())
if n in graph.keys():
print("Node Present ")
else:
print("Node not present")
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
elif opt==6:
print("Enter node whose connective is to check")
X,y input ().split( ")
X int (x)
y int (y)
check(graph, x,y)
107
108
109
110
111
112
113
114
elif opt71
display(graph)
elif opt==8:
print("---..-Terminating-..----")
115
116
117
118
t=0
119
else:
print("Incorrect Choice")
print("
print(
120
121
122
input
3lienowe Node](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fc9fd62cb-9a27-458a-b32f-b1f6ed8167f3%2Fcbf04fa3-ae6b-458c-8ab6-079c0d26f754%2F42x19za_processed.jpeg&w=3840&q=75)
Transcribed Image Text:print("Adjacency list representaion of graph")
I RunO Dubus Skop e Share
H Save Beaully
Langunge Python 3
e 0
man py
def addEdge(graph, u,v):
if u in graph.keys():
if v not in graph(u]:
graph(u].append (v)
2
3-
4
5-
else :
graph[u)-[v]
if v in graph.keys():
if u not in graph[v]:
graph[v].append (u)
7-
else :
graph[v]-[u]
print (u," and ",v," are now connected")
10
11
12
13
14- def renove_Edge(graph, u,v):
15
if u not in graph.keys():
print(u, "not present in graph")
16
17
return
if v not in graph.keys():
print(v, "not present in graph")
18
19
20
return
if v not in graph[u]:
print(u,"
return
21
2
and "v,"is not connected")
23
graph(u).remove(v)
graph[v].remove(u)
print(u," and ",v." are now not connected")
24
25
26
27
28- def renove_node(graph, u):
29
if u not in graph.keys():
print(u, "not present in graph")
return
for i in graph.keys():
if u in graph[i]:
graph(i].renove(u)
30
31
32
33-
34
35
del graph(u)
print(u," deleted from the graph")
36
37
38- def display(graph):
if graph:
print("Adjacency 1ist representaion of graph")
print("
for i in graph.keys():
39
40
41
_")
42
43
print(i,"-- ".graph[i])
44
45
46
else:
47
print('graph not exists')
49- def check(graph,u,v):
sa
if u not in graph.keys():
print(u, "not present in graph")
51
52
return
53
54
if v not in graph.keys():
print(v, "not present in graph")
return
55
56
if (u in graph[v]) and (v in graph[u]):
print(u,' and ,v,' has a edge )
else:
print(u,' and ',v,' is not connected')
57
58
59
61
return
62
63 #Driver code
64 graph-()
65 t-1
66 - while t:I
67
print("Select your option:")
68
print("1. Add Node")
print("2. Add Edge")
print("3. Renove Node")
print("4. Renove Edge")
print ("5. Check presence of a Node")
print("6. Check realtion between two node")
print ("7. Display Graph")
print ("8. Exit")
opt= input()
opt= int (opt)
print("Opted Optione ",opt)
if opt1:
print("Enter Node")
n int (input(0)
if n in graph.keys():
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
print("Node already exist")
asto
graph[n]-[)
print(n," added in graph")
85
86
87
elif opt== 2:
print("Enter Node to be connect seprated by space")
x,y- input (). split(" ")
addEdge (graph,int (x), nt (y))
elif opt 3:
print("Enter Node to be remove ").
n= int(input ())
remove_node(graph, n)
elif opt4:
print("Enter Nlode to be disconnect seprated by space")
X.y input ().split(" ")
remove_Edge(graph, int (x), int (y))
elif opt5:
print("Enter node")
n- int (input ())
if n in graph.keys():
print("Node Present ")
else:
print("Node not present")
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
elif opt==6:
print("Enter node whose connective is to check")
X,y input ().split( ")
X int (x)
y int (y)
check(graph, x,y)
107
108
109
110
111
112
113
114
elif opt71
display(graph)
elif opt==8:
print("---..-Terminating-..----")
115
116
117
118
t=0
119
else:
print("Incorrect Choice")
print("
print(
120
121
122
input
3lienowe Node
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps

Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY