0% found this document useful (0 votes)
13 views10 pages

Dsa Project (Royce CR)

This document discusses the applications of shortest path algorithms in graph theory, focusing on Warshall’s, Floyd’s, Dijkstra’s, and Bellman-Ford algorithms. It provides an overview of each algorithm's methodology, strengths, limitations, and performance in various scenarios, emphasizing the importance of selecting the appropriate algorithm based on graph characteristics. The project includes implementation details, comparisons of methodologies, and references for further reading.

Uploaded by

roycecrraphael
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views10 pages

Dsa Project (Royce CR)

This document discusses the applications of shortest path algorithms in graph theory, focusing on Warshall’s, Floyd’s, Dijkstra’s, and Bellman-Ford algorithms. It provides an overview of each algorithm's methodology, strengths, limitations, and performance in various scenarios, emphasizing the importance of selecting the appropriate algorithm based on graph characteristics. The project includes implementation details, comparisons of methodologies, and references for further reading.

Uploaded by

roycecrraphael
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

EX.

NO: 10
DATE: 8/5/2025

PROJECT – APPLICATIONS OF GRAPH

Chapter 1: Abstract

Chapter 2: Introduction

Chapter 3: Methodologies

Chapter 4: Comparison of Methodologies

Chapter 5: Results and Discussion

Chapter 6: Conclusion

Chapter 7: References
Problems
Chapter 1: Abstract
Shortest path algorithms are foundational tools in computer science, especially
in the realm of data structures and algorithms. These algorithms help determine
the most efficient way to navigate between nodes in a network—be it a map, a
computer network, or a decision-making system. This abstract provides an
overview of four key algorithms—Warshall’s, Floyd’s, Dijkstra’s, and Bellman-
Ford—based on three distinct graph problems.

Warshall’s and Floyd’s Algorithms are both used for finding shortest paths
between all pairs of nodes in a directed graph. Warshall’s algorithm focuses on
reachability—essentially whether a path exists between two vertices—by
progressively updating the transitive closure of the graph. Floyd’s algorithm,
however, goes a step further by calculating the shortest path lengths between all
pairs, making it more suitable for weighted graphs like the one in the first
image, where each edge has a cost. Floyd’s algorithm systematically updates
path lengths using a dynamic programming approach and is capable of handling
graphs with positive weights efficiently.

Dijkstra’s Algorithm, which appears in the second part of the first problem, is
a greedy algorithm that finds the shortest path from a single source node to all
other nodes. It continuously selects the node with the smallest tentative distance
and updates its neighbours. It is best suited for graphs with non-negative edge
weights, as seen in the first graph image. This algorithm is intuitive and
efficient, making it popular for real-time applications like GPS routing and
network flow analysis.

Bellman-Ford Algorithm, shown in the final problem with the third graph,
offers an alternative that can handle negative edge weights—something
Dijkstra’s cannot. While slower than Dijkstra’s, Bellman-Ford is robust; it
iteratively relaxes all edges and can detect negative-weight cycles. The graph
used here includes both negative and positive weights, making it ideal for
showcasing Bellman-Ford’s capability to solve complex pathfinding problems
that involve potential cost reductions (e.g., discounts or penalties in economic
models).

Together, these algorithms illustrate a spectrum of approaches to solving


shortest path problems, each optimized for different constraints and graph
characteristics. The choice between them depends on whether we need all-pairs
paths or single-source paths, and whether the graph contains negative weights.
Mastering these algorithms equips learners with the ability to model and solve a
wide range of practical and theoretical problems in computing and operations
research.
Chapter 2: Introduction

Graphs are fundamental data structures in computer science that model


relationships between pairs of objects. They are widely used in various
applications such as social networks, transportation systems, network routing,
and resource optimization. One of the most important problems in graph theory
is finding the shortest path between nodes, which refers to the path with the
minimum total weight (or cost) among all possible routes. To solve this problem
efficiently, several algorithms have been developed, each with its own
approach, strengths, and limitations.

This project focuses on implementing and understanding four key algorithms


used to determine shortest paths in directed graphs: Warshall’s algorithm,
Floyd’s algorithm, Dijkstra’s algorithm, and the Bellman-Ford algorithm.
Warshall’s and Floyd’s algorithms are both used for computing shortest paths
between all pairs of nodes, with Floyd’s specifically handling weighted paths.
Dijkstra’s algorithm is a greedy technique designed for finding the shortest
paths from a single source to all other vertices in graphs with non-negative
weights. On the other hand, Bellman-Ford is a dynamic programming-based
algorithm that not only handles negative weights but can also detect negative
weight cycles.

Through the implementation of these algorithms in C and their application to


different graph structures, this project aims to demonstrate their working
principles, compare their performance, and highlight the scenarios where each
algorithm is best suited.
Chapter 3: Methodologies
1. Problem Representation:
Each graph provided in the problems is modeled using an adjacency matrix or
adjacency list, depending on the requirements of the algorithm. Adjacency
matrices are used for Warshall’s and Floyd’s algorithms as they naturally
support matrix-based operations. For Dijkstra’s and Bellman-Ford, adjacency
lists are also considered for their memory efficiency, especially in sparse
graphs.

2. Algorithm Design and Implementation:

 Floyd-Warshall Algorithm is a dynamic programming-based approach


used to solve the all-pairs shortest path problem in a directed graph. It
systematically updates the shortest paths between every pair of vertices
by considering each vertex as an intermediate point. Using a simple
triple-nested loop structure, the algorithm compares existing path lengths
with new paths that pass through an intermediate vertex and updates the
distance matrix accordingly.
 Dijkstra’s Algorithm follows the greedy method, using an array to store
distances and a visited set to track processed nodes. It selects the vertex
with the minimum tentative distance and updates its neighbours
accordingly.
 Bellman-Ford Algorithm is implemented using edge relaxation
