C Mini Projects for Students Dijkstra’s Algorithm

C Mini Projects for Students Dijkstra’s Algorithm:

Are you a Bsc., or Diploma student?…  Searching help to do your Mini Projects in C?…  Try the following C Mini Project based on Dijkstra’s Algorithm.  A simple shortest path algorithm application.

Scope of the project:

To find the shortest path (with less distance) between two nodes of a weighted and directed graph.

Introduction:
Dijkstra’s Algorithm:

  • Dijkstra’s Algorithm is one of the shortest-path algorithms.
  • This Dijkstra’s Algorithm is evolved to overcome the problems of single-source shortest-path problem.
  • Dijkstra’s Algorithm was found by Edsger Wybe Dijkstra in the year 1956.

Uses of Dijkstra’s Algorithm:

  • To find the shortest path between different nodes of a graph.
  • It is used to solve  routing problems sometimes.
  • It is also used by other graph algorithms as subroutines.

What is Dijkstra’s Algorithm?

Dijkstra’s Algorithm is the best algorithm that finds solution for the single source shortest path algorithm only when a weighted, directed graph contains non-weighted edge weights.

Now lets see how we are going to implement the C coding for Dijkstra’s Algorithm  in finding the shortest path between the nodes of a graph.

C Mini Project Dijkstra’s Algorithm:

Assumptions:

  • Consider a weighted and directed graph .
  • Lets consider input of our C Program be the source, target and weight of the path between the two nodes of the graph.
  • Fix any node of the graph as ‘initial node’, the starting point.
  • Assume ‘Y’ as the distance between the initial node and another node, ‘y’  of the graph.
  • Assign  initial distance values to each node of the graph. This value can be improved step by step later through Dijkstra’s algorithm.

Algorithm:

  1. Assign distance value of the initial node as zero and infinity for other nodes.
  2. All the nodes are set as unvisited and the initial node is set as current node.
  3. Create a set of unvisited nodes called as “unvisited set”.
  4. For the current node, calculate the tentative value for the nearby unvisited nodes.
    For each node, compare the assigned current value and calculated tentative value. Then fix the smaller value.
    Example: If the current node ‘X’ has distance as 3 with the node ‘Y’. Now if the edge has value ‘1’ between X and Y. Now calculate the tentative distance as 3+1=4. If the initially assigned value for ‘Y’ is less than 4, then keep that value as it is. Otherwise, set the tentative value as 4.
  5. After calculating tentative value to the neighboring nodes of the current value, remove it from unvisited set. Assign them as visited nodes.
  6. The algorithm stopped under two cases:
    Case 1: While finding the route between two nodes, among which if one is the destination node and that node is marked as visited, the algorithm stops.
    Case 2: If the smallest tentative value of the nodes is infinity in a complete traversal, algorithm stops. In this case, the result is there is no connection between the unvisited nodes and the initial current node.
  7. Set the unvisited node with smallest tentative value as current node. Repeat the algorithm from step: 4 . Continue again.

C Program For Dijkstra’s algorithm:

Hope all you have well understood the Dijkstra’s  algorithm along its  implementation in the above C Mini Project Dijkstra’s Algorithm.

Apply the above code for your own graph and test the code. All the best…

You May Also Like to Read:

C Program For Prims Algorithm Using Greedy Method
C Mini Project for Diploma students: Binary Tree Implementation
Frequently Asked C Interview Questions for Freshers: Set-1
C Functions Interview Questions for Freshers

Thanks for reading…..
Please leave your comments below….

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *