Wednesday, July 3, 2024
HomeData ModellingData Structure & AlgorithmAlgorithms | Graph Shortest Paths | Question 3

Algorithms | Graph Shortest Paths | Question 3

Dijkstra’s single source shortest path algorithm when run from vertex a in the below graph, computes the correct shortest path distance to

gate_2008_21
(A) only vertex a
(B) only vertices a, e, f, g, h
(C) only vertices a, b, c, d
(D) all the vertices

Answer: (D)
Explanation: Dijkstra’s single source shortest path is not guaranteed to work for graphs with negative weight edges, but it works for the given graph.
Let us see…

Let us run the 1st pass
b 1
b is minimum, so shortest distance to b is 1.

After 1st pass, distances are
c 3, e -2.
e is minimum, so shortest distance to e is -2

After 2nd pass, distances are
c 3, f 0.
f is minimum, so shortest distance to f is 0

After 3rd pass, distances are
c 3, g 3.
Both are same, let us take g. so shortest distance to g is 3.

After 4th pass, distances are
c 3, h 5
c is minimum, so shortest distance to c is 3

After 5th pass, distances are
h -2
h is minimum, so shortest distance to h is -2
Quiz of this Question

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Shaida Kate Naidoo
am passionate about learning the latest technologies available to developers in either a Front End or Back End capacity. I enjoy creating applications that are well designed and responsive, in addition to being user friendly. I thrive in fast paced environments. With a diverse educational and work experience background, I excel at collaborating with teams both local and international. A versatile developer with interests in Software Development and Software Engineering. I consider myself to be adaptable and a self motivated learner. I am interested in new programming technologies, and continuous self improvement.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments