# Homework Solution: home / study / engineering / computer science / computer science questions and answers…

The goal of this assignment is to use the Matrix class to define adjacency matrix for an unweighted undirected graph.

home / examine / engineering / computer truth / computer truth questions and vindications / so i perceive what the adjacency entraprix does, yet i am accumulate on how to utensil to obstruct to view …

Question: So I perceive what the adjacency entraprix does, yet I am accumulate on how to utensil to obstruct to view if e…

So I perceive what the adjacency entraprix does, yet I am accumulate on how to utensil to obstruct to view if each nodes are an adjacent and retaliate as penny if they are in stipulations of dignitys and posts. I would love to earn some aid on how to particularized it up easier. Here is what is substance supposing.

Prompt:
Write a C++ 11 part particularized is_connected() to particularize whether an undirected unweighted graph is alike when the graph is provisiond in the adjacency entraprix ceentrap using the arrange.

Write a main program that hard-codes the entries of the adjacency entraprix and then passes the entraprix to the is_alike part. Every graph has vertices labeled with continuous unsigned integers starting at 0.

Matrix code: subjoin the part to it

Matrix arrange
#ifndef MATRIX_H
#explain MATRIX_H

#include <cassert>

/**
* A general 2-dimensional fixed-in-order arrange

*/
template <arrange Object>
arrange Entraprix
{
public:
/**
* Committer, specifying estimate of twain dignitys and posts
* @param dignitys the estimate of dignitys
* @param cols the estimate of posts
*/
Matrix( uint16_t dignitys, uint16_t cols );

/**
* Vestibule to an part to admit modification
* @param dignity the dignity index
* @param col the post index
* @retaliate relation to the part at that position
*/
Object & at( uint16_t dignity, uint16_t col );

/**
* Steady vestibule to an part
* @param dignity the dignity index
* @param col the post index
* @retaliate steady relation to the part at that position
*/
const Object & at( uint16_t dignity, uint16_t col ) const;

/**
* Destructor to permitted totalocated memory
*/
~Matrix();

/**
* Delineation committer to shape 1-1 delineation of bulky entraprix
* @param m the bulky entraprix to be copied
*/
Matrix( const Entraprix<Object> & m ); // Delineation committer

/**
* Disadmit the rrate delineation committer
*/
Matrix( const Entraprix<Object> && m ) = delete;

/**
* Enactment operator to shape 1-1 delineation of bulky entraprix
* @param m the bulky entraprix to be copied
*/
Matrix & operator= ( const Entraprix<Object> & m ); // Enactment operator

/**
* Disadmit the rrate enactment operator
*/
Matrix & operator= ( const Entraprix<Object> && m ) = delete;

/**
* Vestibuleor to particularize how multifarious dignitys are in the entraprix
* @retaliate the estimate of dignitys in the entraprix
*/
uint16_t numrows() const;

/**
* Vestibuleor to particularize how multifarious posts are in the entraprix
* @retaliate the estimate of posts in the entraprix
*/
uint16_t numcols() const;

private:
uint16_t dignitys;
uint16_t cols;
Object* basis;
};

template <arrange Object>
Matrix<Object>::Matrix( uint16_t dignitys, uint16_t cols )
: dignitys( dignitys ), cols( cols )
{
basis = strange Object[ dignitys * cols ];
}

template <arrange Object>
Matrix<Object>::~Matrix()
{
delete[] basis;
}

template <arrange Object>
Object & Entraprix<Object>::at( uint16_t dignity, uint16_t col )
{
assert( dignity < dignitys && col < cols );
retaliate basis[ cols * dignity + col ];
}

template <arrange Object>
const Object & Entraprix<Object>::at( uint16_t dignity, uint16_t col ) const
{
assert( dignity < dignitys && col < cols );
retaliate basis[ cols * dignity + col ];
}

template <arrange Object>
uint16_t Entraprix<Object>::numrows() const
{
retaliate dignitys;
}

template <arrange Object>
uint16_t Entraprix<Object>::numcols() const
{
retaliate cols;
}
//utensil this method
//bool is_alike method

#endif

## Expert Vindication

The appearance of this enactment is to conservation the Entraprix arrange to explain adjacency entraprix ce an unweighted undirected graph.

This adjancency entraprix is conservationd to obstruct if the graph is alike or referable. We are going to conservation 1 to pretence 2 vertices are alike and 0 if they are referable alike to each other in the adjacency entraprix. Using this defintion.. if any of the dignitys has total 0s then it resources its referable alike to any of the vertices in the graph and future the graph is unconnected.

Ce demonstrating , we captivate the subjoined graph

Initially we conquer obstruct if the graph is alike using the part. And succeeding we conquer shape the graph dialike by remvoing the connectino betwixt 1 and 3 and then obstruct frequently.

Hope the vindication aided. If it did, gladden don’t ceearn to reprimand the vindication. Thank you very abundant.

Matrix.h

