Question: An undirected weighted graph with N nodes and M edges is given as an adjacency list. You are expected to design an algorithm that finds

An undirected weighted graph with N nodes and M edges is given as an adjacency list. You are expected to design an algorithm that finds the polygons (triangles, quadrilaterals, pentagons, hexagons, etc.) formed by the links in this graph and prints the nodes and the perimeter lengths of each of the shapes. The algorithm you design should print the total number of shapes, the number of individual shapes, their nodes, and their perimeter lengths.
The steps to be implemented in your program are as follows:
1. Read the number of nodes and edges (N and M) from outside.
2. Read the edge information as an adjacency list.
3. With the DFS approach, the shapes in your graph should be detected separately.
4. The nodes contained in the detected shape and the total perimeter length of the shape should be stored.
5. Finally, the total number of shapes, the type of polygons (triangle, quadrilateral, ...etc.), their number, the nodes they contain and their perimeter length should be printed on the screen.
Note: The same shape should not be added to the list for different starting points. Use the edge weights to calculate the perimeter lengths. This code is required in C language.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!