graphs dijkstra' algorithm shares some commonality with depth first search the algorithm proceeds as depth first search proceedsbut starts with single source eventually visiting every node within the graph there are two sets that dijkstra' algorithm maintains the first is an unvisited set this is set of vertices that yet need to be considered while looking for minimum cost paths the unvisited set serves the same purpose as the stack when performing depth first search on graph the visited set is the other set used by the algorithm the visited set contains all vertices which already have their minimum cost and path computed the visited set serves the same purpose as the visited set in depth first search of graph to keep track of the minimum cost path from the source to vertexvit is only necessary to keep track of the previous vertex on the path to for each vertexvwe keep track of the previous vertex on its path from the source initially the source vertexwith its cost of is added to the unvisited set then the algorithm proceeds as follows as long as there is at least one vertex in the unvisited set remove the vertex we'll call current from the unvisited set with the least cost all other paths to this vertex must have greater cost because otherwise they would have been in the unvisited set with smaller cost add current to the visited set for every vertexadjacentthat is adjacent to currentcheck to see if adjacent is in the visited set or not if adjacent is in the visited setthen we know the minimum cost of reaching this vertex from the source so don' do anything if adjacent is not in the visited setcompute new cost for arriving at adjacent by traversing the edgeefrom current to adjacent new cost can be found by adding the cost of getting to current and ' weight if this new cost is better than the current cost of getting to adjacentthen update adjacent' cost and remember that current is the previous vertex of adjacent alsoadd adjacent to the unvisited set when this algorithm terminates the cost of reaching all vertices in the graph has been computed assuming that all vertices are reachable from the source vertex in additionthe minimum cost path to each vertex can be determined from the previous vertex information that was maintained as the algorithm executed dijkstra' complexity analysis in the first step of dijkstra' algorithmthe next current vertex is always the unvisited vertex with smallest cost by always picking the vertex with smallest cost so farwe can be guaranteed that no other cheaper path exists to this vertex since we always proceed by considering the next cheapest vertex on our search to find cheapest paths in the graph the number of edges of any vertex in simpleundirected graph will always be less than the number of total vertices in the graph each vertex becomes the current vertex exactly once in the algorithm in step assume finding the next current takes this copy belongs to 'acha