Computer scienceAlgorithms and Data StructuresAlgorithmsGraph algorithmsShortest path algorithms

Comparing the shortest path algorithms

Compare the outputs

Report a typo

Consider the following graph:

Finding the shortest path in the graph

Apply Dijkstra's and the Bellman-Ford algorithms to the given graph, with node 00 as the source node. In two arrays, write the shortest paths that each of the algorithms outputs: on the first line — Dijkstra's output, and on the second line — the Bellman-Ford output.

The shortest distances in the array should follow this order: d1,d2,d3,d4.d_1, d_2, d_3, d_4. If an algorithm finds the presence of a negative cycle, write NC instead.

Answer format example 1:

3 7 2 4
3 7 1 4

Example 2:

NC
NC
Enter a short text
___

Create a free account to access the full topic