 Hello everyone, this is Alice Gao. In this video, I'm going to discuss the iterative deepening search algorithm, or the IDS algorithm. This may be the first uninform search algorithm that you have not learned before. I hope you are excited about this video. Let's look at a comparison between BFS and DFS. There is a clear tradeoff between them. On one hand, DFS has better space complexity. DFS requires linear space, whereas BFS requires exponential space. On the other hand, BFS has a better guarantee on completeness. BFS is guaranteed to find a solution, whereas DFS may get stuck in a cycle. I have a question for you. Do you think it is possible to design a search algorithm that combines the best of BFS and DFS? This may sound too good to be true, but it turns out that it's possible. Iterative deepening search combines BFS and DFS in an interesting way. IDS starts with a depth limit of 0 and incremented as long as it hasn't found a goal node. For every depth limit, IDS performs DFS up to the depth limit. This means that if the current node is at the depth limit, IDS will not generate and add its successors to the frontier. Essentially, IDS backtracks when it reaches the depth limit. Every time we increase the depth limit, IDS starts the depth first search all over again. IDS is an interesting hybrid of BFS and DFS. It's similar to DFS since it performs DFS for each depth limit. It's similar to BFS since it explores the search graph level by level by increasing the depth limit by 1 every time. The best way to understand IDS is to trace the algorithm on search graph. Let's consider the same search graph. I will add nodes to the frontier in alphabetical order. While executing the algorithm, I will keep track of the depth limit, the frontier, and the search tree. Start with a depth limit of 0. Add the initial state S to the frontier. The most recent node added to the frontier was S. S is the first node expanded. Remove S from the frontier. S is at level 0, which is the depth limit. Therefore, we do not generate its successors. The frontier is empty. Let's increase the depth limit to 1. Add the initial state S to the frontier. The most recent node added to the frontier was S. S is the second node expanded. Remove S from the frontier. S is not at the depth limit. S has three successors, D, E, and P. Let's add them to the frontier in alphabetical order and also add them to the search tree. The most recent node added to the frontier was P. P is the third node expanded. Remove P from the frontier. P is at the depth limit. We do not generate P's successors. The most recent node added to the frontier was E. E is the fourth node expanded. Remove E from the frontier. E is at the depth limit again. We do not generate E's successors. The most recent node added to the frontier was D. D is the fifth node expanded. Remove D from the frontier. D is at the depth limit. Once again, we do not generate its successors. The frontier is empty again. Let's increase the depth limit to 2. By now, you should have a sense of how IDS works. Let me show you the search tree after we're done with depth limit equals to 2. IDS still has not terminated. We need to increase the depth limit again and perform DFS again. As you can see, IDS is mimicking the behavior of BFS in the sense that it is increasing the depth limit by one each time. Doing this ensures that IDS does not miss the shallowest goal node. For each depth limit, IDS tries to save space by performing DFS instead of BFS. Let's look at the properties of IDS. Space complexity, time complexity, completeness, and optimality. For space complexity, IDS performs DFS for every depth limit. Since IDS increases the depth limit by one each time, it will terminate at depth D, where D is the depth of the shallowest goal node. The maximum length of the current path is D, and each node on the path has at most B siblings. Therefore, the space complexity is big O of B multiplied by D. This is linear in D, the depth of the shallowest goal node. The space complexity is similar to DFS. What about time complexity? In the worst case, IDS will visit all the nodes in the top D levels. Therefore, IDS time complexity is similar to that of BFS. The number of nodes up to depth D is dominated by the number of nodes at depth D, which is B to the power of D. So IDS time complexity is big O of B to the power of D. This is exponential in D, the depth of the shallowest goal node. The asymptotic time complexity of IDS is the same as that of BFS. However, if we calculate the exact number of nodes visited, the number for IDS is larger than that of BFS. The reason is that IDS performs some repeated computation. Every time IDS increases a depth limit, it performs DFS from scratch. This means that when IDS terminates at depth D, it visited level D one time, level D minus one two times, level D minus two three times, and so on. The total number of nodes visited by BFS is roughly B to the power of D multiplied by B over B minus one. And the total number of nodes visited by IDS is approximately B to the power of D multiplied by B over B minus one squared. The difference is a multiplicative factor of B over B minus one. This factor is largest when B is small. As B becomes larger, the factor becomes close to one. Let's look at completeness. Is IDS guaranteed to find the solution if one exists? The answer is yes. Since IDS only performs DFS until a depth limit, it won't follow an infinite path forever. Therefore, it doesn't have the same problem as DFS. IDS is complete and is guaranteed to find the solution if one exists. Finally, let's look at optimality. Similar to other uninformed search algorithms, IDS does not pay any attention to the edge costs. Therefore, it makes no guarantee on the quality of the solution found. However, since IDS increases the depth limit by one each time, it can achieve the same weaker property as BFS. IDS is guaranteed to find the shallowest gold node. If every edge has the same cost, IDS is guaranteed to return the optimal solution. Here's a recap of the IDS properties. IDS is an amazing example of a win-win situation. Similar to DFS, IDS requires linear space only. Similar to BFS, IDS is complete and is guaranteed to find the shallowest gold node. IDS also has the same time complexity as BFS, although the exact number of nodes visited by IDS is slightly larger than that of BFS. That's everything on the iterative deepening search algorithm. Let me summarize. After watching this video, you should be able to do the following. Explain the motivation for IDS. Trace IDS on a search graph. Describe the properties of IDS, including space complexity, time complexity, completeness, and optimality. Thank you very much for watching. I will see you in the next video. Bye for now.