Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

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
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education