CS 611 Slides 2
CS 611 Slides 2
CS 611 Slides 2
INTELLIGENCE
• Space Complexity- this denotes the maximum amount of space that is required at
any particular point during the search.
Types of Search Algorithms
• Each node of the tree is examined until the goal node is found.
Types of Uninformed Search Strategies
• Breadth-first Search
• Depth-first Search
• Bidirectional Search
Breadth-first Search
• This is a common strategy used for traversing trees and graphs. The search in
this algorithm follows a breadth-wise approach, hence, it is known as the
breadth-first search.
• The algorithm begins the search process from the root node of the tree and
then expands the successor node at the current level before it can move to
the nodes at the next level.
• To implement this algorithm, we use the FIFO (First In First Out) queue data
structure.
Advantages and Disadvantages of BFS
Advantages:
Disadvantages:
1. Visited
2. Not Visited
• The purpose of the algorithm is to mark each vertex as visited while avoiding cycles.
1. Start by putting any one of the graph's vertices at the back of a queue.
2. Take the front item of the queue and add it to the visited list.
3. Create a list of that vertex's adjacent nodes. Add the ones which aren't in the visited list to the back of
the queue.
• The graph might have two different disconnected parts so to make sure that we cover every vertex, we can also run
the BFS algorithm on every node
BFS Example
• Let's see how the Breadth First
Search algorithm works with an
example. We use an undirected
graph with 5 vertices.
# BFS algorithm
def bfs(graph, root):
while queue:
if __name__ == '__main__':
graph = {0: [1, 2], 1: [2], 2: [3], 3: [1, 2]}
print("Following is Breadth First Traversal: ")
bfs(graph, 0)
BFS Algorithm Complexity BFS Algorithm Applications
• The major goal of this type of search is to find that leads from the root node to the goal node with
the lowest cumulative cost.
• The uniform-cost search expands the nodes based on the path cost from the root node. This type
of search can be used to solve any tree/graph where there is a demand for optimal cost.
• The uniform-cost search algorithm is implemented using the priority queue data structure. The
lowest cumulative cost is given a priority. If all edges have similar path costs, the uniform-cost
search becomes the same as BFS.
• The major advantage associated with the uniform-cost search algorithm is that it is optimal as the
least cost path is chosen at every state.
• The major disadvantage associated with this type of search is that it doesn’t care about the number
of steps involved in the search, but it is only interested in the path costs. This may lead the
algorithm to an infinite path.
Example of Uniform Cost Search
• Consider the below example, where we
need to reach any one of the destination
node{G1, G2, G3} starting from node S.
Node{A, B, C, D, E and F} are the
intermediate nodes. Our motive is to find
the path from S to any of the destination
state with the least cumulative cost.
Each directed edge represents the
direction of movement allowed through
that path, and its labelling represents the
cost is one travels through that path.
Thus Overall cost of the path is a sum of
all the paths.
S->A->G1
S->D->C->G2
S->D->C->F
S->D->E->G3
• Minimum is S->D->C->G2
• It helps to find the path with the • The open list is required to be
lowest cumulative cost inside a kept sorted as priorities in priority
weighted graph having a different queue needs to be maintained.
• This means that informed search strategies are able to find the solution more
efficiently compared to the uninformed search strategies.
• A heuristic refers to a way that may not always guarantee to find the best
solutions but it guarantees to find a good solution within a good time.
• With an informed search, one can solve a complex problem that cannot be solved
in any other way.
• The best-first search helps us combine the benefits of BFS and DFS
algorithms.
• The BFS helps us choose the most promising node at every step. We expand
the node that is very close to the goal node and the heuristic function is used
to estimate the closest cost.
• To implement the greedy best first search, we use the priority queue.
Advantages and Disadvantages of Greedy Search Algorithm
Advantages Disadvantages
• The algorithm can enjoy the • In the worst case scenario, this
benefits of both BFS and DFS algorithm may act line an
algorithms.
unguided depth-first search.
• It relies on the cost and a heuristic function h(n) to reach the goal node n from the
start state g(n).
• It combines the features of a greedy best- first search and UCS, making it
possible to solve problems more efficiently.
• The A* search uses a heuristic function to find the shortest path through the
search space.
• The algorithm is known to expand a less search tree and it provides an optimal
solution faster.
• In A*, we use both the search heuristic and the cost in order to reach the goal
node.
Advantages and Disadvantages of A* Search Algorithm
Advantages Disadvantages