performed repeatedly (V-1) times, where V is the number of vertices. An
additional iteration checks for the presence of negative-weight cycles.

3. Testing and Validation:


Each implementation is tested using the example graphs provided in the
assignment. Outputs such as shortest paths, distance matrices, and cycle
detection are verified manually and by comparing with known correct results.

4. Performance Observation:
Execution steps and complexity are observed for each algorithm. Warshall’s
and Floyd’s have time complexity of O(n³), making them suitable for dense
graphs. Dijkstra’s runs in O(n²) with an adjacency matrix (or O((V+E) log V)
with a min-priority queue), and Bellman-Ford has O(VE) complexity but
handles negative weights, making it uniquely versatile.
Chapter 4: Comparison of Methodologies
1. Approach and Objective:

 Floyd Warshall’s Algorithm, in contrast, is designed to find the shortest


paths between all pairs of nodes in a weighted graph, including multiple
intermediate vertices.
 Dijkstra’s Algorithm is a greedy algorithm that finds the shortest path
from a single source to all other nodes, only in graphs with non-negative
edge weights.
 Bellman-Ford Algorithm uses relaxation techniques and dynamic
programming to find single-source shortest paths, and is capable of
handling graphs with negative weights.

2. Time and Space Complexity:

 FloydWarshall’s algorithm both use a dynamic programming approach


with three nested loops, resulting in a time complexity of O(n³) and space
complexity of O(n²).
 Dijkstra’s algorithm, implemented with an adjacency matrix and
without a priority queue, runs in O(n²), but can be improved to O((V + E)
log V) with a min-heap or priority queue. It is efficient for sparse graphs
with non-negative weights.
 Bellman-Ford, with a time complexity of O(VE), is slower than
Dijkstra’s but uniquely supports negative weights and detects negative
cycles, which the others cannot.

3. Data Structures Used:

 FloydWarshall’s algorithm are best suited to adjacency matrices, which


simplify matrix operations but consume more memory.
 Dijkstra’s and Bellman-Ford work well with adjacency lists, especially
in sparse graphs where memory efficiency and traversal speed are critical.

4. Limitations:

 Warshall’s does not consider path weights, making it unsuitable for


weighted graphs.
 Floyd’s cannot handle graphs with negative cycles, though it handles
negative weights without cycles.
 Dijkstra’s fails in graphs with negative edge weights, possibly producing
incorrect results.
 Bellman-Ford is slower but more robust, capable of identifying and
responding to negative cycles.
Chapter 5: Results and Discussion

1. Floyd-Warshall Algorithm:
Floyd-Warshall performed well on dense graphs, accurately calculating
the shortest paths between all pairs of vertices. With a time complexity of
O(n³), it is suitable for smaller graphs but becomes inefficient for larger
ones. However, it cannot detect negative weight cycles, which limits its
applicability in certain scenarios.
2. Dijkstra’s Algorithm:
Dijkstra’s algorithm was efficient on graphs with non-negative edge
weights, with performance improving on sparse graphs when using an
adjacency list and priority queue (O((V + E) log V)). However, it failed
to handle negative edge weights, producing incorrect results in such
cases.
3. Bellman-Ford Algorithm:
Bellman-Ford excelled in handling graphs with negative edge weights
and detecting negative weight cycles. While slower than Dijkstra’s
(O(VE)), it provided essential functionality for graphs involving negative
weights. It was able to compute correct shortest paths and detect negative
cycles, which neither Floyd-Warshall nor Dijkstra’s could do.

Comparative Analysis:

 Efficiency: Floyd-Warshall's O(n³) time complexity made it inefficient


for large graphs. Dijkstra’s was faster for graphs with non-negative
weights, especially when optimized with a priority queue. Bellman-Ford
was slower but handled negative weights and cycle detection.
 Applicability: Floyd-Warshall is best for all-pairs shortest path problems
in dense graphs. Dijkstra’s is ideal for single-source shortest paths in
sparse, non-negative weight graphs. Bellman-Ford is best suited for
graphs with negative weights or when cycle detection is needed.
Chapter 6: Conclusion

In this project, we explored four fundamental shortest path


algorithms—Floyd-Warshall, Dijkstra’s, and Bellman-Ford—each
with distinct strengths and limitations. Through their implementation
and analysis, we observed that the choice of algorithm heavily
depends on the specific characteristics of the graph, such as the
presence of negative edge weights, the need for all-pairs shortest path
results, and performance requirements.

Floyd-Warshall is optimal for dense graphs where all-pairs shortest


paths are required, but it is less efficient for large-scale graphs.
Dijkstra’s algorithm, on the other hand, is the go-to solution for
graphs with non-negative weights, offering fast performance,
particularly in sparse graphs. Bellman-Ford stands out in scenarios
where negative edge weights exist, providing both shortest path
calculations and the ability to detect negative cycles, although at the
cost of slower performance.

Ultimately, understanding the nature of the graph and the problem at


hand is crucial when selecting the appropriate algorithm. By
mastering these algorithms, one can tackle a wide range of graph-
based problems efficiently, applying the right approach to different
real-world scenarios.
Chapter 7: References

 GeeksforGeeks. (n.d.). Graph Algorithms. Retrieved from


https://www.geeksforgeeks.org/graph-data-structure-and-algorithms/
– Useful for practical implementation examples and performance comparisons.

 Programiz. (n.d.). Graph Algorithms in C. Retrieved from


https://www.programiz.com/dsa/graph
– Offers beginner-friendly guides to implement graph algorithms in C.

 Skiena, S. S. (2008). The Algorithm Design Manual (2nd ed.). Springer.


– Helps in understanding algorithmic trade-offs and choosing appropriate
methods.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy