Posted: June 15th, 2022
Develop a program to read simple undirected connected graphs into an n x n 2D array.
Develop a program to read simple undirected connected graphs into an n x n 2D array.
CMPS 2433 – Discrete Structures and Analysis
Program 4
Due December 4, 2018
Problem: Homework help – Write a program to read simple undirected connected graphs into an n x n 2D array. Then
determine whether that graph has an Euler Circuit using the algorithm described below. If the graph has
an Euler circuit, find one and print out the nodes in the Euler Circuit. If the graph does not have one,
print NO EULER CIRCUIT EXISTS.
Method: First your program must determine if the connected graph input and stored in the 2D array has
an Euler Circuit. A graph that has vertices of all even degree contains an Euler Circuit. Second, if the
graph does have one, then your program must find an Euler Circuit in the graph using a modification of
Fleury’s algorithm.
Fleury’s algorithm, published 1883 constructs Euler subcircuits by first choosing an arbitrary vertex (say
0) of a graph, and forms a circuit by choosing edges successively. Once an edge is chosen, it is removed.
Edges are chosen successively so that each edge begins where the last edge ends, and so that this edge
is not a cut edge, unless there is no alternative. The algorithm terminates when the original vertex (0) is
reached. If there are no edges remaining in the graph, then the path has the constructed Euler circuit,
otherwise it has only found a subcircuit. Just stop there and print out a message that only a subcircuit
was found.
Important Notes:
You must use arrays or vectors in this program.
If you use arrays, you must dynamically allocate memory for each array and properly free up
that memory when you finish processing that particular graph (array).
You must write functions to
o Open the input and output files
o Read in the graph’s edges
o Determine if a graph has an Euler Circuit
o Find and print an Euler Circuit using Fleury’s algorithm
o Determine if a graph has edges
There will not be more than 20 vertices.
Vertices are labelled 0, 1, 2, …
Input File: connected2D.dat
Sample input file: 3 //number of test cases
6 //number of rows and columns in the 2D array
0 1 0 0 0 1 //values in the 2D array
1 0 1 0 0 0 //DRAW the GRAPH on the input file
0 1 0 1 1 1
0 0 1 0 1 0
0 0 1 1 0 1
1 0 1 0 0 0
4 //number of rows and columns in the 2D array
0 1 1 1 //values in the 2D array
1 0 1 1 //DRAW the GRAPH on the input file
1 1 0 1
1 1 1 0
7
0 1 0 1 0 0 0
1 0 0 1 0 0 0
0 0 0 1 1 0 0
1 1 1 0 1 1 1
0 0 1 1 0 0 0
0 0 0 1 0 0 1
0 0 0 1 0 1 0
Output File: lastname_prog4.txt
Sample output file: Joanna Wringer
Euler Circuit: There are 3 Graphs
GRAPH 1
0 1 2 3 4 2 5 0
EULER CIRCUIT CONSTRUCTED
GRAPH 2
NO EULER CIRCUIT EXISTS
GRAPH 3
0 1 3 0
A SUBCIRCUIT CONSTRUCTED
Order | Check Discount
Sample Homework Assignments & Research Topics
Tags:
best essay writing service tiktok,
best essay writing service uk,
best essay writing service uk trustpilot,
best research paper writing service,
Best Research Paper Writing Services in the U.S.