 Hello everyone, this is Alice Gao. In this video, I will discuss two strategies for pruning the search space. Cycle pruning and multiple path pruning. Let's look at cycle pruning. First, what is cycle pruning? Cycle pruning means that whenever we detect that we're following a cycle, we stop following the path and discard it. There are several reasons for performing cycle pruning. First, a cycle may cause an algorithm to not terminate. For instance, depth first search will get trapped in the cycle forever. Moreover, exploring a cycle is a waste of time, since a cycle cannot be part of a solution. How do we perform cycle pruning? Let's take a look at the pseudocode. The important part is highlighted in blue. When we generate the current node's successor, we will check whether the successor is on the current path or not. If the successor is on the current path, it is part of a cycle, and we do not add the successor to the frontier. Next, what is the complexity of cycle pruning? To check whether the new node is in a cycle, we can check whether it's on the current path or not. In the worst case, we need to go through all the nodes on the path. This is going to take time that's linear in the length of the path. Most search algorithms need to store multiple paths on the frontier, so linear time is the best that we can achieve for these algorithms. Breath first search is one example of such algorithms. However, for depth first search, we can do better. DFS only remembers one path at a time. We can store all the nodes on the current path in the hash map. Then checking whether a node is in the hash map requires constant time. Another way to implement cycle pruning for DFS is to add a Boolean flag to each node. The flag is true if the node is on the current path and false otherwise. When we generate a new node, the flag tells us whether the new node is on the current path or not. Next, let's look at the second pruning strategy, multiple path pruning. Why do we want to use multi-path pruning? When solving a search problem, we only need to find one path to any node. Once we found a path to a node, we can discard all other paths to the same node. This is called multi-path pruning. What is the relationship between cycle pruning and multi-path pruning? This is an interesting question. Pause the video and think about this for a minute. Then keep watching. You may have realized that cycle pruning is a special case of multi-path pruning. Following a cycle is one way to have multiple paths to the same node. So pruning a cycle is one example of pruning multiple paths to the same node. Next, how do we perform multi-path pruning? Let's take a look at the pseudocode. Our goal is to keep only one path to a given node at any time. We will create an explored set to store all the visited nodes. After removing a path from the frontier, we will take nsubk, which is the last node on the path, and check whether nsubk is in the explore set or not. If nsubk was visited, we will do nothing. Otherwise, we will add nsubk to the explore set and expand the node, which means performing the goal test and adding its successors to the frontier. In practice, the explore set can become extremely large. It often contains an exponential number of nodes. Because of this, it's crucial to ensure that the data structure for the explore set allows for efficient lookups. For example, a hash map is a great choice. That's everything on the two pruning strategies. Let me summarize. After watching this video, you should be able to do the following. Describe the two pruning strategies, cycle pruning and multipath pruning. Why do we want to use them? How do we perform these pruning? What is the complexity of each pruning strategy? Thank you very much for watching. I will see you in the next video. Bye for now.