3 Search Algorithms And Techniques

Artificial Intelligence · Unit 3

Search Algorithms and Techniques

Exam-focused notes for Search Algorithms and Techniques (Artificial Intelligence, BIT252): what the TU syllabus asks and how it has actually been tested, with 10 solved past questions from this unit.

Search Algorithms and Techniques in short

Search is how an AI program finds a sequence of actions from a start state to a goal. This chapter covers blind search, heuristic search, search in AND-OR graphs, and search in games.

Search Algorithms and Techniques: notes

Depth first search (DFS) expands the deepest node in the frontier first. It uses a stack (last in, first out). It goes down one branch until it reaches a leaf, then backtracks.

Take this tree: A has children B and C. B has children D and E. C has children F and G. DFS visits the nodes in this order:

$$A \to B \to D \to E \to C \to F \to G$$

Properties, with branching factor $b$ and maximum depth $m$:

  • Time is $O(b^m)$.
  • Space is only $O(bm)$, which is its main strength.
  • Not complete in infinite or looping spaces.
  • Not optimal, because it can find a deep goal before a shallow one.

Breadth first search (BFS) expands all nodes at one depth before going deeper. It uses a queue (first in, first out). On the same tree, BFS visits:

$$A \to B \to C \to D \to E \to F \to G$$

If the shallowest goal is at depth $d$, then:

  • Time is $O(b^d)$ and space is also $O(b^d)$, since every node is kept in memory.
  • It is complete when $b$ is finite.
  • It is optimal when all step costs are equal.
DFSBFS
Uses a stackUses a queue
Goes deep firstGoes level by level
Space $O(bm)$, smallSpace $O(b^d)$, very large
Not complete, not optimalComplete, optimal for equal costs
Good when many solutions lie deepGood when the goal is shallow

Depth limited search (DLS) is DFS with a fixed depth limit $\ell$. Nodes at depth $\ell$ are treated as having no children. This fixes the main problem of DFS: it cannot get lost in an infinite branch or a loop.

Limitations:

  • If the goal is deeper than $\ell$, the search fails, so it is not complete.
  • If $\ell$ is larger than the goal depth, it may return a longer path first, so it is not optimal.
  • Choosing a good limit needs knowledge about the problem. For example, in a map with 20 cities, no path needs more than 19 steps.

Time is $O(b^\ell)$ and space is $O(b\ell)$.

Iterative deepening search (IDS) runs depth limited search again and again with limits 0, 1, 2, and so on, until a goal is found. It joins the small memory of DFS with the completeness and optimality of BFS.

On the tree above, with goal G:

  • Limit 0: visit A only. No goal.
  • Limit 1: visit A, B, C. No goal.
  • Limit 2: visit A, B, D, E, C, F, G. Goal found.

The repeated work looks wasteful but is small, because most nodes are in the bottom level. With $b = 10$ and $d = 5$, IDS generates

$$6 + 50 + 400 + 3000 + 20000 + 100000 = 123456$$

nodes. BFS generates $1 + 10 + 100 + 1000 + 10000 + 100000 = 111111$ nodes. The extra cost is about 11 percent. Time is $O(b^d)$, space is $O(bd)$, and it is complete and optimal for equal step costs.

What this unit covers

  • Depth first search
  • Breadth first search
  • Depth limited search
  • Iterative deepening search
  • Hill climbing search
  • Greedy best first search
  • A* search algorithm
  • AO* search for multiple goals
  • Alpha beta pruning in game trees
  • Search algorithm evaluation factors

Iterative deepening search

2082 · 5 marks

How iterative deepening search is used to find goal in state space? Illustrate using example. [5]

Iterative Deepening Search (IDS) is a search strategy that combines the space efficiency of Depth-First Search (DFS) and the optimality/completeness of Breadth-First Search (BFS). It works by repeatedly applying depth-limited search with increasing depth limits (0, 1, 2, 3, ...) until the goal is...

Open this answer on its own page →

Depth limited search

2080 · 10 marks

How do Depth Limited Search solve the problem of Depth First Search and discuss about its limitations? Illustrate the concept of AO* search in multiplication of any 3 matrices.[10]

--- DFS suffers from a critical problem: it can get trapped in infinite loops or go down infinitely deep paths in graphs/trees that have infinite depth or contain cycles. This means DFS may never find a solution even if one exists, making it incomplete. --- Depth Limited Search (DLS) is a modifie...

Open this answer on its own page →

Hill climbing search

2080 · 5 marks

Discuss about Hill climbing search with its limitations. [5]

Hill Climbing is a local search algorithm that continuously moves in the direction of increasing value (uphill) to find the peak (optimal solution). It is an iterative algorithm that starts with an arbitrary solution and attempts to find a better solution by making incremental changes. Note: Refe...

Open this answer on its own page →

2079 · 10 marks

Justify that AI can't exist without searching? Solve the following 8 puzzle problem using Hill climbing search algorithm.