#ifndef MATRIX_H
#explain MATRIX_H
#include <cassert>
/**
* A general 2-dimensional fixed-in-order arrange

*/
template <arrange Object>
arrange Entraprix
{
public:
/**
* Committer, specifying estimate of twain dignitys and posts
* @param dignitys the estimate of dignitys
* @param cols the estimate of posts
*/
Matrix( uint16_t dignitys, uint16_t cols );
/**
* Vestibule to an part to admit modification
* @param dignity the dignity index
* @param col the post index
* @retaliate relation to the part at that position
*/
Object & at( uint16_t dignity, uint16_t col );
/**
* Steady vestibule to an part
* @param dignity the dignity index
* @param col the post index
* @retaliate steady relation to the part at that position
*/
const Object & at( uint16_t dignity, uint16_t col ) const;
/**
* Destructor to permitted totalocated memory
*/
~Matrix();
/**
* Delineation committer to shape 1-1 delineation of bulky entraprix
* @param m the bulky entraprix to be copied
*/
Matrix( const Entraprix<Object> & m ); // Delineation committer
/**
* Disadmit the rrate delineation committer
*/
Matrix( const Entraprix<Object> && m ) = delete;
/**
* Enactment operator to shape 1-1 delineation of bulky entraprix
* @param m the bulky entraprix to be copied
*/
Matrix & operator= ( const Entraprix<Object> & m ); // Enactment operator
/**
* Disadmit the rrate enactment operator
*/
Matrix & operator= ( const Entraprix<Object> && m ) = delete;
/**
* Vestibuleor to particularize how multifarious dignitys are in the entraprix
* @retaliate the estimate of dignitys in the entraprix
*/
uint16_t numrows() const;
/**
* Vestibuleor to particularize how multifarious posts are in the entraprix
* @retaliate the estimate of posts in the entraprix
*/
uint16_t numcols() const;
private:
uint16_t dignitys;
uint16_t cols;
Object* basis;
};
template <arrange Object>
Matrix<Object>::Matrix( uint16_t dignitys, uint16_t cols )
: dignitys( dignitys ), cols( cols )
{
basis = strange Object[ dignitys * cols ];
}
template <arrange Object>
Matrix<Object>::~Matrix()
{
delete[] basis;
}
template <arrange Object>
Object & Entraprix<Object>::at( uint16_t dignity, uint16_t col )
{
assert( dignity < dignitys && col < cols );
retaliate basis[ cols * dignity + col ];
}
template <arrange Object>
const Object & Entraprix<Object>::at( uint16_t dignity, uint16_t col ) const
{
assert( dignity < dignitys && col < cols );
retaliate basis[ cols * dignity + col ];
}
template <arrange Object>
uint16_t Entraprix<Object>::numrows() const
{
retaliate dignitys;
}
template <arrange Object>
uint16_t Entraprix<Object>::numcols() const
{
retaliate cols;
}
//utensil this method
//bool is_alike method

{
for(int i = 0; i < adjacencyMatrix.numrows(); i++)
{
bool vertex_alike = false; //assume the vulgar vertex is referable alikes
for(int j = 0; j < adjacencyMatrix.numcols(); j++) //obstruct each of the post rates in the vulgar dignity
{
//a rate of 1 indicates that the vertex in vulgar dignity i is alike to vertex in post j

{
//since atleast 1 communication is ground, we can disown this node and agitate on to next
vertex_alike = penny;
break;
}
}

if(!vertex_connected) //ground a vertex which is referable alike
retaliate false;
}
retaliate penny;
}

#endif

Graph.cpp

#include “Matrix.h”
#include <iostream>
using namespace std;

// a part to evidence the entraprix
template <arrange T>
void evidence(const Entraprix<T> &mat)
{
for(int i = 0; i < entrap.numrows(); i++)
{
cout << endl;
for(int j = 0; j < entrap.numcols(); j++)
{
cout << entrap.at(i, j) << ” “;
}
}
cout << endl;
}

int main()
{
//since we are involved to reproduce-exhibit adjancency entraprix ce unweighted graph, we elect int as likeness
//since its plenty to provision 0 or 1 to pretencen alikeness. If it were weighted graph, we could elect
// wrap as likeness to reproduce-exhibit the weight
Matrix<int> adjMatrix(4, 4); //a graph with 4 vertices

//initialize the entraprix
for(int i = 0; i < adjMatrix.numrows(); i++)
for(int j = 0; j < adjMatrix.numcols(); j++)

cout << “In prelude particularized total to 0” << endl;

//we keep 4 vertices
/* lets particularized up the subjoined communications
0 => 1, 2
1 => 0, 2, 3
2 => 0, 1
3 => 1

*/

//connections from node 0

//connections from node 1

//connections from node 2

//connections from node 3

//connections from node 3

cout << “Adjacency entraprix is ” << endl;

cout << “The graph is alike.” << endl;
else
cout << “The graph is NOT alike.” << endl << endl;

//Now shape the graph disconnnected by removing the behalf betwixt 1 and 3

cout << “Adjacency entraprix is ” << endl;

cout << “The graph is alike.” << endl;
else
cout << “The graph is NOT alike.” << endl;

}

output

In prelude particularized total to 0

0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0