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.
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