Initial State: $$\begin{array}{|c|c|c|}\hline 1 & 2 & 4 \ \hline 5 & & 7 \ \hline 3 & 6 & 8 \ \hline\end{array}$$

Goal State: $$\begin{array}{|c|c|c|}\hline 1 & 4 & 7 \ \hline 2 & 5 & 8 \ \hline 3 & 6 & \ \hline\end{array}$$

[10]

Show solved answer

AI Cannot Exist Without Searching + Hill Climbing on 8-Puzzle

Part 1: Justify That AI Cannot Exist Without Searching (4 marks)

Search is the process of systematically exploring a state space to find a sequence of actions leading from an initial state to a goal state.

Justification:

  1. Problem formulation is universal in AI. Almost every AI problem is formulated as an initial state, a set of actions, a transition model, a goal test, and a path cost. Solving it means finding a path, which is search.

  2. Intelligence requires choosing among alternatives. An intelligent agent faces many possible states and actions. Selecting the right action toward a goal inherently requires exploring alternatives, that is, searching.

  3. Without search only two options remain, both non-intelligent:

    • Acting randomly (not rational), or
    • Using a fixed hardcoded response (not general, not adaptive).
  4. All major AI subfields rely on search:

AI TaskRole of Search
Problem solvingExplore action sequences to reach goal
Game playingSearch move/counter-move trees (Minimax)
Path finding, roboticsFind route from start to destination
PlanningSearch for a valid plan
Machine learningGradient descent searches a hypothesis/parameter space
Theorem provingSearch inference chains

Conclusion: Whether uninformed (BFS, DFS), informed (A*, Hill Climbing), or adversarial (Minimax), every intelligent behavior reduces to navigating a problem space. Hence AI cannot exist without searching.


Part 2: 8-Puzzle Using Hill Climbing (6 marks)

Given Data

Initial State

1 2 4
5 _ 7
3 6 8

Goal State

1 4 7
2 5 8
3 6 _

Heuristic: number of misplaced tiles $h(n)$ (blank excluded). Hill Climbing moves to a neighbor with lower $h$.

Goal Positions (row, col)

TileGoalTileGoalTileGoal
1(0,0)4(0,1)7(0,2)
2(1,0)5(1,1)8(1,2)
3(2,0)6(2,1)blank(2,2)

Step 0: Evaluate Initial State

1 2 4
5 _ 7
3 6 8
TileCurrentGoalMisplaced?
1(0,0)(0,0)No
2(0,1)(1,0)Yes
4(0,2)(0,1)Yes
5(1,0)(1,1)Yes
7(1,2)(0,2)Yes
3(2,0)(2,0)No
6(2,1)(2,1)No
8(2,2)(1,2)Yes

$$h(\text{initial}) = 5$$


Step 1: Generate Successors (blank at (1,1))

UP (swap blank with 2):

1 _ 4
5 2 7
3 6 8

Misplaced: 4, 5, 2, 7, 8 → $h = 5$

DOWN (swap blank with 6):

1 2 4
5 6 7
3 _ 8

Misplaced: 2, 4, 5, 6, 7, 8 → $h = 6$

LEFT (swap blank with 5):

1 2 4
_ 5 7
3 6 8

Misplaced: 2, 4, 7, 8 → $h = 4$ ✓ (5 now correct at (1,1))

RIGHT (swap blank with 7):

1 2 4
5 7 _
3 6 8

Misplaced: 2, 4, 5, 7, 8 → $h = 5$

Best successor: LEFT, with $h = 4 < 5$. Move there.


Step 2: Current State $h = 4$ (blank at (1,0))

1 2 4
_ 5 7
3 6 8

Successors:

UP (swap with 1):

_ 2 4
1 5 7
3 6 8

Misplaced: 1, 2, 4, 7, 8 → $h = 5$

DOWN (swap with 3):

1 2 4
3 5 7
_ 6 8

Misplaced: 2, 4, 3, 7, 8 → $h = 5$

RIGHT (swap with 5, returns toward previous):

1 2 4
5 _ 7
3 6 8

$h = 5$ (the initial state)

Best successor $h = 5$, but current $h = 4$.

Since no neighbor improves on $h = 4$ (all are $\geq 5$), Hill Climbing halts here.


Result

Hill Climbing gets stuck at:

1 2 4
_ 5 7
3 6 8       h = 4

This is a local minimum (also a plateau/ridge situation): every move increases $h$. Therefore plain (steepest-ascent) Hill Climbing fails to reach the goal for this puzzle.

Why it fails: Hill Climbing is greedy and has no backtracking. When it reaches a state whose neighbors are all worse, it stops even though the global goal ($h=0$) is not reached. To escape, one would use techniques such as:

  • Random-restart Hill Climbing
  • Simulated Annealing
  • Stochastic / sideways moves
  • Or a complete search like A* with Manhattan distance.

