0% found this document useful (0 votes)
5 views

Search Algorithm

The document discusses various search algorithms, categorizing them into uninformed (blind) and informed (heuristic) strategies. It details specific algorithms such as Breadth-First Search (BFS), Dijkstra's algorithm, Depth-First Search (DFS), and Greedy Best-First Search (GBFS), highlighting their principles, advantages, disadvantages, and use cases. Additionally, it covers advanced techniques like Iterative Deepening Search and Bidirectional Search, emphasizing their efficiency and complexity in problem-solving.

Uploaded by

judenblack468
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Search Algorithm

The document discusses various search algorithms, categorizing them into uninformed (blind) and informed (heuristic) strategies. It details specific algorithms such as Breadth-First Search (BFS), Dijkstra's algorithm, Depth-First Search (DFS), and Greedy Best-First Search (GBFS), highlighting their principles, advantages, disadvantages, and use cases. Additionally, it covers advanced techniques like Iterative Deepening Search and Bidirectional Search, emphasizing their efficiency and complexity in problem-solving.

Uploaded by

judenblack468
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Search Algorithms

A search algorithm takes a search problem as input and returns a solution, or an indication of
failure. Search algorithms help solve problems by finding sequences of actions leading from an
initial state to a goal state.

Types of Search Strategies

1. Uninformed (Blind) Search: These algorithms use no specific knowledge about the problem
domain, making them universally applicable but often less efficient.

2. Informed (Heuristic) Search: Use problem-specific knowledge to guide the search process,
usually resulting in faster solutions.

Uninformed Search Strategies

Uninformed search strategies, also known as blind search methods, explore the search space
without additional information beyond the problem definition. These strategies are essential for
cases where heuristic information is not available or where systematic exploration is required.

a) Breadth-First Search (BFS)

This search explores nodes level-by-level, beginning from the root and progressing layer by layer
outward.

Properties:

o Completeness: BFS is complete if the branching factor is finite, meaning it will find a
solution if one exists.

o Optimality: Guarantees finding the shortest path in terms of the number of steps if all
actions have the same cost.

o Time and Space Complexity: , where is the branching factor, and is the depth of
the shallowest solution.

Use Cases: Ideal when all actions cost the same, and the search tree isn’t too deep.

Example of Search Using Breadth-First Search (BFS)

Let's consider an example of BFS to solve a simple pathfinding problem. Suppose we want to
find the shortest path from a starting point (node A) to a goal (node G) in a simple graph, where
each node represents a location, and each edge represents a direct path between two nodes.

Graph Structure
Below is a sample graph representing our search problem:

/ \

B C

/| |\

DE FG

 Goal: Find the shortest path from node A to node G.

 Assumptions: All edges have equal costs, so BFS will find the shortest path in terms of
the number of steps.

Steps in BFS

1. Initialization:

o Start with node A.

o Use a queue to manage the nodes to explore, initialized with the starting node A.

o Mark A as visited to avoid re-processing.

2. Execution:

o Step 1: Dequeue A and explore its neighbors, B and C. Enqueue B and C.

 Queue: [B, C]

 Visited: {A}

{Note: Dequeue: This operation removes (or "pops") an element from the front of the queue. Enqueue:
This operation adds (or "pushes") an element, such as a node or state, to the end of the queue}

o Step 2: Dequeue B and explore its neighbors, D and E. Enqueue D and E.

 Queue: [C, D, E]

 Visited: {A, B}

o Step 3: Dequeue C and explore its neighbors, F and G. Enqueue F and G.

 Queue: [D, E, F, G]
 Visited: {A, B, C}

 Goal Reached: We found G while exploring C’s neighbors.

3. Path Found:

o BFS stops as soon as we find the goal node G.

o The path from A to G is identified as the shortest path: A → C → G.

b) Dijkstra’s algorithm or uniform-cost search

Dijkstra's algorithm is, in fact, a specific form of Uniform-Cost Search (UCS). UCS is a search
algorithm that expands the node with the lowest path cost first, ensuring it finds the least-cost
path to a goal if one exists. Dijkstra's algorithm uses this principle to find the shortest path from a
starting node to all other nodes in a graph, making it slightly more extensive than UCS, which
typically focuses on a single goal node.

