Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q2) A: Returns all the vertices in the graph that are reachable from the given {source} vertex. vectorint > get_reachable_from ( int source) const B:

Q2)
A: Returns all the vertices in the graph that are reachable from the given {source} vertex. vectorint> get_reachable_from(int source) const B: Returns all the connected components in the graph assuming that the graph is undirected. The vertices of each component are stored in a separate vector. vectorint>> get_connected_components() const
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
You are given an incomplete class in graph.h representing a directed weighted graph. The graph is represented using an adjacency list that stores objects of type Edge in the adjacency list of each vertex. Each Edge object represents a directed weighted edge, storing the weight, the source vertex (from) and the destination vertex (to). 8 2 frono to a weight 4 from o to 1 weight 7 from @ to 2 weight from 1 1 5 5 4 6 2 2 -:- 3 0 0 from = 0 to 3 weight = 4 from = 0 to 11 weight = 7 from = @ to = 2 weight = 5 1 from = 1 to = 3 weight = 6 N 3 from = 3 to - 1 weight = 2 from = 3 to 22 weight = 1 int V; 24 // Represents a directed weighted graph. Can also 25 // be used to represent an undirected weighted graph. 26 class Graph { 27 private: 28 // number of vertices 29 list *adi; // adjacency lists 30 31 public: 32 Graph(int v) { 33 this->V = V; 34 adj = new list [V]; 35 } -Graph() { delete [] adj; } 37 int get_vo const { return V; } 38 39 7/ adds an edge from v to w with the given weight 40 void add_edge(int v, int w, double weight) { 41 if (weight get_reachable_from(int s) const; 58 69 Q2.B 40 47 48 49 50 there is an eage trom v to w bool has_edge(int v, int w) const { for (Edge edge : adj[v]) if (edge. to == w) return true; return false; } 51 52 53 54 55 56 57 58 Il prints the graph void print() const { for (int v ; v get_reachable_from(int s) const; 71 Q2.B vector> connected_components() const; me/graph. 1:1 Spaces: 4 (Auto)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions