Add comments to the code and display output Int main(void) //Input array containing edges of the graph //(X,Y,W)tuple represents an edge from 'x' to y' having weight w' struct Edge edges I= {0,1,4.).(1,2,4).(2,0,4),(2,1,4) int n=size of (edges)/size of (edges|0]); struct Graph *graph=createGraph(edges,n); return 0; static int minsum=100000; static void getMinPathSum(Dictionarygraph,bool[visited,ArrayLi necessary,int source,int dest,int currsum) if(src==dest) bool flag=true; for each(int i in necessary) if(!visitedi]) flag=false; break: if (flag ) minsum=Math. Min(minsum,currsum); return; elsel visited[src]=true; for(auto node:graph[src]) if (Ivisited[node.first]) visited [node.first])=true; getMinPathSum(graph, visited, necessary,node.first,dest,currsum+node.second); visited [node.first]=false;

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Add comments to the code and display output
Int main(void)
//Input array containing edges of the graph
//(X,Y,W)tuple represents an edge from 'x' to y' having weight w'
struct Edge edges I=

{0,1,4.).(1,2,4).(2,0,4),(2,1,4)
int n=size of (edges)/size of (edges|0]);
struct Graph *graph=createGraph(edges,n);
return 0;

static int minsum=100000;
static void
getMinPathSum(Dictionary<int,ArrayList>graph,bool[visited,ArrayLi
necessary,int source,int dest,int currsum)
if(src==dest)

bool flag=true;
for each(int i in necessary)
if(!visitedi])
flag=false;
break:

if (flag )
minsum=Math. Min(minsum,currsum);
return;
elsel
visited[src]=true;
for(auto node:graph[src])

if (Ivisited[node.first])
visited [node.first])=true;
getMinPathSum(graph, visited,
necessary,node.first,dest,currsum+node.second);
visited [node.first]=false;

First we have to create a graph with all nodes and all edges ad
weights are same using the following code:
Int main(void)
{
//Input array containing edges of the graph
//(X,Y,W)tuple represents an edge from 'x' to 'y' having weight 'w'
struct Edge edges ]=
{
{0,1,4,),(1,2,4},(2,0,4),(2,1,4)
};
int n=size of (edges)/size of (edges[0]);
struct Graph *graph3createGraph(edges,n);
return 0;
static int minsum3D100000;
static void
getMinPathSum(Dictionary<int,ArrayList>graph,bool]visited,ArrayLi
necessary,int source,int dest,int currsum)
{
if(src==dest)
{
bool flag=true%;
for each(int i in necessary)
{
if(!visited[i])
{
flag=false;
break;
}
if(flag)
minsum=Math.Min(minsum,currsum);
return;
else{
visited[src)=true;
for(auto node:graph[srcl)
{
if(!visited[node.first)
{
visited [node.first])=true;
getMinPathSum(graph, visited,
necessary,node.first,dest,currsum+node.second);
visited [node.first]=false;
}
Transcribed Image Text:First we have to create a graph with all nodes and all edges ad weights are same using the following code: Int main(void) { //Input array containing edges of the graph //(X,Y,W)tuple represents an edge from 'x' to 'y' having weight 'w' struct Edge edges ]= { {0,1,4,),(1,2,4},(2,0,4),(2,1,4) }; int n=size of (edges)/size of (edges[0]); struct Graph *graph3createGraph(edges,n); return 0; static int minsum3D100000; static void getMinPathSum(Dictionary<int,ArrayList>graph,bool]visited,ArrayLi necessary,int source,int dest,int currsum) { if(src==dest) { bool flag=true%; for each(int i in necessary) { if(!visited[i]) { flag=false; break; } if(flag) minsum=Math.Min(minsum,currsum); return; else{ visited[src)=true; for(auto node:graph[srcl) { if(!visited[node.first) { visited [node.first])=true; getMinPathSum(graph, visited, necessary,node.first,dest,currsum+node.second); visited [node.first]=false; }
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education