![]() |
VOOZH | about |
Uniform-Cost Search is a variant of Dijikstra's algorithm. Here, instead of inserting all vertices into a priority queue, we insert only the source, then one by one insert when needed. In every step, we check if the item is already in the priority queue (using the visited array). If yes, we perform the decrease key, else we insert it.
This variant of Dijkstra is useful for infinite graphs and that graph which are too large to represent in memory. Uniform-Cost Search is mainly used in Artificial Intelligence.
Examples:
Input :
Output : Minimum cost from S to G is =3
Uniform-Cost Search is similar to Dijikstra's algorithm. In this algorithm from the starting state, we will visit the adjacent states and will choose the least costly state then we will choose the next least costly state from the all un-visited and adjacent states of the visited states, in this way we will try to reach the goal state (note we won't continue the path through a goal state ), even if we reach the goal state we will continue searching for other possible paths( if there are multiple goals). We will keep a priority queue that will give the least costly next state from all the adjacent states of visited states.
Minimum cost from 0 to 6 is = 3
Time Complexity: O( m ^ (1+floor(l/e)))
where,
m is the maximum number of neighbors a node has
l is the length of the shortest path to the goal state
e is the least cost of an edge