 Hello everyone, this is Alice Gao. In this video, I will discuss how to take a real-world problem and formulate it as a search problem. When is it a good idea to use search? We often use search algorithms to solve challenging problems. A problem is challenging when it is easy to recognize a solution, but there is no efficient algorithm to derive a solution. An example is NP-hard problems. A search algorithm mimics how we solve a complex problem in real life. For example, to solve a sliding puzzle, we can keep moving the pieces in different ways until we reach the goal state. Doing this is similar to executing a search algorithm, except that we are using it in a trial and error manner. Executing a search algorithm will allow us to explore all the paths systematically. Let me describe the components of a search problem using this search graph. Each node represents a state. S is the initial state, and G is the goal state. A search problem may have multiple goal states. One option is to list all the goal states. Another option is to define a goal test, a boolean function that takes a state and returns true if and only if the state is a goal state. The directed edges represent the successor or the neighbor relationships. If there is a directed edge from X to Y, then Y is the successor or neighbor of X. For example, the initial state S has three successors, D, E, and P. You can also consider the directed edges as actions. For instance, taking an action allows us to move from S to D. For some search problems, the directed edges may have costs associated with them. In this course, we assume that the costs are non-negative. If we don't care about costs, then our goal is to find any path from the initial state to any goal state. Otherwise, if the directed edges have costs, our goal may be to find the shortest path with the smallest total cost. Let's look at the 8-puzzle as an example. In an 8-puzzle, a 3x3 grid has a numbers 1 to 8. Starting from the initial state on the left, we want to move the tiles horizontally or vertically until the board is the same as the goal state on the right. Let's define the 8-puzzle as a search problem. Pause the video and fill in the definitions yourself. Then, keep watching. First, we need to define a state. A state must contain enough information so that we can distinguish two different states before and after moving a piece. We can verify whether a state is a goal state or not. We can generate the successors of a state efficiently. For the 8-puzzle, it's critical to remember the order of the numbers. Let's use 0 to denote the empty square. Each state contains 9 numbers. We will write down the numbers line by line from top to bottom. For each line, we'll write down the 3 numbers from left to right. Given the state definition, the initial state is 530876241 and the goal state is 123456780. Next, let's define a successor function. To change a state, we need to move a piece adjacent to the empty square to the empty square. For the initial state, we can move 3 or 6 to the empty square. There are many ways to describe the successor function. Here's one possibility. Let's consider the empty square to be a tile. If state B is the successor of state A, we can convert state A to state B by moving the empty tile up or down or left or right by one step. What about the cost function? For the 8-puzzle, our goal is to find the path from the initial state to the goal state. We may want to minimize the number of moves. There is no sense of one move being more expensive than another one, so we can define every move or every directed edge to have a cost of 1. Take a look at the complete search formulation for the 8-puzzle. To check that you understood the successor function, here's a practice question for you. Which option is the successor of the initial state? Pause the video and derive an answer yourself. Then keep watching. I highly recommend that you derive the answer yourself before checking the solutions. You will learn the most if you attempt to question yourself first. The correct answer is B. We can derive this successor by moving 6 upward. To answer this question, we can draw the state as a 3x3 grid. Draw the grids for the successors, and then write each of its successors as a 9-digit string. The state in the question is the initial state. The empty square has two adjacent tiles, 3 and 6, so it has two successors. Take a look at the grids and the 9-digit strings for the two successors. For a given problem, there are often multiple ways of formulating it as a search problem. Choosing a suitable formulation is crucial, since it may affect how efficiently we can find a solution. When constructing a search graph, we can create nodes using the state definition, and we can create directed edges using the successor function. Ideally, we want to choose a state definition that minimizes the number of nodes in the graph. Doing this reduces the number of nodes we need to explore in the worst case. We also want to choose the successor function such that the graph has fewer edges if possible. Moreover, the state definition and the successor function will affect each other. Choosing one state definition may make it easier or harder to implement the successor function. Consider the eight puzzle again. An alternative way of defining a state is to keep track of each tiles x and y coordinates. We will have eight coordinates, one for each of the eight tiles. Given the state definition, how would you implement the successor function? Which state definition makes it easier to implement the successor function? I will leave this as a thought question for you. That's everything on formulating a search problem. Let me summarize. After watching this video, you should be able to do the following. Explain why we want to use the search algorithm to solve a problem. Describe components of a search problem. Formulate a real-world problem as a search problem. Thank you very much for watching. I will see you in the next video. Bye for now.