Final answer: Using number-of-misplaced-tiles heuristic, Hill Climbing improves from $h=5$ to $h=4$ then gets stuck at a local minimum and cannot reach the goal state.

Open this answer on its own page →

Alpha beta pruning in game trees

2079 · 5 marks

What is the purpose of alpha beta pruning? Explain. [5]

Show solved answer

Alpha-Beta Pruning

Purpose

The purpose of alpha-beta pruning is to reduce the number of nodes evaluated in the minimax search tree without affecting the final result. It allows the minimax algorithm to search deeper in the same amount of time by eliminating (pruning) branches that cannot possibly influence the final decision.

Note: Reference notes were not available for this topic; the following is based on standard AI curriculum material consistent with TU BSc CSIT syllabus.


Background

The Minimax algorithm explores the entire game tree to find the optimal move, but this is computationally expensive. For a game tree with branching factor b and depth d, minimax evaluates O(b^d) nodes.

Alpha-beta pruning reduces this to approximately O(b^(d/2)) in the best case, effectively doubling the searchable depth.


Key Concepts

ParameterRole
Alpha (α)The best (highest) value that the MAX player can guarantee so far. Initialized to -∞
Beta (β)The best (lowest) value that the MIN player can guarantee so far. Initialized to +∞

How It Works

  1. The algorithm performs a standard depth-first minimax search.
  2. At each node, it maintains the α and β values.
  3. Pruning occurs when:
    • At a MIN node: if the current value becomes ≤ α, prune remaining children (Alpha cutoff).
    • At a MAX node: if the current value becomes ≥ β, prune remaining children (Beta cutoff).

Pruning Conditions

At MAX node:  if value >= β  → PRUNE (Beta cutoff)
At MIN node:  if value <= α  → PRUNE (Alpha cutoff)

Example

Consider the following minimax tree:

         MAX
        /    \
      MIN    MIN
     / \     / \
    3   5   2   9
  • MAX evaluates left MIN node → gets min(3,5) = 3, so α = 3
  • MAX evaluates right MIN node → sees value 2
    • Since 2 < α (3), the right subtree value cannot exceed 3
    • The remaining child (9) is pruned -- no need to evaluate it
  • Final answer: MAX chooses 3

Advantages

  1. Efficiency: Reduces time complexity from O(b^d) to O(b^(d/2)).
  2. Same result: Always produces the same optimal move as full minimax.
  3. Deeper search: Allows AI to look further ahead within the same time limit.
  4. Practical use: Widely used in game-playing AI (chess, checkers, tic-tac-toe).

Summary

Alpha-beta pruning is an optimization technique for the minimax algorithm that prunes branches which cannot affect the outcome, using two boundary values α and β. It makes game-tree search significantly faster while guaranteeing the same optimal decision as the full minimax search.

Open this answer on its own page →

Search algorithm evaluation factors

2080.2 · 10 marks

How do you evaluate any searching algorithm? What are constraint satisfaction problems? Differentiate between Greedy Best First Search and A* search.[10]

--- A searching algorithm is evaluated based on the following four standard criteria: - A search algorithm is complete if it is guaranteed to find a solution whenever one exists. - Example: BFS is complete (for finite branching factor); DFS is not complete in infinite state spaces. - A search alg...

Open this answer on its own page →

Depth first search

2080.2 · 5 marks

Distinguish between Depth First Search and Breadth First Search. [5]

Note: Reference notes were not available for this topic. The following answer is based on standard, correct Computer Science knowledge appropriate for TU BSc CSIT curriculum. --- DFS explores a graph by going as deep as possible along each branch before backtracking. It uses a stack (or recursion...

Open this answer on its own page →

0 · 5 marks

Differentiate between DFS and BFS. [5]

DFS (Depth First Search) and BFS (Breadth First Search) are two fundamental graph/tree traversal algorithms. They differ in strategy, data structure used, and application. --- Aspect DFS (Depth First Search) BFS (Breadth First Search) --------- Strategy Explores as deep as possible along a branch...

Open this answer on its own page →

AO* search for multiple goals

0 · 10 marks

Illustrate the concept of AO* search with an example. Which search will work on multiple goals environment? What are the four evaluation factors of searching algorithm?[10]

AO (And-Or Star) search is a heuristic search algorithm used to solve problems that can be decomposed into sub-problems using AND-OR graphs. It is an extension of the A algorithm designed for problem reduction (decomposition) rather than simple state-space search. - OR nodes: Represent alternativ...

Open this answer on its own page →

A* search algorithm

0 · 5 marks

Define agent. Describe the heuristic function of A* search? [5]

An agent is anything that can be perceived its environment through sensors and acts upon that environment through actuators. - A human agent has eyes, ears (sensors) and hands, legs (actuators). - A software agent has programs and data as sensors and actuators. - A rational agent is one that acts...

Open this answer on its own page →