Question
Given vertex v of graph G = (V,E), we define G-v = (V-{v},E'),where E'= { e E | e is not incident with v }
Given vertex v of graph G = (V,E), we define G-v = (V-{v},E'),where E'= { e E | e is not incident with v } That is, the graph we get by deleting v and all edges having v as an endpoint Vertex v is said to be a cutpoint of connected graph G is G-v is not connected. Our goal is to find all the cutpoints of a graphWe will do this via a class methodDepth-first search is the main tool we use, although BFS could be used instead.
We will adapt depth-first search to determine if G-v is connected We use a little trick to do thisA crucial data structure used is vector
FILL THE MISSISNG CODE ONLY
//graph.h
#ifndef GRPH #define GRPH #include
using namespace std;
struct vnode { int vertex; vnode *next; vnode(int u, vnode *n): vertex(u), next(n){}; };
typedef vnode * vnodeptr;
class graph { public: graph(); // interactive constructor using cin bool connected(int excluded); void dfs(vector
-------------------------------------------------
//graph.cpp
#include "graph.h" #ininclude
int vertex; cin >> size; adjList.resize(size,NULL); for(int i = 0; i < size; ++i) { cin >> vertex; while(vertex != -1) { adjList[i] = new vnode(vertex,adjList[i]); // insert at begining cin >> vertex; } } } int firstFalse(vector
vector
----------------------
//cut_tester.cpp
#include "graph.h" using namespace std;
int main() { graph G; if(!G.connected(-1)) { cout << "Graph is not connected; terminating" << endl; return 1; } vector
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started