There are multiple graph search algorithms we can use to search for elements in a graph, these do not consider any information we may have about the graph.
Properties of Algorithms
- Completeness: is the algorithm guaranteed to find a solution when there is one
- Optimality: does the algorithm find the optimal solution
- Time complexity: how long does it take to find a solution
- Space complexity: how much memory is needed to perform the search
Uninformed Search Algorithms
Breadth First Search
It is:
- Complete
- Optimal if all actions have the same cost
- Complexity is measured based on a branching factor , If the goal is at level then the number of nodes is . This means the time and space complexity is exponential.
Breadth First Search (Algorithm)
:
Link to original
- Select root vertex and add to a Queue (ADT)
- While queue is not empty:
- Inspect first element in queue
- Add unvisited neighbours of to queue
- Remove from queue
Depth First Search
Depth First Search (Algorithm)
:
Link to original
- Select root vertex and add to a Stack (ADT)
- While stack is not-empty:
- Inspect top element on the stack
- Add any unvisited neighbours of to the stack
- Remove from the stack
Bidirectional Search
Bidirectional Search is when we search from the initial and goal state at the same time and meet somewhere in the middle.