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

Algo

Uploaded by

khshri3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Algo

Uploaded by

khshri3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Depth-Limited Search (DLS)

Depth-Limited Search (DLS) is a variant of Depth-First Search (DFS) where the search is limited to a
specific depth. This means the algorithm will explore paths only up to a predetermined limit (let's call
this limit l), beyond which it will stop.

 Process:

o Starts at the root node and explores as far as possible along each branch before
backtracking, like DFS.

o However, it stops when it reaches the depth limit l. This prevents the algorithm from
going deeper, avoiding the risk of ge ng trapped in infinite paths in cyclic or infinite
search spaces.

 Advantages:

o Solves problems that require limi ng explora on depth (useful when the search
space is very large or infinite).

o Prevents infinite loops in graphs with cycles.

 Disadvantages:

o If the solu on is deeper than the depth limit, DLS will not find it.

o Choosing an appropriate depth limit can be challenging.

2. Itera ve Deepening Depth-First Search (IDDFS)

Itera ve Deepening Depth-First Search (IDDFS) is a search strategy that combines the benefits of
Depth-First Search (DFS) and Breadth-First Search (BFS). It runs mul ple Depth-Limited Searches,
star ng with a depth limit of 0 and gradually increasing the depth limit by 1 at each itera on, un l a
solu on is found.

 Process:

o Perform a Depth-Limited Search with depth 0 (only root node).

o Then, perform another search with depth 1, and so on.

o Con nue increasing the depth limit un l the goal is found.

 Advantages:

o Space Efficiency: Since each depth-limited search is DFS, it uses less memory (similar
to DFS).

o Completeness: Like BFS, it will eventually find the shallowest goal node.

o Op mality: If step costs are uniform, IDDFS finds the op mal solu on.

 Disadvantages:

o Redundant explora on: Nodes are re-explored mul ple mes across different
itera ons. However, since the deeper levels are computa onally more expensive, the
overhead is not significant for most problems.
3. Uniform Cost Search (UCS)

Uniform Cost Search (UCS) is an uninformed search algorithm that expands the node with the lowest
cumula ve path cost (g(n)), which is the cost of the path from the root node to node n.

 Process:

o Starts at the root node and maintains a priority queue (min-heap) to keep track of
the nodes to be explored, where the priority is based on the path cost.

o It explores the least expensive node first and con nues un l the goal node is found
or all paths are explored.

 Advantages:

o Completeness: UCS is complete as it will find a solu on if one exists.

o Op mality: UCS is guaranteed to find the least cost (op mal) solu on because it
always explores the least cost path first.

 Disadvantages:

o Time and Space Complexity: UCS can be slow in cases where there are many nodes
with low costs. It is less efficient for large state spaces as it needs to explore all
possible paths.

Comparison Summary:

 DLS: Explores to a fixed depth, good for controlling search depth but may miss deeper
solu ons.

 IDDFS: Combines the space efficiency of DFS with the completeness of BFS, op mal for
problems with unknown depths.

 UCS: Explores based on the path cost, op mal for problems where path costs are non-
uniform.

4o

You said:

write advantages and disadvantages of bfs & dfs

ChatGPT said:

ChatGPT

Breadth-First Search (BFS)

Advantages:

1. Completeness: BFS is complete, meaning it will find a solu on if one exists, as it explores all
possible nodes level by level.

2. Op mality: BFS is op mal if all edge costs are the same, as it always finds the shortest path
to the goal node.
3. Shortest Path: If the graph has uniform edge weights, BFS guarantees finding the shortest
path from the star ng node to the goal.

4. Explores All Solu ons: It systema cally explores all levels of the tree, ensuring that no
solu on at any level is missed.

Disadvantages:

1. Memory Intensive: BFS requires storing all nodes at the current level in memory, which can
become problema c for large search trees. Its space complexity is O(b^d), where b is the
branching factor and d is the depth of the tree.

2. Slower for Deep Searches: BFS can be slower when the solu on is deep, as it explores all
levels uniformly even if the solu on is far down the tree.

3. Less Efficient for Unbounded Problems: In problems where the state space is infinite or very
large, BFS might explore an excessive number of unnecessary nodes before finding the
solu on.

Depth-First Search (DFS)

Advantages:

1. Low Memory Usage: DFS uses less memory than BFS. It only needs to store the path from
the root to the current node and unvisited sibling nodes. Its space complexity is O(d), where
d is the depth of the tree.

2. Faster for Deep Solu ons: DFS can reach deep solu ons quickly if they exist near the end of
a long path.

3. Simple Implementa on: DFS is simple to implement, especially with recursion, making it a
straigh orward algorithm to use for exploring deep trees or graphs.

4. Useful for Pathfinding in Large Graphs: DFS is o en used in applica ons like maze-solving
where reaching deep solu ons is necessary.

Disadvantages:

1. Not Complete (Infinite Depth): DFS is not guaranteed to find a solu on if the search tree is
infinite or has cycles (unless cycle detec on is implemented). It may get stuck in loops.

2. Not Op mal: DFS does not necessarily find the shortest path to the goal; it might find a
subop mal or longer path.

3. May Explore Irrelevant Paths: DFS can waste me exploring deep but irrelevant paths,
especially if the solu on is shallow or located in another part of the graph.

4. Inefficient for Shallow Solu ons: DFS can be inefficient when the solu on is located near the
root but DFS goes deep along other branches first.

You might also like