logo Hurry, Grab up to 30% discount on the entire course
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
SYED MOHAMMED HASAN RIZVIMathematics
(/5)

664 Answers

Hire Me
expert
Zaiden GarzaResume writing
(5/5)

569 Answers

Hire Me
expert
Robert NjueSocial sciences
(/5)

561 Answers

Hire Me
expert
Jefferson KnowlesSociology
(5/5)

882 Answers

Hire Me
C++ Programming

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.

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. 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

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme