EBK DATA STRUCTURES AND ALGORITHMS IN C
4th Edition
ISBN: 9781285415017
Author: DROZDEK
Publisher: YUZU
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Alert dont submit AI generated answer.
Write a program that reads a weighted graph and an initial vertex.The program must print on the screen the minimum paths obtained by Dijkstra's algorithm.
Input: Receives n, m and s; n is the total number of vertices, m the total number of arcs and s is the initial vertex.Next, m lines, each line with a trio of integers, corresponding to the beginning and end of the arc, followed by the weight of the arc.(Vertices are identified from 0 to n-1.)
Output: Prints the shortest paths obtained by Dijkstra's algorithm.
Exemple:
Input:
5 10 00 1 100 4 51 2 11 4 22 3 43 2 63 0 74 1 34 2 94 3 2
Output:
[0, 8, 9, 7, 5][-1, 4, 1, 4, 0]
In a graph, two vertices are connected if there is a path between them. If all vertices are connected, we say the graph is connected. Given the Graph ADT below:
class Graph {
public:
void addEdge (int vl, int v2);
void delEdge (int vl, int v2);
bool hasEdge (int v1, int v2) const;
VList adj (int v) const;
int v() const;
int e()
const;
} ;
Fill in the function isConnected that tells whether graph g is connected or not.
Note that you can only use the above methods for g. You may assume vertex ID starts from 0 and define other helper functions if necessary.
bool isConnected (const Graph &g) {
// Copy this function in the answer and add code below this line.
For the toolbar, press ALT+F10 (PC) or ALT+FN+F10 (Mac).
IN java
Make a dijkestra algorithm that is efficient with large data sets
Runs Dijkstra's algorithm on the graph, starting at the node specified by the start parameter.
* Return a map where the key is the name of the node and the value is the distance from the start node.
* The start node should be included in the returned map, with the value 0 as the distance.
*
* @param start - a5.Node to start Dijkstra's algorithm at
* @return Map of all the nodes in the graph and the distance to the start a5.Node.
*/
these is the description of the method
the method signature is below
public Map<String, Double> dijkstra(String start);
Class that this method is in is below
public class GraphImpl implements Graph {
Map<String, Node> nodes; //do not delete, use this field to store your nodes
// key: name of node. value: a5.Node object associated with name
privateinttotaledges;
publicGraphImpl() {
nodes = newHashMap<>();…
Chapter 8 Solutions
EBK DATA STRUCTURES AND ALGORITHMS IN C
Knowledge Booster
Similar questions
- Algorithm: Algebraic JP Algorithm1: Input : G(V, E), directed or undirected graph2: Output :3: s=0;4: wt ← 0;5: s(1)=∞;6: π ← Ø;7: d = D(1, :);8: while s = ∞9: i=argmin{s + d};10: s(i) = ∞;11: < w, p >=d(i)12: wt = wt + d(u);13: π(i) = p14: d = d.min A(i, :);15: Make Python implementation of the algebraic algorithm is shown above need clean code with explainationarrow_forwardQ- In order to plot a graph of f(x)=z and g(y)=z in the same graph, with t as a parameter. The function used is plot3(x,y,z) O plot(x,y,z) O surf(x,y,z) O mesh(z) Oarrow_forwardQuestion 3 The figure below shows the structure of a directed graph. Write a method that finds a possible starting point(vertex) for a topological order in this graph. class edge { class vertex { int vertexId; class vertex nextVertex; class edge edgeLink; int vertexId; class vertex vertexLink; class edge nextEdge; }; }; 1 3 edge. Starting vertex is 1, ending 2 vertex is 3 3 2 vertex 1arrow_forward
- Algorithm: Algebraic JP Algorithm1: Input : G(V, E), directed or undirected graph2: Output :3: s=0;4: wt ← 0;5: s(1)=∞;6: π ← Ø;7: d = D(1, :);8: while s = ∞9: i=argmin{s + d};10: s(i) = ∞;11: < w, p >=d(i)12: wt = wt + d(u);13: π(i) = p14: d = d.min A(i, :);15: Make Python implementation of the algebraic algorithm is shown abovearrow_forward5. Vertices: (a, b, c, d, e, f, g) Edges: {(a, b), (a, f), (b, e), (b, g). (c. f). (c. g). (c. d), (d. e), (d. g} } Draw a Graph for the given vertices and edges. Find the adjacent vertices of a vertex c. Find the shortest path between source vertex f and destination vertex e.arrow_forwardbool DelOddCopEven(Node* headPtr) { if (headPtr == nullptr) { return false; } Node* prev = nullptr; Node* current = headPtr; while (current != nullptr) { if (current->data % 2 != 0) { // Odd-valued node, delete it if (prev != nullptr) { prev->link = current->link; } else { headPtr = current->link; } Node* temp = current; current = current->link; delete temp; } else { // Even-valued node, create a copy and insert it after the original node Node* newNode = new Node; newNode->data = current->data; newNode->link = current->link; current->link = newNode; // Update the previous and current pointers prev = newNode; current = newNode->link; } } return true;} int FindListLength(Node* headPtr){ int length = 0;…arrow_forward
- When a vertex Q is connected by an edge to a vertex K, what is the term for the relationship between Q and K? *a) Q and K are "insecure."b) Q and K are "incident."c) Q and K are "adjacent."d) Q and K are "isolated."arrow_forward6 591 9 1 75 1 3 10 8 8 5 8 G746arrow_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
- Graph Transversal Simulation: For this graph write down the order of vertices encountered in a breadth-first search starting from vertex A. Break ties by picking the vertices in alphabetical order (for example, A before Z)arrow_forwardQ9-A student has to plot a graph of f(x)=z and g(y)=z in the same graph, with t as a parameter. The function he uses is O plot3(x,y,z) plot(x,y,z) disp O stem(x,y)arrow_forwardvector<VertexT> Vertices; map<VertexT, vector<list>> adjList; What is the worst case time complexity for this version of _LookupVertex? bool _LookupVertex(VertexT v) const { if (adjList.count(v) != 0) { return true; } return false; } V is the number of total vertices in the graph, E is the average number of edges per vertex. O(v) O(VlogE) O(logV) O(V^2) O(E+V)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