Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package
11th Edition
ISBN: 9780134694511
Author: Liang, Y. Daniel
Publisher: Pearson Education Canada
expand_more
expand_more
format_list_bulleted
Question
Chapter 28, Problem 28.16PE
Program Plan Intro
Induced subgraph
Program Plan:
- Create a package “main”.
- Add a java class named “Edge” to the package which is used to get the edges from the graph.
- Add a java class named “Graph” to the package which is used to add and remove vertices, edges.
- Add a java class named “UnweightedGraph” to the package which is used to store vertices and neighbors.
- Add a java class named “WeightedGraph” to the package which is used to get the weighted edges and print the edges.
- Add a java class named “WeightedEdge” to the package which is used to compare edges.
- Add a java class named “E16” to the package.
- Import the required packages.
- Declare the main class.
- Give the “main ()” method.
- Declare the string array that contains the names of the city.
- Declare an integer array that contains the weight.
- Create an object for unweighted graph.
- Print the size of the graph, vertex of the graph, index of the vertex “Miami”, and the edges of the graph.
- Call the function “maxInducedSubgraph ()”.
- Print the size of the graph, vertex of the graph, index of the vertex “Miami”, and the edges of the graph.
- Give function definition for “maxInducedSubgraph ()”.
- Declare required variables
- Do until the condition “(!Isdone && g.getSize() > 0)” fails.
- Assign “true” to the variable.
- Loop from 0 through size.
- Check the condition “(g.getDegree(i) < k)”.
- Call the function “remove_Vertex ()”.
- Assign false to the variable.
- Break the loop.
- Check the condition “(g.getDegree(i) < k)”.
- Return the graph.
- Function definition for “UnweightedGraphInducedSubgraph ()”.
- Construct the empty graph.
- Construct a graph from vertices and edges stored in arrays.
- Get the vertices and edges.
- Construct a graph from vertices and edges stored in List.
- Get the vertices and edges.
- Construct a graph for integer vertices 0, 1, 2 and edge list.
- Get the vertices and edges.
- Construct a graph from integer vertices 0, 1, and edge array.
- Get the vertices and edges.
- Give function definition for “remove_Vertex ()”.
- Check the condition “(vertices.contains(v))”.
- Get the index.
- Call the functions “vertices.remove ()”, and “neighbors.remove ()”.
- Loop to remove the edges.
- Loop from 0 through size.
- Check the condition “(list.get(i).v == index)”. If it is true then remove the edge.
- Else, increment the variable
- Loop from 0 through size.
- Loop to reassign the labels.
- Loop from 0 through size.
- Check the condition “(list.get(i).u >= index)”. If the condition is true then get the edge
- Check the condtion “(list.get(i).v >= index)”. If the condition is true then get the edge
- Loop from 0 through size.
- Return “true”.
- Else,
- Return “false”.
- Check the condition “(vertices.contains(v))”.
- Give the “main ()” method.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
2.
Q1)
You are given an undirected connected planar graph. There are 10 vertices and 7 faces in the graph. What is the number of edges in the graph?
Note that: A graph is said to be planar if it can be drawn in a plane so that no edge cross.
Q2)
In how many ways can we pick any number of balls from a pack of three different balls?
Q3)
The distance between 2 points A and B is 1320Km. Two cars start moving towards each other with 50 Km/hr and 60 Km/hr. After how many hours do they meet?
(0)URGENT!!!!
Please use this graph class and SOLVE FOR ISOLATEDTRIPLETS QUESTION AND AVERAGE BALANCE RATIO
Here is the graph class:
public class Graph {private final int V;private int E;private final Bag<Integer>[] adj;
/*** Create an empty graph with V vertices.*/@SuppressWarnings("unchecked")public Graph(int V) {if (V < 0) throw new Error("Number of vertices must be nonnegative");this.V = V;this.E = 0;this.adj = new Bag[V];for (int v = 0; v < V; v++) {adj[v] = new Bag<>();}}
/*** Return the number of vertices in the graph.*/public int V() { return V; }
/*** Return the number of edges in the graph.*/public int E() { return E; }
/*** Add the undirected edge v-w to graph.* @throws java.lang.IndexOutOfBoundsException unless both 0 <= v < V and 0 <= w < V*/public void addEdge(int v, int w) {if (v < 0 || v >= V) throw new IndexOutOfBoundsException();if (w < 0 || w >= V) throw new IndexOutOfBoundsException();E++;adj[v].add(w);adj[w].add(v);}
/***…
Application
"networkx" library is used for implementing graphs. Draw a graph using this
library in python. (Hint: use 'add_node()", 'add_edge()' functions to draw edges
and nodes). Construct the graph shown in figure using python language. Also,
plot the graph using matplotlib library, Traverse the graph using DFS, and output
the DFS order.
2
Chapter 28 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package
Ch. 28.2 - What is the famous Seven Bridges of Knigsberg...Ch. 28.2 - Prob. 28.2.2CPCh. 28.2 - Prob. 28.2.3CPCh. 28.2 - Prob. 28.2.4CPCh. 28.3 - Prob. 28.3.1CPCh. 28.3 - Prob. 28.3.2CPCh. 28.4 - Prob. 28.4.1CPCh. 28.4 - Prob. 28.4.2CPCh. 28.4 - Show the output of the following code: public...Ch. 28.4 - Prob. 28.4.4CP
Ch. 28.5 - Prob. 28.5.2CPCh. 28.6 - Prob. 28.6.1CPCh. 28.6 - Prob. 28.6.2CPCh. 28.7 - Prob. 28.7.1CPCh. 28.7 - Prob. 28.7.2CPCh. 28.7 - Prob. 28.7.3CPCh. 28.7 - Prob. 28.7.4CPCh. 28.7 - Prob. 28.7.5CPCh. 28.8 - Prob. 28.8.1CPCh. 28.8 - When you click the mouse inside a circle, does the...Ch. 28.8 - Prob. 28.8.3CPCh. 28.9 - Prob. 28.9.1CPCh. 28.9 - Prob. 28.9.2CPCh. 28.9 - Prob. 28.9.3CPCh. 28.9 - Prob. 28.9.4CPCh. 28.10 - Prob. 28.10.1CPCh. 28.10 - Prob. 28.10.2CPCh. 28.10 - Prob. 28.10.3CPCh. 28.10 - If lines 26 and 27 are swapped in Listing 28.13,...Ch. 28 - Prob. 28.1PECh. 28 - (Create a file for a graph) Modify Listing 28.2,...Ch. 28 - Prob. 28.3PECh. 28 - Prob. 28.4PECh. 28 - (Detect cycles) Define a new class named...Ch. 28 - Prob. 28.7PECh. 28 - Prob. 28.8PECh. 28 - Prob. 28.9PECh. 28 - Prob. 28.10PECh. 28 - (Revise Listing 28.14, NineTail.java) The program...Ch. 28 - (Variation of the nine tails problem) In the nine...Ch. 28 - (4 4 16 tails problem) Listing 28.14,...Ch. 28 - (4 4 16 tails analysis) The nine tails problem in...Ch. 28 - (4 4 16 tails GUI) Rewrite Programming Exercise...Ch. 28 - Prob. 28.16PECh. 28 - Prob. 28.17PECh. 28 - Prob. 28.19PECh. 28 - (Display a graph) Write a program that reads a...Ch. 28 - Prob. 28.21PECh. 28 - Prob. 28.22PECh. 28 - (Connected rectangles) Listing 28.10,...Ch. 28 - Prob. 28.24PECh. 28 - (Implement remove(V v)) Modify Listing 28.4,...Ch. 28 - (Implement remove(int u, int v)) Modify Listing...
Knowledge Booster
Similar questions
- 2. Use the following description of an undirected graph and draw the graph: v(Graph1) = { A, B, C, D} E(Graph1) = { (A,B), (A,D), (B,C), (B,D) }arrow_forward7- A student has created a plot of y(t)=t^2. He needs to show another graph of z(t)=t^3 in the same plot. But every time he hits the plot() function- MATLAB generates a plot of z(t) vs t but on a different window. What is the error? O It is not possible to plot multiple plots O He is not using the line function Maybe he is using polar() instead of plot() O He is not using the hold functionarrow_forwardUsing the graph in the question: Write Java code to create an Adjacency Matrix M to represent the graph. Write Java code to create an Adjacency List L to represent the graph.arrow_forward
- Transcribed Image Text Elon Musk is running the graph construction business. A client has asked for a special graph. A graph is called special if it satisfies the following properties: • It has <105 vertices. It is a simple, undirected, connected 3-regular graph. It has exactly k bridge edges, (k given as input). For a graph G, define f(G) to be the minimum number of edges to be removed from it to make it bipartite. The client doesn't like graphs with a high value of f, so you have to minimize it. If there doesn't exist any special graph, print –1. Otherwise, find a special graph G with the minimum possible value of f(G) and also find a subset of its edges of size f(G) whose removal makes it bipartite. In case there are multiple such graphs, you can output any of those. Elon has assigned this task to you, now vou have to develon a C++ code that takes bridge edges as innut and print all the possible granhsarrow_forward1. This question is about type of graphs. a. Construct a graph with exactly 5 nodes such that the graph is strongly connected. b. Construct a graph with exactly 5 nodes such that the graph is weakly connected. c. Construct a graph with exactly 5 nodes such that the graph is completely connected. d. Construct a graph with exactly 5 nodes such that the graph is not connected. e. Construct a graph with exactly 5 nodes such that the graph is not a simple graph.arrow_forwardPick all statements that apply to this directed graph. A) Every node is reachable from node c. (Do not include node c.) B) From node a to node g there are at least 3 different paths, all with different lengths. C) There are no cycles in this graph. D) There is a loop in this graph. E) There is a path from node e to node f of length 3.arrow_forward
- *Discrete Math In the graph above, let ε = {2, 3}, Let G−ε be the graph that is obtained from G by deleting the edge {2,3}. Let G∗ be the graph that is obtain from G − ε by merging 2 and 3 into a single vertex w. (As in the notes, v is adjacent to w in the new if and only if either {2,v} or {3,v is an edge of G.) (a) Draw G − ε and calculate its chromatic polynomial. (b) Give an example of a vertex coloring that is proper for G − ε, but not for G. (c) Explain, in own words, why no coloring can be proper for G but not proper for G − ε. (d) Draw G∗ and calculate its chromatic polynomial. (e) Verify that, for this example,PG(k) = PG−ε(k) − PG∗ (k).arrow_forward[] [] dir_euler Write a function "dir_euler(digraph)" that takes in a connected, directed graph as its input, and then determines whether or not a directed Eulerian circuit exists. After compiling the above cell, you should be able to compile the following cell and obtain the desired outputs. print(dir_euler({"A" : ["A", "B", "C"], "B" : ["A"], "C" : ["A"]}), dir_euler({"A" : ["B", "D"], "B" : ["A", "D"], "C" : This should return True False ["C", "D"], "D" : []})) Python Pythonarrow_forwardUse c++ language Implement the isNeighbor(int u, int v) method. This method should return true if v is a neighbor of u and false otherwise. bool Graph::isNeighbor(int u, int v) { code here... }arrow_forward
- Create the following graph. Implement the following functions. 1. addEdge() that takes two vertices as two parameters and creates an Edge between them. 2. nonAdjacentVertices() that takes a single vertex as parameter, and returns an array of vertices that are NOT adjacent to that vertex. 3. Write a function addUnknownVertices() that takes a vertex as a parameters, and creates an Edge with the vertices that are NOT adjacent to it. 4. Write a method searchVertex() which takes an array of Vertices as parameters. The first member of the array will be the starting vertex and the last member will be the Vertex you want to reach. For example searchVertex(Vertex 0, Vertex 4, Vertex 3) will output “Vertex cannot be reached” since you can reach from 0 to 4, but cannot from 4 to 3. Again, searchVertex(Vertex 0, Vertex 1, Vertex 2, Node 3) will output “Vertex can be reached” since you can reach from 0 to 1, 1 to 2, 2 to 3.arrow_forward1. Input: An unweighted graph G = (V, E).2. Output: C = {C1,C2,...,Ck }, k clusters of G.3. Calculate edge betweenness value ∀(u, v) ∈ E.4. Remove all edges from G that have a higher betweenness value than a threshold τ .5. Find the components of GN which are the clusters of G.Write Python Implementation considering figurearrow_forwardIn graph theory, graph coloring is a special case of graph labeling; it is an assignment of labels traditionally called "colors" to elements of a graph subject to certain constraints. In its simplest form, it is a way of coloring the vertices of a graph such that no two adjacent vertices share the same color; this is called a vertex coloring. The chromatic number of a graph is the least mumber of colors required to do a coloring of a graph. Example Here in this graph the chromatic number is 3 since we used 3 colors The degree of a vertex v in a graph (without loops) is the number of edges at v. If there are loops at v each loop contributes 2 to the valence of v. A graph is connected if for any pair of vertices u and v one can get from u to v by moving along the edges of the graph. Such routes that move along edges are known by different names: edge progressions, paths, simple paths, walks, trails, circuits, cycles, etc. a. Write down the degree of the 16 vertices in the graph below: 14…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education