Python Programming. I need to learn. Help me please. Instructions: Read the problem below.

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...
icon
Related questions
Question

Python Programming. I need to learn. Help me please.

Instructions:

  • Read the problem below.
  • The code is in https://pastebin.com/ZdVYapav
    • Answer the parts with "INSERT CODE BELOW" only.
  • Sample inputs and outputs are given.
Sample Input 1
O 0 9
add_vertex ()
add_vertex()
add_vertex ()
add_vertex()
add_edge(1, 2, 5)
add_edge (1, 3,
add_edge (2, 3, 11)
add_edge (2, 4, 13)
add_edge (3, 4, 17)
7)
Sample Output 1
4,
|티
[1] -> [(2, 5), (3, 7)]
[2] -> [(1, 5), (3, 11), (4, 13)]
[3] -> [(1, 7), (2, 11), (4, 17)]
[4] -> [(2, 13), (3,
17)]
Sample Input 2
3 3 0
1 2 5
1 3 7
2 3 11
Sample Output 2
= 3,
|E|
= 3
[1] -> [(2, 5), (3, 7)]
[2] -> [(1, 5), (3, 11)]
[3]
-> [(1, 7), (2, 11)]
Sample Input 3
2 33
1 2 5
13 7
2 3 11
add_vertex()
add_edge (1, 3, 13)
add_edge (2, 3, 17)
Sample Output 3
|V| = 3,
[1] -> [(2, 5), (3, 13)]
[2] -> [(1, 5), (3, 17)]
[3] -> [(1, 13), (2, 17)]
|E|
= 3
Transcribed Image Text:Sample Input 1 O 0 9 add_vertex () add_vertex() add_vertex () add_vertex() add_edge(1, 2, 5) add_edge (1, 3, add_edge (2, 3, 11) add_edge (2, 4, 13) add_edge (3, 4, 17) 7) Sample Output 1 4, |티 [1] -> [(2, 5), (3, 7)] [2] -> [(1, 5), (3, 11), (4, 13)] [3] -> [(1, 7), (2, 11), (4, 17)] [4] -> [(2, 13), (3, 17)] Sample Input 2 3 3 0 1 2 5 1 3 7 2 3 11 Sample Output 2 = 3, |E| = 3 [1] -> [(2, 5), (3, 7)] [2] -> [(1, 5), (3, 11)] [3] -> [(1, 7), (2, 11)] Sample Input 3 2 33 1 2 5 13 7 2 3 11 add_vertex() add_edge (1, 3, 13) add_edge (2, 3, 17) Sample Output 3 |V| = 3, [1] -> [(2, 5), (3, 13)] [2] -> [(1, 5), (3, 17)] [3] -> [(1, 13), (2, 17)] |E| = 3
You are tasked to define methods of a graph class implementation to be able to create a graph from: (a)
the number of vertices, (b) a list of directed edges, and/or (c) from a set of graph methods which can add
and/or remove vertices and/or edges.
Specifically you need to define the following Graph methods:
• A. add_vertex()
• B. add_edge ( )
• C. initialize_graph()
• D. remove_edge()
• E. remove_vertex()
Grading:
• [25%] Test Case
1 makes sure that you have defined the Graph methods add_vertex() and
add_edge().
• [25%] Test Cases 2 and 3 make sure that you have: (a) properly defined the function add_edge() to
ignore invalid input, and (b) defined the Graph method initialize_graph() properly.
• [25%] Test Cases 4 and 5 make sure that you have properly defined the Graph method
remove_edge () and make sure it ignores invalid input.
• [25%] Test Cases 6 and 7 make sure that you have properly defined the Graph method
remove_vertex() and make sure it ignores invalid input.
Input Format
The first line of the input contains three non-negative integers V, E, and C separated by white spaces.
V is the number of vertices of the graph to be added (initially); E is the number of undirected edges to
be added (initially); and C is the number of graph methods to be executed after initializing the graph.
If E > 0, the next E lines will each contain three non-negative integers v1, v2, cost corresponding to
undirected edges; where v1 is the first vertex, v2 is the second vertex, and cost is the weight associated
with the undirected edge between veretices vl to vertex v2.
If C > 0, the next C lines will each contain a graph method to be called.
Constraints
• Do not create additional class attributes, helper methods, or helper functions. Do not modify formal
parameters. Just make use of the existing methods and attributes.
• For reduced difficulty, the method remove_vertex() will only be tested to remove the last existing
vertex. This is to remove the need to shift the vertex values in the adjacency list when vertices are
removed.
• Graph methods will ignore invalid input arguments, i.e. do nothing to the graph.
Output Format
The output is a formatted string that is generated by the method print_graph () of the graph class.
See sample outputs for more information.
Transcribed Image Text:You are tasked to define methods of a graph class implementation to be able to create a graph from: (a) the number of vertices, (b) a list of directed edges, and/or (c) from a set of graph methods which can add and/or remove vertices and/or edges. Specifically you need to define the following Graph methods: • A. add_vertex() • B. add_edge ( ) • C. initialize_graph() • D. remove_edge() • E. remove_vertex() Grading: • [25%] Test Case 1 makes sure that you have defined the Graph methods add_vertex() and add_edge(). • [25%] Test Cases 2 and 3 make sure that you have: (a) properly defined the function add_edge() to ignore invalid input, and (b) defined the Graph method initialize_graph() properly. • [25%] Test Cases 4 and 5 make sure that you have properly defined the Graph method remove_edge () and make sure it ignores invalid input. • [25%] Test Cases 6 and 7 make sure that you have properly defined the Graph method remove_vertex() and make sure it ignores invalid input. Input Format The first line of the input contains three non-negative integers V, E, and C separated by white spaces. V is the number of vertices of the graph to be added (initially); E is the number of undirected edges to be added (initially); and C is the number of graph methods to be executed after initializing the graph. If E > 0, the next E lines will each contain three non-negative integers v1, v2, cost corresponding to undirected edges; where v1 is the first vertex, v2 is the second vertex, and cost is the weight associated with the undirected edge between veretices vl to vertex v2. If C > 0, the next C lines will each contain a graph method to be called. Constraints • Do not create additional class attributes, helper methods, or helper functions. Do not modify formal parameters. Just make use of the existing methods and attributes. • For reduced difficulty, the method remove_vertex() will only be tested to remove the last existing vertex. This is to remove the need to shift the vertex values in the adjacency list when vertices are removed. • Graph methods will ignore invalid input arguments, i.e. do nothing to the graph. Output Format The output is a formatted string that is generated by the method print_graph () of the graph class. See sample outputs for more information.
Expert Solution
steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
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 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)
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
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY