Preview

Breath First Search

Satisfactory Essays
Open Document
Open Document
538 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Breath First Search
readth First Search (BFS) searches breadth-wise in the problem space. Breadth-First search is like traversing a tree where each node is a state which may a be a potential candidate for solution. Breadth first search expands nodes from the root of the tree and then generates one level of the tree at a time until a solution is found. It is very easily implemented by maintaining a queue of nodes. Initially the queue contains just the root. In each iteration, node at the head of the queue is removed and then expanded. The generated child nodes are then added to the tail of the queue.
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

You May Also Find These Documents Helpful

  • Powerful Essays

    13. Which one of the following OSPF neighbor states is the expected state after completion of the…

    • 901 Words
    • 3 Pages
    Powerful Essays
  • Good Essays

    Problem Set 1 302 2014T1

    • 1095 Words
    • 5 Pages

    (e) Let’s say you had to guess to answer to (d) based on the results in (b), (c) without…

    • 1095 Words
    • 5 Pages
    Good Essays
  • Satisfactory Essays

    For each question, mark tbe appropriate response (a), (b), (c), or (d). There is only one correct response to each question in Part A.…

    • 472 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Nt1330 Unit 7

    • 465 Words
    • 2 Pages

    1. c 2. c 3. a 4. d 5. a 6. c 7. a 8. b 9. d 10. d…

    • 465 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    Mis Decison Tree

    • 366 Words
    • 2 Pages

    Start at the top of the decision tree (with the 3-way splits) and work your way downward to answer the following questions (you don’t need to include screen shots for these questions – just provide the answer):…

    • 366 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    I. To find if there is any root to leaf path with specified sum in a binary tree.…

    • 359 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    Search

    • 1165 Words
    • 4 Pages

    Mark Chan had spent the past six years working overseas and Mark’s past international experience helped him to get the job at Energem, a diversified, global company with market-leading positions in a number of industries. Headquartered in the UK. By the end of his third year at Energem Mark was offered a three-year international assignment opportunity at the corporate headquarters in London. The job was another promotion and he would now be part of the company’s senior management. This was a great opportunity and with the expatriate benefits package and Mark’s wife Linda would not have to work and could stay at home with their two children who were still very young. She could always go back to work as a private banker when they returned to Singapore. This assignment would be a big stepping stone for Mark’s career when he returned.…

    • 1165 Words
    • 4 Pages
    Powerful Essays
  • Good Essays

    Algorithms Test

    • 640 Words
    • 3 Pages

    Depth-first search is best-first search with f(n) = −depth(n); breadth-first search is best-first search with f(n) = depth(n);…

    • 640 Words
    • 3 Pages
    Good Essays
  • Better Essays

    A fascinating and important balanced binary search tree is the red-black tree. Rudolf Bayer invented this important tree structure in 1972, about 10 years after the introduction of AVL trees. Bayer referred to his red-black trees as “symmetric binary B-trees.”…

    • 2558 Words
    • 11 Pages
    Better Essays
  • Good Essays

    Problem Solving in Ai

    • 2523 Words
    • 11 Pages

    * Position 8 queens on a chessboard so that no queen attacks any other queen…

    • 2523 Words
    • 11 Pages
    Good Essays
  • Good Essays

    In the previous post, we discussed how asymptotic analysis overcomes the problems of naive way of analyzing algorithms. In this post, we will take an example of Linear Search and analyze it using asymptotic analysis.…

    • 688 Words
    • 3 Pages
    Good Essays
  • Powerful Essays

    network. Sometimes this computation has to be done in real time. For the sake of…

    • 2144 Words
    • 9 Pages
    Powerful Essays
  • Good Essays

    Today, top search engines like Google and Yahoo use a data structure called Inverted Index for their matching of queries to the documents and give users the relevant documents according to their rank. Inverted Index is basically a mapping from a word to its position of occurence in the document. Since a word may appear more than once in the document, storing all the positions and the frequency of a word in the document gives an idea of relevance of this document for a particular word. If such an inverted index is build up for each document in the collection, then when a query is fired, a search can be done for the query in these indexes and ranking is obtained according to the frequency. Mathematically, an inverted index for a document D and strings s1 , s2 , ..., sn is of the form s1 − > a1 , a1 , ... 1 2 s2 − > a2 , a2 , ... 1 2 . . . sn − > an , an , ... 2 1 where ak denotes the lth position of k th word in the document D. l To build up this kind of data structure efficiently, Tries are used. Tries are a good data structure for strings as searching becomes very simple here with every leaf node describing one word. To build up an inverted index given a set of documents using trie, following steps are followed • Traverse one document and insert words into a trie. As a leaf node is reached, assign it a number (in increasing order) representing its location in the index (staring from 0). Add the position of this word into the index. • Now for a word which occur more than once in the document, when attempt for second insertion into the trie is made, a leaf node already containing that word would be found and its value would tell the location in the index. So simply go to this index and add another position for this word. • Do this till end of document is reached. Now, you have a trie and an inverted index for the first document. • Repeat this procedure for the rest of the documents. 1…

    • 879 Words
    • 4 Pages
    Good Essays
  • Good Essays

    Binary Search Trees (BSTs) Def. A BINARY SEARCH TREE is a binary tree in symmetric order. it A binary tree is either: empty a key-value pair and two binary trees [neither of which contain that key]…

    • 2419 Words
    • 10 Pages
    Good Essays
  • Good Essays

    Search

    • 755 Words
    • 4 Pages

    If you love what you do and do what you love; every man would find his life a joyful encounter and thus would agree to what Helen Hayes says, ‘if we rest, we rust’.…

    • 755 Words
    • 4 Pages
    Good Essays