# DFS on weighted graphs

I have the following weighted graph with connected nodes. I've made some connections red just to be easier on the eye.

I am applying DFS on this graph and I am not sure if this is correct because on theory DFS takes the first node and that implementation is easy when the graph isn't weighted so we apply alphabetically order. But on weighted graph it's more complicated.

My output solution : 1-3-6-2-5-8-9

Graph front (step by step):

(1)
(3 2)
(6 5 2)
(2 7 5 2)
(5 4 7 5 2)
(8 7 4 7 5 2)
(9 4 7 4 7 5 2)
(4 7 4 7 5 2)


My solution is based on the weights, the nodes are coming to the front on ascending order. They key moment on my solution was when it was on node 6 and moved to 2 because 2 wasn't visited. I need some guidance when it comes to weighted graphs and DFS.

• It is unclear what you want to achieve. DFS or BFS on weighted graphs is exactly the same as on unweighted graphs, since both algorithms don't use any edge weights. Can you tell us why you want to run these algorithms? – adrianN Sep 4 '17 at 13:55
• But what's your question? You've run DFS on your graph, but you don't say what you were trying to achieve by doing that. Nor do you say what was wrong with the result you got. – David Richerby Nov 3 '17 at 10:37