 Hello everyone, this is Alice Gao. In this video, I'm going to discuss the breadth-first search algorithm. Recall the generic search algorithm. Our strategy for selecting and removing a path from the frontier determines the search algorithm. Breath-first search treats a frontier as a queue. A queue is first seen, first out. Imagine a line up at the ticket office. We add items to the queue on one end and remove items at the other end. If the frontier is a queue, we remove the oldest node added to the frontier at each step. Let's trace BFS on a search graph. We will add nodes to the frontier in alphabetical order. Pause the video and trace the algorithm yourself. Then, keep watching. This is the final search tree when BFS terminates. I will describe the tracing process in a separate video. BFS explores the search tree level by level. When BFS terminates, we found the shallowest goal node in the search tree. In other words, the path we found has the fewest edges to any goal node among all possible solutions. Let me discuss the properties of BFS. Space complexity, time complexity, completeness, and optimality. When characterizing the complexities, I will make use of the three useful quantities. B is the branching factor, M is the maximum depth of the search tree, and D is the depth of the shallowest goal node. Let's look at space complexity. What is the size of the frontier for BFS in the worst case? Since BFS explores the tree level by level, it will terminate at depth D, where D is the depth of the shallowest goal node. The size of the frontier is at most the size of level D. How many nodes are there at depth D? At level 0, we have one node. At level 1, we have at most B nodes. At level 2, they are at most B square nodes. At level D, we have at most B to the power of D nodes. Therefore, the space complexity is big O of B to the power of D. This is exponential in D, the depth of the shallowest goal node. What about time complexity? How many nodes does BFS need to visit in the worst case? In the worst case, BFS will visit all the nodes up to and including depth D, and terminates at depth D. Therefore, the time complexity is dominated by the size of level D. The total number of nodes at level D is B to the power of D. So, the time complexity is big O of B to the power of D. This is exponential in D. So far, the complexities of BFS are not great. Both space and time complexities are exponential. However, these complexities are not surprising, since the total number of nodes in the search tree is exponential. What about completeness? Is BFS guaranteed to find a solution if a solution exists? Unlike DFS, BFS won't follow an infinite path forever. BFS explores the nodes level by level and will terminate when it finds the shallowest goal node. If a solution exists at a finite depth and if the branching factor is finite, then BFS is guaranteed to find the solution. Finally, let's look at optimality. If BFS terminates on a problem, is it guaranteed to return the optimal solution? Unfortunately, the answer is no. BFS pays no attention to the edge costs. Therefore, it doesn't have any guarantee on the total cost of the path returned. However, we can achieve a slightly weaker property. BFS is guaranteed to find the shallowest goal node since it explores the search tree level by level. In a special case, when every edge has the same cost, the solution returned by BFS is the optimal solution. That's everything on the breadth-first search algorithm. Let me summarize. After watching this video, you should be able to do the following. Explain BFS at a high level. Trace BFS on a search graph. Describe properties of BFS, 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.