How to make graph | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to make graph

i wanna know to to make weighted graph and how to search the shortest path

4th Nov 2016, 2:55 AM
Alexander Nicholas S.
Alexander Nicholas S. - avatar
4 Answers
+ 1
to make weighted graph you can use 2D array..! ex. int G[5][5] suppose you have node 1 and 2 with weight 30 the you can enter weight 30 into G[1][2] and G[2][1](if undirected). like wise u have to enter all the weights and remaining elements should be very large like 9999. for finding shortest path... We have some algorithms Dijkstra algo. BellMan ford algo. Floydwarshall algo. you can implement one of them to find shortest path.(I recommend Dijkstra).
4th Nov 2016, 9:02 AM
Jaydeep Galani
Jaydeep Galani - avatar
+ 1
okk, thanks
4th Nov 2016, 9:16 AM
Alexander Nicholas S.
Alexander Nicholas S. - avatar
0
how ti make Dijkstra's algo?
4th Nov 2016, 9:05 AM
Alexander Nicholas S.
Alexander Nicholas S. - avatar
0
you can get Dijkstra algo. online and implemt it as per your requirment in c++.
4th Nov 2016, 9:07 AM
Jaydeep Galani
Jaydeep Galani - avatar