Chapter 3 Problem Solving
Chapter 3 Problem Solving
Problem Solving
Unit 3: Problem Solving
• Bidirectional search can use search techniques such as BFS, DFS, DLS, etc.
• Advantages:
• Disadvantages:
• For each neighbor node, calculate its initial g(n) value, which is the sum of the g
value of the current node and the cost of moving from the current node to a
neighboring node. If the neighbor node is not in priority order or the original g(n)
value is less than its current g value, update its g value and set its parent node to
the current node. Calculate the f(n) value from the neighbor node and add it to
the priority queue.
• If the cycle ends without finding the destination node, the graph has no path from
start to finish. The key to the efficiency of A* is its use of a heuristic function h(n)
that provides an estimate of the remaining cost of reaching the goal of any node.
By combining the actual cost g (n) with the heuristic cost h (n), the algorithm
effectively explores promising paths, prioritizing nodes likely to lead to the
shortest path. It is important to note that the efficiency of the A* algorithm is
highly dependent on the choice of the heuristic function. Acceptable heuristics
ensure that the algorithm always finds the shortest path, but more informed and
accurate heuristics can lead to faster convergence and reduced search space.
Advantages of A* Search Algorithm in Artificial Intelligence
• Optimal solution: A* ensures finding the optimal (shortest) path from the start node to the destination node in
the weighted graph given an acceptable heuristic function. This optimality is a decisive advantage in many
applications where finding the shortest path is essential.
• Completeness: If a solution exists, A* will find it, provided the graph does not have an infinite cost This
completeness property ensures that A* can take advantage of a solution if it exists.
• Efficiency: A* is efficient ifan efficient and acceptable heuristic function is used. Heuristics guide the search to a
goal by focusing on promising paths and avoiding unnecessary exploration, making A* more efficient than
non-aware search algorithms such as breadth-first search or depth-first search.
• Versatility: A* is widely applicable to variousproblem areas, including wayfinding, route planning, robotics,
game development, and more. A* can be used to find optimal solutions efficiently as long as a meaningful
heuristic can be defined.
• Optimized search: A* maintains a priority order to select the nodes with the minor f(n) value (g(n) and h(n)) for
expansion. This allows it to explore promising paths first, which reduces the search space and leads to faster
convergence.
• Memory efficiency: Unlike some other search algorithms, such as breadth-first search, A* stores only a limited
number of nodes in the priority queue, which makes it memory efficient, especially for large graphs.
• Tunable Heuristics: A*'s performancecan be fine-tuned by selecting different heuristic functions. More
educated heuristics can lead to faster convergence and less expanded nodes.
• Extensively researched: A* is a well-established algorithm with decades of research and practical applications.
Many optimizations and variations have been developed, making it a reliable and well-understood
troubleshooting tool.
• Web search: A* can be used for web-based path search, where the algorithm constantly updates the path
according to changes in the environment or the appearance of new It enables real-time decision-making in
dynamic scenarios.
Disadvantages of A* Search Algorithm in Artificial Intelligence
• Heuristic accuracy: The performance of the A* algorithm depends heavily on the accuracy of the heuristic
function used to estimate the cost from the current node to the If the heuristic is unacceptable (never
overestimates the actual cost) or inconsistent (satisfies the triangle inequality), A* may not find an optimal path
or may explore more nodes than necessary, affecting its efficiency and accuracy.
• Memory usage: A* requires that all visited nodes be kept in memory to keep track of explored paths. Memory
usage can sometimes become a significant issue, especially when dealing with an ample search space or limited
memory resources.
• Time complexity: AlthoughA* is generally efficient, its time complexity can be a concern for vast search spaces
or graphs. In the worst case, A* can take exponentially longer to find the optimal path if the heuristic is
inappropriate for the problem.
• Bottleneck at the destination: In specific scenarios, the A* algorithm needs to explore nodes far from the
destination before finally reaching the destination region. This the problem occurs when the heuristic needs to
direct the search to the goal early effectively.
• Cost Binding: A* faces difficulties when multiple nodes have the same f-value (the sum of the actual cost and
the heuristic cost). The strategy used can affect the optimality and efficiency of the discovered path. If not
handled correctly, it can lead to unnecessary nodes being explored and slow down the algorithm.
• Complexity in dynamic environments: In dynamic environments where the cost of edges or nodes may change
during the search, A* may not be suitable because it does not adapt well to such changes. Reformulation from
scratch can be computationally expensive, and D* (Dynamic A*) algorithms were designed to solve this
• Perfection in infinite space : A* may not find a solution in infinite state space. In such cases, it can run
indefinitely, exploring an ever-increasing number of nodes without finding a solution. Despite these
shortcomings, A* is still a robust and widely used algorithm because it can effectively find optimal paths in many
practical situations if the heuristic function is well-designed and the search space is manageable. Various
variations and variants of A* have been proposed to alleviate some of its limitations.
Applications of the A* Search Algorithm in Artificial Intelligence
• Motivation
• To approximate the shortest
path in real-life situations, like-
in maps, games where there can
be many hindrances.
We can consider a 2D Grid
having several obstacles and we
start from a source cell (colored
red below) to reach towards a
goal cell (colored green below)
What is A* Search Algorithm?
• A* Search algorithm is one of the best and popular technique used in
path-finding and graph traversals.
• Why A* Search Algorithm?
Informally speaking, A* Search algorithms, unlike other traversal
techniques, it has “brains”. What it means is that it is really a smart
algorithm which separates it from the other conventional algorithms.
This fact is cleared in detail in below sections.
And it is also worth mentioning that many games and web-based
maps use this algorithm to find the shortest path very efficiently
(approximation).
Explanation
• Consider a square grid having many obstacles and we are given a starting cell and
a target cell. We want to reach the target cell (if possible) from the starting cell as
quickly as possible. Here A* Search Algorithm comes to the rescue.
What A* Search Algorithm does is that at each step it picks the node according to
a value-‘f’ which is a parameter equal to the sum of two other parameters – ‘g’
and ‘h’. At each step it picks the node/cell having the lowest ‘f’, and process that
node/cell.
We define ‘g’ and ‘h’ as simply as possible below
g = the movement cost to move from the starting point to a given square on the
grid, following the path generated to get there.
h = the estimated movement cost to move from that given square on the grid to
the final destination. This is often referred to as the heuristic, which is nothing but
a kind of smart guess. We really don’t know the actual distance until we find the
path, because all sorts of things can be in the way (walls, water, etc.). There can be
many ways to calculate this ‘h’ which are discussed in the later sections.