ALGORITHM: BREADTH-FIRST SEARCH
1. Create a variable called NODE-LIST and set it to the initial state. 2. Loop until the goal state is found or NODE-LIST is empty. a. Remove the first element, say E, from the NODE-LIST. If NODE-LIST was empty then quit. b. For each way that each rule can match the state described in E do:
i) Apply the rule to generate a new state. ii) If the new state is the goal state, quit and return this state. iii) Otherwise add this state to the end of NODE-LIST
Since it never generates a node in the tree until all the nodes at shallower levels have been generated, breadth-first search always finds a shortest path to a goal. Since each node can be generated in constant time, the amount of time used by Breadth first search is proportional to the number of nodes generated, which is a function of the branching factor b and the solution d. Since the number of nodes at level d is bd, the total number of nodes generated in the worst case is b + b2 + b3 +… + bd i.e. O(bd) , the asymptotic time complexity of breadth first search.
Breadth First Search
Look at the above tree with nodes starting from root node, R at the first level, A and B at the second level and C, D, E and F at the third level. If we want to search for node E then BFS will search level by level. First it will check if E exists at the root. Then it will check nodes at the