Home Robotics C++ Physics II AP Physics B Electronics AP Java Astronomy Independent Study Summer Session Contests  About
                                                       

Pseudocode and Algorithms

Previously, we looked at how to solve search problems by hand. Now, it's time for the next step. It is time to help your computer to solve the search problems also.

 

Pseudocode / Informal Algorithms


Now that you have a good idea on how to solve these various search problems, you need to translate them so that a computer can solve it. Before we get into the code, let's solve it generally using pseudocode.


Depth First Search
The pseudocode for depth first search based on what we did earlier is:

  1. Declare two empty lists: Open and Closed.

  2. Add Start node to our Open list.

  3. While our Open list is not empty, loop the following:
     

    1. Remove the first node from our Open List.

    2. Check to see if the removed node is our destination.
       

      1. If the removed node is our destination, break out of the loop, add the node to our Closed list,  and return the value of our Closed list.

      2. If the removed node is not our destination, continue the loop (go to Step c).

    3. Extract the neighbors of our above removed node.

    4. Add the neighbors to the beginning of our Open list, and add the removed node to our Closed list. Continue looping.


Breadth First Search


The pseudocode for breadth first first search is similar to the above and similar to what we did earlier:

  1. Declare two empty lists: Open and Closed.

  2. Add Start node to our Open list.

  3. While our Open list is not empty, loop the following:
     

    1. Remove the first node from our Open List.

    2. Check to see if the removed node is our destination.
       

      1. If the removed node is our destination, break out of the loop, add the node to our Closed list,  and return the value of our Closed list.

      2. If the removed node is not our destination, continue the loop (go to Step c).

    3. Extract the neighbors of our above removed node.

    4. Add the neighbors to the end of our Open list, and add the removed node to our Closed list.