Search Algorithms
Lesson Learning Outcomes
• Differentiate between uninformed and informed search
algorithms
• Discuss the characteristics, advantages and limitations of
each type of search algorithm
• Analyze and identify appropriate search algorithms for
specific problem-solving scenarios in the context of
artificial intelligence.
• Apply search algorithms to solve real-world problems
Lesson objectives
• Define the importance of search algorithms in AI for problem
solving
• Types of search algorithms
• Exploration vs Exploitation
Problem-solving agents
• Search techniques are universal problem-solving methods.
• Rational agents or Problem-solving agents in AI mostly
use these search strategies or algorithms to solve a specific
problem and provide the best result.
• Problem-solving agents are the goal-based agents and use
atomic representation.
What is a Search Algorithm?
• A search algorithm is a kind of algorithm used
in artificial intelligence that explores a set of
potential solutions, also known as a search
space, in order to discover the best or most
optimum solution to a problem.
• To identify the optimum answer for a given set
of constraints, a search algorithm sorts through
a vast number of options.
• Generally, search algorithms work by arranging
the search space into a specific kind of graph,
which is usually a tree, and then calculating the
optimal score, or cost, of going through each
branch of the tree.
• A path that maximizes the cost within the
constraints of the implemented method from
the start state to the goal state is called a
Components of a Search
• State/Search Space
Problem
• The set of all possible states the system can be in. Each state represents a specific
configuration or situation of the problem
• Initial/Start State
• It is a state from where an agent begins the search.
• Goal State
• The desired state/condition that the system aims to reach. The objective of the search is to
find a sequence of actions that lead from initial state to the goal state
• Operators/Actions
• The set of actions or operators that the system can perform to transition from one state to
another. (building blocks of the search process)
• Transition model
• Describes how the system moves from one state to another when a specific action is applied.
• Path Cost 6
• The cost associated with taking a specific path. The goal is to find the path with minimum
cost
Other Terms
• Search tree: A tree representation of search problem. The root of the search
tree is the root node which is corresponding to the initial state.
• Time and space complexity are measured in
• ‘b‘ – maximum branching factor of the search tree.
• ‘d‘ – the depth of the least-cost solution.
• ‘m‘ – maximum depth of the state space(maybe infinity)
• Solution: It is an action sequence which leads from the start node to the goal
node.
• Optimal Solution: If a solution has the lowest cost among all solutions.
ROBOTIC LAWN MOWER
PROBLEM
1. Define the problem
2. Create a search space with states and actions
3. Employ search algorithms
4. Consider heuristics and optimization criteria
5. Adapt to a dynamic environment, possibly with a
learning mechanism
8
07/21/2025
07/21/2025 10
4 Essential Properties of Search Algorithms
• Completeness: A search algorithm is said to be complete if it
guarantees to return a solution if at least any solution exists for any
random input
• Optimality: If a solution found for an algorithm is guaranteed to be the
best solution (lowest path cost) among all other solutions, then such a
solution for is said to be an optimal solution.
• Time Complexity: Time complexity is a measure of time for an
algorithm to complete its task.
• Space Complexity: It is the maximum storage space required at any
point during the search, as the complexity of the problem.
AI: Chapter 3: Solving Problems by Searching 07/21/2025 12
What is Uninformed Search in
AI?
• Aka blind search : an algorithm that explores a problem space
(produces the search tree ) without any domain knowledge or
information about the problem other than the initial state and the
possible actions to take.
• The machine blindly follows the algorithm regardless of whether
right or wrong, efficient or in-efficient. (it’s brute force in nature)
• They systematically explore the search space for all possible
solutions of the problem by applying predefined rules to generate
successor states until a goal state is found or the search is
exhausted.
• They are less efficient than informed search algorithms.
• They are used in various applications, ranging from game playing
to route planning and problem-solving
Breadth-First Search (BFS)
• Exploration Strategy: Explores the search
space level by level, visiting all nodes at the
current level before moving on to the next
level.
• Memory Usage: Requires more memory as it
needs to store all nodes at the current level.
• Completeness: Guarantees finding the
shallowest solution, making it complete if the
branching factor is finite.
• Optimality: Finds the optimal solution in
terms of the number of steps but not
necessarily in terms of cost.
Depth-First Search (DFS)
• Exploration Strategy: Explores as far as
possible along one branch before backtracking.
• Memory Usage: Uses less memory compared
to BFS, as it only needs to store the nodes
along the current path.
• Completeness: May not be complete if the
search space has infinite depth or loops.
• Optimality: Does not guarantee finding the
optimal solution in terms of the number of
steps or cost.
Depth-Limited Search (DLS)
• Exploration Strategy: Similar to DFS but with
a depth limit, preventing it from going too deep
into the search space.
• Memory Usage: Uses less memory compared
to DFS but may still require significant memory
for deep searches.
• Completeness: Complete if the depth limit is
greater than or equal to the depth of the
optimal solution.
• Optimality: May not find the optimal solution
if the depth limit is too shallow.
Uniform-Cost Search (UCS)
• Exploration Strategy: Explores the least-cost
path first, prioritizing nodes with lower path
costs.
• Memory Usage: Can use a significant amount of
memory, especially in scenarios with high path
costs.
• Completeness: Complete if the step cost is
greater than or equal to some small positive value
and the solution exists.
• Optimality: Guarantees finding the optimal
solution in terms of cost.
Iterative deepening depth-first Search
Bidirectional Search Algorithm
• Completeness: Bidirectional Search is
complete if we use BFS in both
searches.
• Time Complexity: Time complexity of
bidirectional search using BFS is O(bd).
• Space Complexity: Space complexity of
bidirectional search is O(bd).
• Optimal: Bidirectional search is
Optimal.
Summary
What is Informed Search in AI?
• AKA heuristic search: it use additional knowledge or heuristics to guide the
search process
• Examples of additional knowledge: how far we are from the goal, path cost,
how to reach to goal node, etc.
• This knowledge help agents to explore less to the search space and find more
efficiently the goal node. (more useful for large search space)
• Heuristic is a function h(n) in Informed Search, used to find the most
promising path.
• It takes the current state of the agent as its input and produces the estimation
of how close agent is from the goal.
Best-first Search Algorithm (Greedy Search)
• Time Complexity: The worst case time complexity of
Greedy best first search is O(bm).
• Space Complexity: The worst case space complexity of
Greedy best first search is O(bm). Where, m is the
maximum depth of the search space.
• Complete: Greedy best-first search is also incomplete,
even if the given state space is finite.
• Optimal: Greedy best first search algorithm is not
optimal.
A* Search Algorithm
• A* search is the most commonly known form of best-first search.
• It uses heuristic function h(n), and cost to reach the node n from
the start state g(n).
• A* algorithm returns the path which occurred first, and it does
not search for all remaining paths.
• The efficiency of A* algorithm depends on the quality of heuristic.
• A* algorithm expands all nodes which satisfy the condition f(n)
Key Features of Informed Search
Applications of Search
Algorithms
• Pathfinding: finding the shortest path between two points.
• Dijkstra's algorithm or A* (A-star)
• Scheduling Tasks efficiently: find an optimal schedule that
minimizes the overall completion time.
• Game theory: enable players or AI agents to analyze
potential moves, evaluate outcomes, and make informed
decisions.
References
• https://www.youtube.com/watch?v=OmOwj3qMdOY
• https://angeluriot.com/maze_solver/
• Top 5 Most Common Graph Algorithms for Coding Intervie
ws (youtube.com)
• Breadth First Search (BFS): Visualized and Explained (you
tube.com
)
• Depth First Search (DFS) Explained: Algorithm, Examples,
and Code (youtube.com
)