Overview of Dijkstra’s Algorithm

 Purpose: To find the shortest (least-cost) path from a source node to all other nodes in a
graph with non-negative edge weights.

 Principle: Always expand the node with the lowest cumulative path cost from the start.

 Key Data Structure: A priority queue (usually implemented as a min-heap) to select the
next node with the minimum cost efficiently.

c) Depth-First Search (DFS) and the problem of memory

DFS is presented as a strategy that explores paths by diving as deep as possible along each
branch before backtracking. This uninformed search method has the advantage of lower memory
requirements compared to other strategies, such as Breadth-First Search (BFS), but it is not
without its challenges—particularly in handling memory and avoiding repeated or cyclic paths in
large or infinite search spaces.

Depth-First Search Overview

 Principle: DFS begins at the root node and explores as far down one branch as possible
before backtracking. It uses a Last-In, First-Out (LIFO) stack, where the most recently
generated node is expanded next.
 Path Exploration: DFS goes deep into one path at a time, only returning to previous
nodes when a dead-end or goal failure is encountered.

Advantages of DFS

1. Low Memory Usage:

o DFS generally requires storing only the path from the start node to the current
node, plus the nodes along unexpanded paths, significantly reducing memory
demands compared to BFS.

2. Efficient for Large Graphs:

o Since it doesn’t store all nodes at each level, DFS is efficient for exploring deep
spaces where paths are long, and the entire state space would otherwise be
challenging to store.

Memory Challenges and Problems

While DFS has lower memory requirements, it has its own set of potential pitfalls:

1. Failure to Terminate in Infinite Spaces:

o In graphs with infinite depth or cycles, DFS may continue infinitely along one
path, never backtracking to check other branches. This makes DFS non-
terminating in some cases unless a limit is imposed.

2. Difficulty with Optimal Solutions:

o DFS is not guaranteed to find the shortest path to a solution, as it explores one
path fully before considering alternatives. In cases where an early path leads to
the goal but is longer than alternative paths, DFS will not necessarily choose the
optimal one.

3. Cycle and Redundant Path Handling:

o Without mechanisms to detect cycles, DFS can revisit nodes within cycles
repeatedly, leading to excessive computation and memory usage. Implementing
cycle-checking (e.g., storing visited nodes) can help mitigate this but can reduce
the memory efficiency advantage.

Example of search using DFS

Imagine a simple maze represented as a tree structure where each branch is a possible path, and
we want to find a way from the start to the goal. Each node in the tree represents a room in the
maze, and edges between nodes represent pathways connecting rooms.
Graph Representation

Let’s represent our maze as follows:

A (Start)

/ | \

B C D

/ | / \

E F G H (Goal)

Depth-First Search Execution

DFS will explore nodes by going as deep as possible along each branch before backtracking.
We’ll assume we’re using a stack (LIFO structure) to keep track of the nodes to visit next.

1. Start at Node A:

o Add A to the stack: Stack = [A]

o Visit A and expand its neighbors B, C, and D. Push them onto the stack in that
order.

2. Visit Node D (last added, so first out from the stack):

o Stack = [B, C, D]

o Expand D, adding G and H to the stack.

o Stack = [B, C, G, H]

3. Visit Node H:

o Stack = [B, C, G, H]

o Since H is the goal node, the search stops here.

Path Found

The DFS path from A to H would look like this: A -> D -> H.

d) Depth-limited and iterative deepening search


Iterative Deepening Search combines the advantages of DLS and breadth-first search (BFS) by
systematically increasing the depth limit in successive iterations. This approach finds the goal
while ensuring that all nodes are explored within a certain depth limit before moving deeper.

Key Characteristics:

1. Incremental Depth Limit:

o IDS performs a series of depth-limited searches, starting from a depth of 0 and


increasing by 1 each time until the goal is found.

2. Advantages:

o Completeness: IDS is complete; it will find a solution if one exists, regardless of


