Earn Higher Grades With Instant Academic Help.Ask Question!

(5/5)

### The task is to implement a directed_graph class, where each node/edge has a weight. The class should offer a reasonably effective suite of operations.

INSTRUCTIONS TO CANDIDATES
###### ANSWER ALL QUESTIONS

The task is to implement a directed_graph class, where each node/edge has a weight.

The class should offer a reasonably effective suite of operations. Some (but not all) of basic operations are:

• Adding and removing nodes and edges (with weights);

• Depth-first and breadth-first traversals;

• Computing the minimum spanning tree (MST);

• Pre-order, in-order, and post-order traversals of the MST

#ifndef DIRECTED_GRAPH_H

#define DIRECTED_GRAPH_H

#include

#include

#include

// include more libraries here if you need to

using namespace std; // the standard namespace are here just in case.

/*

the vertex class

*/

template

class vertex {

public:

int id;

T weight;

vertex(int x, T y) : id(x), weight(y) {}

// add more functions here if you need to

};

/*

the graph class

*/

template

class directed_graph {

private:

//You will need to add some data members here

//to actually represent the graph internally,

//and keep track of whatever you need to.

public:

directed_graph(); //A constructor for directed_graph. The graph should start empty.

~directed_graph(); //A destructor. Depending on how you do things, this may not be necessary.

bool contains(const int&) const; //Returns true if the graph contains the given vertex_id, false otherwise.

bool adjacent(const int&, const int&) const; //Returns true if the first vertex is adjacent to the second, false otherwise.

void add_vertex(const vertex&); //Adds the passed in vertex to the graph (with no edges).

void add_edge(const int&, const int&, const T&); //Adds a weighted edge from the first vertex to the second.

void remove_vertex(const int&); //Removes the given vertex. Should also clear any incident edges.

void remove_edge(const int&, const int&); //Removes the edge between the two vertices, if it exists.

size_t in_degree(const int&) const; //Returns number of edges coming in to a vertex.

size_t out_degree(const int&) const; //Returns the number of edges leaving a vertex.

size_t degree(const int&) const; //Returns the degree of the vertex (both in edges and out edges).

size_t num_vertices() const; //Returns the total number of vertices in the graph.

size_t num_edges() const; //Returns the total number of edges in the graph.

vector get_vertices(); //Returns a vector containing all the vertices.

vector get_neighbours(const int&); //Returns a vector containing all the vertices reachable from the given vertex. The vertex is not considered a neighbour of itself.

vector get_second_order_neighbours(const int&); // Returns a vector containing all the second_order_neighbours (i.e., neighbours of neighbours) of the given vertex.

// A vector cannot be considered a second_order_neighbour of itself.

bool reachable(const int&, const int&) const; //Returns true if the second vertex is reachable from the first (can you follow a path of out-edges to get from the first to the second?). Returns false otherwise.

bool contain_cycles() const; // Return true if the graph contains cycles (there is a path from any vertices directly/indirectly to itself), false otherwise.

vector depth_first(const int&); //Returns the vertices of the graph in the order they are visited in by a depth-first traversal starting at the given vertex.

vector breadth_first(const int&); //Returns the vertices of the graph in the order they are visisted in by a breadth-first traversal starting at the given vertex.

directed_graph out_tree(const int&); //Returns a spanning tree of the graph starting at the given vertex using the out-edges. This means every vertex in the tree is reachable from the root.

vector pre_order_traversal(const int&, directed_graph&); // returns the vertices in the visiting order of a pre-order traversal of the minimum spanning tree starting at the given vertex.

vector in_order_traversal(const int&, directed_graph&); // returns the vertices in the visiting order of an in-order traversal of the minimum spanning tree starting at the given vertex.

vector post_order_traversal(const int&, directed_graph&); // returns the vertices in ther visitig order of a post-order traversal of the minimum spanning tree starting at the given vertex.

vector significance_sorting(); // Return a vector containing a sorted list of the vertices in descending order of their significance.

};

// Define all your methods down here (or move them up into the header, but be careful you don't double up). If you want to move this into another file, you can, but you should #include the file here.

// Although these are just the same names copied from above, you may find a few more clues in the full method headers.

// Note also that C++ is sensitive to the order you declare and define things in - you have to have it available before you use it.

(5/5)

## Related Questions

##### . Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

##### . The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

##### . Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

##### . SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

##### . Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

### Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed ##### Ashutosh NautiyalComputer science
(/5)

792 Answers

Hire Me ##### Smayan DasComputer science
(/5)

989 Answers

Hire Me ##### Goueth Issola Gouater Loic DimitriEngineering
(/5)

805 Answers

Hire Me (4/5)

12 Answers

Hire Me