Lab 11: Graph Data Structures Implement the Graph ADT with two data structures: Graph_ES edge set...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Lab 11: Graph Data Structures Implement the Graph ADT with two data structures: Graph_ES edge set Graph_AS adjacency set Note: you can find partial or full solutions for this lab in the textbook and video lectures for this module. Avoid external resources during lab; do your best to figure things out with you and your partner. Feel free to access these resources afterwards if you do not finish during. Graph Each graph you implement should support the following ADT Magic Metohds init(V, E) -initializes with optional sets of vertices V and edges E len iter returns the number of vertices in the graph -iterates over all vertices in graph Non-magic Methods add_vertex(v) - adds vertex v to graph remove_vertex(v) -removes vertex v from graph - raise a KeyError if v is not in graph add_edge(e) adds edge e to graph (assume e is a 2-tuple) remove_edge(e) removes edge e from graph (assume e is a 2-tuple) - raise a KeyError if e is not in graph neighbors (v) -returns an iterable collection of neighbors of vertex v - Running time: Examples * O(m), Graph_ES (m is the number of edges in the graph) * O(1), Graph_AS (time to return an iterator does not depend on the number of neighbors) Examples Any examples below are intended to be illustrative, not exhaustive. Your code may have bugs even if it behaves as below. Write your own tests, and think carefully about edge cases. >>> from lab11 import * >>> # 1 2 3 >>> vs = {1,2,3} >>> es {(1,2), (2,1), (2,3), (3,2)} >>> g = Graph ES (vs, es) >>> assert len(g) == 3 >>> verts = set() >>> for v in vs: verts.add(v) >>> assert verts VS >>> nbrs {2:set()} >>> for n in g._neighbors (2): nbrs [2].add(n) >>> assert nbrs (2:13, 1}} Lab 11: Graph Data Structures Implement the Graph ADT with two data structures: Graph_ES edge set Graph_AS adjacency set Note: you can find partial or full solutions for this lab in the textbook and video lectures for this module. Avoid external resources during lab; do your best to figure things out with you and your partner. Feel free to access these resources afterwards if you do not finish during. Graph Each graph you implement should support the following ADT Magic Metohds init(V, E) -initializes with optional sets of vertices V and edges E len iter returns the number of vertices in the graph -iterates over all vertices in graph Non-magic Methods add_vertex(v) - adds vertex v to graph remove_vertex(v) -removes vertex v from graph - raise a KeyError if v is not in graph add_edge(e) adds edge e to graph (assume e is a 2-tuple) remove_edge(e) removes edge e from graph (assume e is a 2-tuple) - raise a KeyError if e is not in graph neighbors (v) -returns an iterable collection of neighbors of vertex v - Running time: Examples * O(m), Graph_ES (m is the number of edges in the graph) * O(1), Graph_AS (time to return an iterator does not depend on the number of neighbors) Examples Any examples below are intended to be illustrative, not exhaustive. Your code may have bugs even if it behaves as below. Write your own tests, and think carefully about edge cases. >>> from lab11 import * >>> # 1 2 3 >>> vs = {1,2,3} >>> es {(1,2), (2,1), (2,3), (3,2)} >>> g = Graph ES (vs, es) >>> assert len(g) == 3 >>> verts = set() >>> for v in vs: verts.add(v) >>> assert verts VS >>> nbrs {2:set()} >>> for n in g._neighbors (2): nbrs [2].add(n) >>> assert nbrs (2:13, 1}}
Expert Answer:
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these computer network questions
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
(i) Write down the linear program relaxation for the vertex cover problem and solve the linear program. [6 marks] (ii) Based on the solution of the linear program in (b)(i), derive an integer...
-
What is the probability that the number X of successes in the personnel managers sample of 100 employees in question 10 will be 48 or more?
-
List the principal professional activities of macro-economists. What role does macroeconomic research play in each of these activities?
-
What strategies do operating systems use for resource allocation to prevent resource starvation, and how do they mitigate the risks of resource hoarding by individual processes ?
-
Grunewald Industries sells on terms of 2/10, net 40. Gross sales last year were $4,562,500, and accounts receivable averaged $437,500. Half of Grunewalds customers paid on the 10th day and took...
-
You have had some time to organize your management team and make decisions for your firm, it is time to report to the board of directors. All members of the team should contribute to the report's...
-
1. Chandler has six stores where he has to get rid of a product that has about 12,704 pieces and amongst those pieces- he has to divide them into six different stores with a mounted way of 21 states...
-
Identify 1 intentional teaching strategy you could incorporate into you program to promote creativity related to your chosen NQS element. Identify 1 regulation that you would be guided by during the...
-
10. You are renting a storage warehouse for 6 years. The rent is $6,000 per year payable at the beginning of each year. You want to set aside the money necessary to meet these payments. If the money...
-
Code a nested loop program that will generate a multiplication table, but instead of creating a simple 10 by 10 multiplication table, the program allows the user to type in two numbers (beginning and...
-
Set Up 1. Make a new main class called IA4_ParallelBubbleSort_LastName.java. 2. Copy an applicable sort method from a previous assignment and then alter it to take in a String Array for sorting plus...
-
A. State whether each of the following vector fields could describe a static electric field? Show your reasoning for each. (i) E(r) = xx yu (ii) E(F) = yx + xy (iii) E(7) = yx - xy B. Calculate the...
-
Essay based on "story of an hour" and "desiree's baby" by kate chopin and explain the contrast between Appearances with Reality.
-
Before the latest financial crisis and recession, when was the largest recession of the past 50 years, and what was the cumulative loss in output over the course of the slowdown?
-
A vertical tube is attached to the bottom of an open vessel. A liquid with an $\mathrm{SG}$ of 1.2 is draining through the tube, which is $10 \mathrm{~cm}$ long with an ID of $3 \mathrm{~mm}$. When...
-
An air ventilating system must be designed to deliver air at $20^{\circ} \mathrm{F}$ and atmospheric pressure at a rate of $150 \mathrm{ft}^{3} / \mathrm{s}$ through $4000 \mathrm{ft}$ of square...
-
An open drainage canal with a rectangular cross section and a width of $20 \mathrm{ft}$ is lined with concrete. The canal has a slope of $1 \mathrm{ft} / 1000$ yards. What is the depth of water in...
Study smarter with the SolutionInn App