Final 3333
Final 3333
Academic Year:2024
Course Code: B22EF0305 Algorithms Lab Project Report
Semester & Batch: 4th A-2
Project Details:
Student Details:
D.DHINESH KUMAAR REDDY
Name: Sign:
9392026464
Mobile No:
[email protected]
Email-ID:
R22EF047
SRN:
SEE Examiners
Name of Sign:
Examiner 1: Date:
Name of Sign:
Examiner 2: Date:
Contents
1. Abstract 3
2. Introduction 3
3. Problem Statement. 4
4. Project overview. 4
4.1.Objectives
4.2.Goals
5. Implementation. 4
5.2.Modules identified.
7. Conclusions 13
8. References 13-14
2. Introduction:
Graph algorithms form the backbone of many computational processes and have broad applications
across various fields such as network routing, geographical mapping, game development, and
artificial intelligence. These algorithms help in solving complex problems by providing efficient
methods to traverse, search, and find optimal paths in graphs and grids. This project aims to
develop a robust C program that implements three fundamental graph algorithms: Dijkstra's
Algorithm, Depth First Search (DFS), and the A* Algorithm.
Dijkstra's Algorithm is a widely-used algorithm designed to find the shortest path between nodes in
a weighted graph, where all edge weights are non-negative. This algorithm is particularly useful in
scenarios such as network routing, where it ensures that data packets travel the shortest possible
route between routers. Depth First Search (DFS) is another essential algorithm, used primarily for
graph traversal. It explores as far along a branch as possible before backtracking, making it useful
for applications such as finding connected components, performing topological sorting, and solving
puzzles where all potential solutions must be explored.
The A* Algorithm is an advanced pathfinding and graph traversal algorithm that combines the
benefits of Dijkstra's Algorithm with heuristic methods to enhance efficiency. By using heuristics,
A* can often find the shortest path more quickly than Dijkstra’s Algorithm alone, especially in
large grids or graphs. This algorithm is extensively used in artificial intelligence for games, where
characters need to navigate through complex environments, and in robotics, where efficient
pathfinding is crucial for navigation and obstacle avoidance.
The primary objective of this project is to provide a comprehensive and practical implementation
of these algorithms. Users will be able to input custom graphs and grids, execute the algorithms,
and observe the results along with the execution time. This hands-on approach will not only
demonstrate the practical utility of these algorithms but also provide insights into their performance
and efficiency. Through this project, users can better understand the intricacies of graph algorithms
and their real-world applications, thereby enhancing their problem-solving and computational
skills.
5. Project Implementation.
5.1. Problem analysis and description.
This project addresses the problem of graph traversal and pathfinding in different scenarios:
• Shortest Path in Weighted Graph: Using Dijkstra's algorithm to find the shortest path
from a source vertex to all other vertices.
• Graph Traversal: Using DFS to explore all vertices of a graph from a given starting point.
• Pathfinding in Grid: Using A* algorithm to find the shortest path in a grid, considering
obstacles.
• These problems are common in network routing, game development, and various
optimization tasks
5.2. Modules identified:
Input Module: Handles user input for graph and grid configurations.
Dijkstra Module: Implements Dijkstra's algorithm.
School of Computer Science and Engineering Page 4
DFS Module: Implements the Depth First Search algorithm.
A Module:* Implements the A* algorithm.
Output Module: Displays the results and execution time.
5.3. Code with comments.
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits.h>
typedef struct {
int x, y;
} Node;
typedef struct {
Node parent;
double f, g, h;
} NodeData;
int graph[MAX_VERTICES][MAX_VERTICES];
bool visited[MAX_VERTICES];
int numVertices;
dist[src] = 0;
printSolution(dist);
printf(“Time Complexity:O(v2)”);
printf("Time taken: %f seconds\n", ((double)(end - start)) / CLOCKS_PER_SEC);
}
void astar(int grid[][MAX_VERTICES], Node start, Node goal, int rows, int cols) {
NodeData nodes[rows][cols];
bool closedList[rows][cols];
while (true) {
double minF = INFINITY;
Node current = {-1, -1};
if (minF == INFINITY) {
printf("No path found!\n");
return;
}
printf("Path:\n");
for (int i = pathLength - 1; i >= 0; i--) {
printf("(%d,%d)\n", path[i].x, path[i].y);
return;
}
closedList[current.x][current.y] = true;
int main() {
int rows, cols;
School of Computer Science and Engineering Page 9
printf("Enter the number of rows and columns for the adjacency matrix : ");
scanf("%d %d", &rows, &cols);
numVertices = rows;
printf("Enter the adjacency matrix for the graph (%d x %d):\n", rows, cols);
for (int i = 0; i < numVertices; i++) {
for (int j = 0; j < numVertices; j++) {
scanf("%d", &graph[i][j]);
}
}
int srcVertex;
printf("Enter the source vertex for Dijkstra's algorithm: ");
scanf("%d", &srcVertex);
dijkstra(srcVertex);
start_time = clock();
end_time = clock();
printf("\nEnter the number of rows and columns for the grid :\n ");
scanf("%d %d", &rows, &cols);
int grid[MAX_VERTICES][MAX_VERTICES];
printf("\nEnter the grid (0 for empty, 1 for obstacles):\n");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
scanf("%d", &grid[i][j]);
}
}
Node startNode, goalNode;
printf("Enter the start node coordinates (x y): ");
scanf("%d %d", &startNode.x, &startNode.y);
printf("Enter the goal node coordinates (x y): ");
scanf("%d %d", &goalNode.x, &goalNode.y);
astar(grid, startNode, goalNode, rows, cols);
return 0;
}
8. References:
G. Eason, B. Noble, and I. N. Sneddon, “On certain integrals of Lipschitz-Hankel type involving
products of Bessel functions,” Phil. Trans. Roy. Soc. London, vol. A247, pp. 529–551, April
1955.
J. Clerk Maxwell, A Treatise on Electricity and Magnetism, 3rd ed., vol. 2. Oxford: Clarendon,
1892, pp.68–73.
I. S. Jacobs and C. P. Bean, “Fine particles, thin films and exchange anisotropy,” in Magnetism,
vol. III, G. T. Rado and H. Suhl, Eds. New York: Academic, 1963, pp. 271–350.
K. Elissa, “Title of paper if known,” unpublished.
R. Nicole, “Title of paper with only first word capitalized,” J. Name Stand. Abbrev., in press.
Y. Yorozu, M. Hirano, K. Oka, and Y. Tagawa, “Electron spectroscopy studies on magneto-optical
media and plastic substrate interface,” IEEE Transl. J. Magn. Japan, vol. 2, pp. 740–741, August
1987 [Digests 9th Annual Conf. Magnetics Japan, p. 301, 1982].
M. Young, The Technical Writer’s Handbook. Mill Valley, CA: University Science, 1989.
NPTEL Course on “Design and Analysis of Algorithms”, Prof. Abhiram G Ranade, Prof. Ajit A
Diwan and Prof. Sundar Vishwanathan, https://nptel.ac.in/courses/106101060
“Introduction to Design and Analysis of Algorithms” by Anany Levitin,
2nd edition
http://160592857366.free.fr/joe/ebooks/ShareData/Anany%20Levitin%
20English
School of Computer Science and Engineering Page 13
https://www.researchgate.net/publication/276847633_A_Review_Report_on_Divide_and_Co
nquer_Sortin g_ Algorithm
https://www.ijsrp.org/research-paper-0813/ijsrp-p2014.pdf
https://iopscience.iop.org/article/10.1088/1742-6596/1566/1/012038/pdf