how deep it is.

o Optimality: If the path cost is uniform, IDS will find the least-cost solution, as it
expands all nodes at depth d before going deeper.

o Memory Efficiency: Similar to DLS

3. Disadvantages:

o Time Complexity: IDS can be slower than other methods, as it repeatedly


explores nodes at shallower depths.

o Redundant Expansions: Nodes that are already visited at shallower depths will be
expanded again.

Bidirectional Search

Definition: Bidirectional Search is a search strategy that simultaneously explores the search
space from two directions: from the initial state towards the goal state and from the goal state
back to the initial state. The two searches are performed concurrently until they meet.

Key Concepts
1. Two Search Frontiers:

o One search tree is built from the initial state (forward search).

o A second search tree is built from the goal state (backward search).

2. Meeting Point:

o The search continues until the two trees intersect at a common node, indicating
that a path has been found.

3. Search Depth:

o In a typical unidirectional search, if the solution is at depth ddd, the time


complexity is O(bd)O(b^d)O(bd) (where bbb is the branching factor). In contrast,
bidirectional search reduces this to O(bd/2)O(b^{d/2})O(bd/2), as each search
only needs to explore half the depth.

Execution Steps

1. Initialization:

o Start with two sets of nodes: one for the forward search and one for the backward
search.

o Maintain two queues for the two searches.

2. Expand Nodes:

o Alternately expand nodes from the forward search and the backward search.

o After each expansion, check for any common nodes in the two sets.

3. Check for Intersection:

o If a node exists in both sets, the search has found a solution.

4. Path Reconstruction:

o Combine the paths from the initial state to the meeting point and from the goal
state to the meeting point.

Example

/ \

B C

/\ \
D E F

| \

G H (Goal)

Search Execution

1. Forward Search from A:

o Begin at A, expand to B and C.

2. Backward Search from H:

o Start at H, expand to F and G.

3. Continue Expanding:

o Expand B to D and E.

o Expand F back to C.

4. Intersection Found:

o When the forward search reaches E and the backward search reaches G, an
intersection occurs.

5. Path Reconstruction:

o The complete path from A to H is formed by concatenating the paths from A to E


and from G to H.

Advantages of Bidirectional Search

 Reduced Time Complexity: By effectively halving the depth of the search, it often finds
solutions more quickly than unidirectional searches.

 Lower Memory Usage: Memory requirements are also reduced, as only a fraction of the
total nodes need to be maintained at any given time.

Disadvantages of Bidirectional Search

 Complex Implementation: Managing two search trees and ensuring they can meet
requires more complex coding than a single search tree.

 Need for a Goal State: This method is only applicable when both the initial state and the
goal state are known.

Informed (Heuristic) Search Strategies


Informed search strategies make use of heuristics—additional information about the problem
space—to make educated guesses about which paths are more promising. Heuristics can
significantly reduce the search space, making informed strategies more efficient than uninformed
ones.

a) Greedy Best-First Search (GBFS)

BBFS is an informed search strategy that prioritizes exploration of nodes based on their
estimated proximity to the goal. This method uses a heuristic function h(n)hthat estimates
the cost from the current node to the goal, allowing the algorithm to quickly move toward what
appears to be the most promising path. While efficient in certain cases, Greedy Best-First Search
is not guaranteed to find the optimal path, as it focuses on short-term gains rather than overall
cost.

Properties of Greedy Best-First Search

1. Completeness:

o GBFS is not guaranteed to be complete, especially in spaces with infinite paths,


as it may get stuck in loops if it revisits nodes with low heuristic values.

2. Optimality:

o Not optimal: GBFS does not necessarily find the least-cost path to the goal
because it does not consider the actual path cost g(n)g(n)g(n).

o It can settle on suboptimal paths if those paths seem heuristically closer to the
goal.

3. Efficiency:

o GBFS can be highly efficient in terms of search time, especially in scenarios


where a well-designed heuristic brings the algorithm close to the goal quickly.

o However, it can also be inefficient and misled by inaccurate heuristics, exploring


