UCR - CS 010C Assignment 4 Deliverables: Create a single PDF file that contains your answers to the questions. Then create a zip file that contains this PDF file along with all your code source files....

1 answer below »
C++ graph implementation


UCR - CS 010C Assignment 4 Deliverables: Create a single PDF file that contains your answers to the questions. Then create a zip file that contains this PDF file along with all your code source files. Submit this zip file on iLearn. Deadline: 12/11/2020 11:59 pm. Exercise 1 Use provided C++ skeleton to insert your code. A. Define Graph, which stores an undirected graph using adjacency list, where each node stores a CityName (string) and each edge has a double weight (distance between two cities). Implement the following functions in Graph: a. bool hasTripletClique():returns true if there are three nodes in the graph that are all connected to each other. E.g., a, b, c, with edges (a, b), (b, c), and (a, c) b. bool isConnected(): returns true if graph is connected c. double getMinDistance(string city1,string city2): returns the shortest path distance between city1 and city 2. Hint: You may use Dijkstra Algorithm. d. [extra credit] double getLongestSimplePath(): returns length of longest simple path (no cycle allowed) B. What is the big-Oh complexity of your functions above if graph has nodes and edges? C. Test your functions. Write code to create a random graph of 100 nodes, with 500 random edges with weight 1.0, 500 random edges with weight 2.0 and 500 random edges with weight 3.0. (For function in A(d) use a smaller graph if too slow.) Measure the time of each function in nanoseconds or microseconds. · Assume there can be at most 1 edge between 2 nodes. · Assume there is no self-loop (edge from one node to itself).
Answered Same DayDec 02, 2021

Answer To: UCR - CS 010C Assignment 4 Deliverables: Create a single PDF file that contains your answers to the...

Sandeep Kumar answered on Dec 09 2021
144 Votes
#include "graph.hpp"
#include
#include
#include
#include
#include
#inclu
de
#include "edge.hpp"
#include "node.hpp"
// Complete this
bool Graph::hasTripletClique() const {
if (nodes_.size() < 3) return false;
for(auto it1 : nodes_) {
Node* node1 = it1.second; //node1
for(auto it2 : node1->getNeighbors()) {
Node* node2 = it2; //edge exists between node1--node2
for(auto it3 : nodes_) {
if(it3.second != node1 && it3.second != node2) {
Node* node3 = it3.second; //node3 is unique

if(node3->getNeighbors().find(node1) != node3->getNeighbors().end() &&
node3->getNeighbors().find(node2) != node3->getNeighbors().end()
&& node3->getNeighbors().empty() == false) {

/*
std::cout << "Node 1--3:";
if(node3->getNeighbors().find(node1) == node3->getNeighbors().end()) {
std::cout << " false\n";
}
else {
std::cout << " true\n";
}
std::cout << "Node 2--3:";
if(node3->getNeighbors().find(node2) == node3->getNeighbors().end()) {
std::cout << " false\n";
}
else {
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here