Question: Please code this in C + + . Please be sure all of these functions have circumstances where they return true, and some where they
Please code this in C Please be sure all of these functions have circumstances where they return true, and some where they return false. THis should be based on the name of each function. a pts Implement the bool isTwoColorable method. This method should return true if the vertices of the graph can each be assigned one of two colors such that no pair of adjacent nodes have the same color and false otherwise. Graph coloring is a very interesting question in general with important connections to a variety of applications including scheduling and resource allocation. b pts Implement the bool isConnected method. This method should return true if the graph is connected and false otherwise. Recall that an undirected graph G V E is connected if for all pairs of vertices u v in V there is at least one path between u and v c pts Implement the bool hasCycle method. This method should return true if the graph has at least one cycle and false otherwise. Recall that an undirected graph G V E has a cycle if there exist vertices u v in V such that there are at least two distinct paths between u and v The method bool has CycleRecurint s might be helpful here. You are not required to implement this method. It is intended to serve a similar purpose as DFSVisit. pts Implement the bool isReachableint u int v method. This method should return true if node v is reachable from node u Note that, since we are dealing with undirected graphs, if v is reachable from u u is reachable from v as well. In general, v is reachable from u if there is a path from u to v in the graph. Here is the code to be modified: bool Graph::isTwoColorable return false; bool Graph::isConnected return false; bool Graph::hasCycle return false; bool Graph::hasCycleRecurint s return false; bool Graph::isReachableint u int v return false; Here are some header files you will need: Graph.h: #ifndef GRAPHH #define GRAPHH #include #include #include "Node.h class Graph public: std::vector nodes; Graph; void printAdjList; bool isNeighborint int; void DFS; int DFSVisitint int; void BFSint; std::vector distancesFromint; bool isTwoColorable; bool isConnected; bool hasCycle; bool hasCycleRecurint; bool isReachableint int; ; #endif Node.h: #ifndef NODEH #define NODEH #include #include #include class Node public: int id; int dist; int discovered; int finished; bool visited; std::sharedptr predecessor; std::string color; std::vector neighbors; Node; Nodeint; ; #endif Node.cpp: #include "Node.h #include Node::Node id ; dist INTMAX; discovered ; finished ; visited false; color ; predecessor nullptr; neighbors ; Node::Nodeint i id i; dist INTMAX; discovered ; finished ; visited false; color ; predecessor nullptr; neighbors ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