non-promising paths that appear close to the goal but are far in reality.

Advantages of Greedy Best-First Search

 Fast Execution: GBFS often finds a path to the goal more quickly than other uninformed
or exhaustive search methods.

 Low Memory Usage: Because GBFS focuses only on promising nodes, it generally uses
less memory compared to exhaustive searches like Breadth-First Search (BFS).

 Simple Heuristic Application: By focusing solely , GBFS is easier to implement


and does not require calculating the full cost function ) used in A*.
Here's a detailed note on Greedy Best-First Search:

Lecture Note: Greedy Best-First Search

Overview

Greedy Best-First Search (GBFS) is an informed search strategy in artificial intelligence that
prioritizes exploration of nodes based on their estimated proximity to the goal. This method uses
a heuristic function h(n)h(n)h(n) that estimates the cost from the current node nnn to the goal,
allowing the algorithm to quickly move toward what appears to be the most promising path.
While efficient in certain cases, Greedy Best-First Search is not guaranteed to find the optimal
path, as it focuses on short-term gains rather than overall cost.

Key Concepts of Greedy Best-First Search

1. Heuristic Function (h(n)h(n)h(n)):

o In Greedy Best-First Search, h(n)h(n)h(n) is a heuristic function that estimates the


cost to reach the goal from node nnn.

o The choice of h(n)h(n)h(n) depends on the problem domain and should ideally
reflect the "distance" or "closeness" to the goal.

2. Evaluation Function:

o The evaluation function in GBFS is defined as f(n)=h(n)f(n) = h(n)f(n)=h(n),


meaning the algorithm only considers the heuristic value and not the actual cost
from the start node.

o Unlike A* Search, which uses f(n)=g(n)+h(n)f(n) = g(n) + h(n)f(n)=g(n)+h(n),


GBFS ignores the path cost g(n)g(n)g(n) and focuses solely on reaching the goal
as quickly as possible according to h(n)h(n)h(n).

3. Algorithm Process:

o The algorithm starts at the initial node and uses h(n)h(n)h(n) to evaluate all
reachable nodes.

o The node with the lowest heuristic value (indicating closest to the goal) is selected
for expansion.

o This process continues, with GBFS always choosing the node that appears closest
to the goal based on h(n)h(n)h(n).
o The algorithm terminates when the goal node is reached or if no more nodes are
left to explore.

Properties of Greedy Best-First Search

1. Completeness:

o GBFS is not guaranteed to be complete, especially in spaces with infinite paths,


as it may get stuck in loops if it revisits nodes with low heuristic values.

2. Optimality:

o Not optimal: GBFS does not necessarily find the least-cost path to the goal
because it does not consider the actual path cost g(n)g(n)g(n).

o It can settle on suboptimal paths if those paths seem heuristically closer to the
goal.

3. Efficiency:

o GBFS can be highly efficient in terms of search time, especially in scenarios


where a well-designed heuristic brings the algorithm close to the goal quickly.

o However, it can also be inefficient and misled by inaccurate heuristics, exploring


non-promising paths that appear close to the goal but are far in reality.

Advantages of Greedy Best-First Search

 Fast Execution: GBFS often finds a path to the goal more quickly than other uninformed
or exhaustive search methods.

 Low Memory Usage: Because GBFS focuses only on promising nodes, it generally uses
less memory compared to exhaustive searches like Breadth-First Search (BFS).

 Simple Heuristic Application: By focusing solely on h(n)h(n)h(n), GBFS is easier to


implement and does not require calculating the full cost function f(n)f(n)f(n) used in A*.

Disadvantages of Greedy Best-First Search

 Suboptimal Paths: Due to ignoring path costs, GBFS can end up taking a longer or more
costly path to the goal if led astray by a misleading heuristic.

 Incomplete in Infinite Spaces: In search spaces with infinite branches or loops, GBFS
may never terminate if it cycles through nodes with similar heuristic values.
 Heuristic Dependency: The effectiveness of GBFS depends heavily on the heuristic
function's accuracy. A poor heuristic can significantly reduce the algorithm’s efficiency.

You might also like