Question

In: Computer Science

Using C++: Create a function to search an undirected weighted graph and find the highest weighted...

Using C++:

Create a function to search an undirected weighted graph and find the highest weighted edge between two specific values.

This should include a class declaration and the definition for all required members that are needed to support the search. NO NEED to code those members. You can assume any other data structures such as stack, heap, or linked list is defined (so you can use their standard functions without declaring or defining them).

Solutions

Expert Solution

#include <bits/stdc++.h>
#include <limits.h>
using namespace std;
#define n 6
class graph
{
private:
int g[n][n];
public:
int search()
{
int max=INT_MIN;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(g[i][j]>max)max=g[i][j];
}
}
return max;
}
void initialize()
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
g[i][j]=0;
}
}
return ;
}
void addEdge(int x, int y,int w)
{
g[x][y]=w;
g[y][x]=w;
}
};

int main()
{
graph gra;
gra.initialize();
gra.addEdge(0,2,4);
gra.addEdge(3,2,2);
gra.addEdge(5,4,6);
gra.addEdge(1,4,9);
gra.addEdge(2,3,6);
gra.addEdge(5,3,7);
cout<<"The maximum weight of the edge is "<<gra.search();
return 0;
}

PLEASE DO UPVOTE IF THE ANSWER IS HELPFUL , AS IT GIVES CONFIDENCE TO HELP MORE STUDENTS


Related Solutions

give an example of a simple, undirected, weighted graph such that breadth-firstsearch outputs a search-tree that...
give an example of a simple, undirected, weighted graph such that breadth-firstsearch outputs a search-tree that is not a single source shortest path tree. Youranswer must (a) Specify the graphG= (V, E)by specifyingVandE. (b) Specify the weight functionw. (c) Specify an ordering of the vertices and the search-tree output by breadth-first search assuming the specified graph and ordering. (d) Specify a valid single-source shortest path treeT= (V, ET)by specifyingETand its root, the first vertex in your specified ordering. (e) Include...
Which graph search method will be better for finding a cycle in an undirected graph: a...
Which graph search method will be better for finding a cycle in an undirected graph: a BTS or a DFS? In detail, describe (create) an algorithm for finding a cycle in any undirected graph, explaining why the algorithm assures to find a cycle if there exists one.
Suppose you are given an undirected, connected, weighted graph G. You want to find the heaviest...
Suppose you are given an undirected, connected, weighted graph G. You want to find the heaviest weight set of edges that you can remove from G so that G is still connected. Propose an optimal greedy algorithm for this problem and prove that it is optimal. (Hint: use matroid theory!).
Write a python code to generate a random undirected weighted graph and calculate the shortest distance...
Write a python code to generate a random undirected weighted graph and calculate the shortest distance from node i to node j (shortest path algorithm) where i is not equal to j. Store the results in text file. Thank you!
5. Suppose we are given both an undirected graph G with weighted edges and a minimum...
5. Suppose we are given both an undirected graph G with weighted edges and a minimum spanning tree T of G . (a) Describe an algorithm to update the minimum spanning tree when the weight of a single edge e is decreased. (b) Describe an algorithm to update the minimum spanning tree when the weight of a single edge e is increased. In both cases, the input to your algorithm is the edge e and its new weight; your algorithms...
Let G(V, E,w) be a weighted undirected graph, where V is the set of vertices, E...
Let G(V, E,w) be a weighted undirected graph, where V is the set of vertices, E is the set of edges, and w : E → R + is the weight of the edges (R + is the set of real positive numbers). Suppose T(G) is the set of all minimum spanning trees of G and is non-empty. If we know that the weight function w is a injection, i.e., no two edges in G have the same weight, then:...
Please write program in c++ with using pointer. create a function that can find the number...
Please write program in c++ with using pointer. create a function that can find the number of even numbers that are between the maximum and minimum elements of an given array.The program have to use pointer. example 8 -1 2 2 1 9 2 4 0 output: 2
Write a program of Binary Search in C++ by using function and arrays with the explanation.
Write a program of Binary Search in C++ by using function and arrays with the explanation.
(C++) I need to Create a Copy function of a Binary Search Tree recursively providing these...
(C++) I need to Create a Copy function of a Binary Search Tree recursively providing these structure emplate <typename T> class Tree {    struct TreeNode    {        T mData;        TreeNode* mLeft = nullptr;        TreeNode* mRight = nullptr;        TreeNode* mParent = nullptr;        bool mIsDead = false;        TreeNode()        {        }        TreeNode(T tData) : TreeNode()        {            mData = tData;...
Implement a function to find a node in a binary search tree. Using the following class...
Implement a function to find a node in a binary search tree. Using the following class and function definition. If a node with a matching value is found, return a pointer to it. If no match is found, return nullptr. #include <iostream> class BTNode { public: int item; BTNode *left; BTNode *right; BTNode(int i, BTNode *l=nullptr, BTNode *r=nullptr):item(i),left(l),right(r){} }; BTNode *root = nullptr; BTNode *find(int item) { //implement code here return nullptr; } int main() {    root = new...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT