C PROGRAMMING Implement dijkstras alorithm  Check that the Graph graph, and starting node, id, are valid • Create the set S containing all the networks (vertices) except the source node (you might want to use an array for this. • Create an array to represent the table D and initialise it with the weights of the edges from the source node, or infinity if no edge exists. You should use the constant DBL_MAX to represent infinity. • Create an array to represent the table R and initialise it with the next hops if an edge exists from the source, or 0 otherwise. • Then repeatedly follow the remaining rules of Dijkstra’s algorithm, updating the values in D and R until S is empty. • Each of the values required to complete the above can be found by calling the various functions (get_vertices(), get_edge(), edge_destination(), edge_weight(), etc.) in the supplied graph library. • Once Dijkstra’s algorithm has run, you will need to create the routing table to be returned by allocating enough memory for the required number of Path structures and filling each entry of the array. • Finally, you should free() any unused memory you have allocated, set *pnEntries to the correct value, and return the pointer to the routing table you’ve just filled in (obviously, you shouldn’t free that!)   using the below as a starting point: /*  *  dijkstra.c  *  ProgrammingPortfolio  *  */ #include #include #include #include #include "graph.h" #include "dijkstra.h" /* find shortest paths between source node id and all other nodes in graph. */ /* upon success, returns an array containing a table of shortest paths.  */ /* return NULL if *graph is uninitialised or an error occurs. */ /* each entry of the table array should be a Path */ /* structure containing the path information for the shortest path between */ /* the source node and every node in the graph. If no path exists to a */ /* particular desination node, then next should be set to -1 and weight */ /* to DBL_MAX in the Path structure for this node */ Path *dijkstra(Graph *graph, int id, int *pnEntries) {     Path *table = NULL;          /* Insert your implementation of Dijkstra's algorithm here */     return table; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

C PROGRAMMING

Implement dijkstras alorithm 

Check that the Graph graph, and starting node, id, are valid
• Create the set S containing all the networks (vertices) except the source node (you might want
to use an array for this.
• Create an array to represent the table D and initialise it with the weights of the edges from the
source node, or infinity if no edge exists. You should use the constant DBL_MAX to represent
infinity.
• Create an array to represent the table R and initialise it with the next hops if an edge exists
from the source, or 0 otherwise.
• Then repeatedly follow the remaining rules of Dijkstra’s algorithm, updating the values in D and
R until S is empty.
• Each of the values required to complete the above can be found by calling the various
functions (get_vertices(), get_edge(), edge_destination(), edge_weight(), etc.)
in the supplied graph library.
• Once Dijkstra’s algorithm has run, you will need to create the routing table to be returned by
allocating enough memory for the required number of Path structures and filling each entry of
the array.
• Finally, you should free() any unused memory you have allocated, set *pnEntries to the
correct value, and return the pointer to the routing table you’ve just filled in (obviously, you
shouldn’t free that!)

 

using the below as a starting point:

/*
 *  dijkstra.c
 *  ProgrammingPortfolio
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include "graph.h"
#include "dijkstra.h"


/* find shortest paths between source node id and all other nodes in graph. */
/* upon success, returns an array containing a table of shortest paths.  */
/* return NULL if *graph is uninitialised or an error occurs. */
/* each entry of the table array should be a Path */
/* structure containing the path information for the shortest path between */
/* the source node and every node in the graph. If no path exists to a */
/* particular desination node, then next should be set to -1 and weight */
/* to DBL_MAX in the Path structure for this node */
Path *dijkstra(Graph *graph, int id, int *pnEntries)
{
    Path *table = NULL;
    
    /* Insert your implementation of Dijkstra's algorithm here */

    return table;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Binary Tree
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education