# Iterative Deepening Search (IDS) or Iterative Deepening Depth First Search (IDDFS)

An integral component of computer science and artificial intelligence are search algorithms. They are used to solve a variety of issues, from playing games like chess and checkers to locating the shortest route on a map. The Depth First Search (DFS) method, one of the most popular search algorithms, searches a network or tree by travelling as far as possible along each branch before turning around. However, DFS has a critical drawback: if the graph contains cycles, it could become trapped in an endless loop. Utilizing Iterative Deepening Search (IDS) or Iterative Deepening Depth First Search is one technique to solve this issue (IDDFS).

## What is IDS?

A search algorithm known as IDS combines the benefits of DFS with Breadth First Search (BFS). The graph is explored using DFS, but the depth limit steadily increased until the target is located. In other words, IDS continually runs DFS, raising the depth limit each time, until the desired result is obtained. Iterative deepening is a method that makes sure the search is thorough (i.e., it discovers a solution if one exists) and efficient (i.e., it finds the shortest path to the goal).

The pseudocode for IDS is straightforward:

Code

### How does IDS work?

The iterativeDeepeningSearch function performs iterative deepening search on the graph using a root node and a goal node as inputs until the goal is attained or the search space is used up. This is accomplished by regularly using the depthLimitedSearch function, which applies a depth restriction to DFS. The search ends and returns the goal node if the goal is located at any depth. The search yields None if the search space is used up (all nodes up to the depth limit have been investigated).

The depthLimitedSearch function conducts DFS on the graph with the specified depth limit by taking as inputs a node, a destination node, and a depth limit. The search returns FOUND if the desired node is located at the current depth. The search returns NOT FOUND if the depth limit is reached but the goal node cannot be located. If neither criterion is true, the search iteratively moves on to the node's offspring.

Program:

Code

Output

```Path found
```

• IDS is superior to other search algorithms in a number of ways. The first benefit is that it is comprehensive, which ensures that a solution will be found if one is there in the search space. This is so that all nodes under a specific depth limit are investigated before the depth limit is raised by IDS, which does a depth-limited DFS.
• IDS is memory-efficient, which is its second benefit. This is because IDS decreases the algorithm's memory needs by not storing every node in the search area in memory. IDS minimises the algorithm's memory footprint by only storing the nodes up to the current depth limit.
• IDS's ability to be utilised for both tree and graph search is its third benefit. This is due to the fact that IDS is a generic search algorithm that works on any search space, including a tree or a graph.

• IDS has the disadvantage of potentially visiting certain nodes more than once, which might slow down the search. The benefits of completeness and optimality frequently exceed this disadvantage. In addition, by employing strategies like memory or caching, the repeated trips can be minimised.