0% found this document useful (0 votes)
7 views

What is a Search Algorithm.docx

A search algorithm is a method for navigating through a search space to find optimal solutions for problems, playing a vital role in AI applications such as GPS navigation, search engines, e-commerce, and social media. There are two main types of search algorithms: uninformed (blind) and informed (heuristic), with examples including Breadth-First Search (BFS) and Depth-First Search (DFS). These algorithms enhance efficiency in information retrieval, database systems, and problem-solving tasks.

Uploaded by

utkarshm025
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

What is a Search Algorithm.docx

A search algorithm is a method for navigating through a search space to find optimal solutions for problems, playing a vital role in AI applications such as GPS navigation, search engines, e-commerce, and social media. There are two main types of search algorithms: uninformed (blind) and informed (heuristic), with examples including Breadth-First Search (BFS) and Depth-First Search (DFS). These algorithms enhance efficiency in information retrieval, database systems, and problem-solving tasks.

Uploaded by

utkarshm025
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

What is a Search Algorithm?

A search algorithm is a method used to navigate through a set of possible solutions


(known as the search space) to find the best or most optimal solution for a given
problem. These algorithms are crucial in AI for tasks like pathfinding,
decision-making, and problem-solving
GPS Navigation Systems
When you use a GPS app to find the shortest route to your destination, it employs
search algorithms like A* to calculate the optimal path based on distance and traffic
conditions1.
2. Search Engines
Google Search uses complex search algorithms to quickly find the most relevant
web pages based on your query. These algorithms consider factors like keyword
relevance, page rank, and user behavior2.
3. Online Shopping
E-commerce platforms like Amazon use search algorithms to help you find
products. These algorithms consider your search terms, past purchases, and
browsing history to recommend items2.
4. Social Media Feeds
Platforms like Facebook and Instagram use search algorithms to curate your
feed. These algorithms prioritize posts based on your interactions, likes, and the
popularity of the content2.

Search algorithms play a crucial role in computer science and various applications
by efficiently locating specific items within a collection of data. Here are some key
roles and applications of search algorithms:

1.​ Information Retrieval: Search engines like Google and Bing use sophisticated
search algorithms to retrieve relevant information from vast amounts of data on the
web1.

2.​ Database Systems: Search algorithms are fundamental in database systems for
quickly querying and retrieving specific data records based on user queries1.

3.​ Efficiency: Efficient search algorithms improve program performance by reducing


the time and resources needed to find data1.
4.​ Problem Solving: They are used in a wide range of problem-solving tasks, such as
finding the shortest path in a graph or locating a specific element in a data structure1.

5.​ SEO (Search Engine Optimization): In SEO, search algorithms determine how
search engines rank and display relevant information against user queries, improving
website visibility on search engine result pages (SERPs)2.
Types of search algorithm:

Uninformed Searching
Informed Searching

Uninformed Searching Informed Searching


Uninformed search algorithms, also Informed search algorithms, also known
known as blind search algorithms, do as heuristic search algorithms, use
not have any additional information additional information (heuristics) to
about the goal state beyond the problem guide the search process. This
definition. They explore the search information helps estimate how close a
space systematically but without state is to the goal state, making the
guidance on which path might be more search more efficient.
promising
Search without information Search with Information
No Knowledge Use knowledge to find steps to solution

Time consuming Quick solution


More complexity Less complexity

BFS,DFS ETC A*, Heuristic, BFS, Greedy etc

Real life example: Navigating a maze Real life example: GPS navigation
without any clues about the exit systems using real-time traffic data to
location. find the fastest route.

Breadth-First Search (BFS)


BFS explores all nodes at the present depth level before moving on to nodes at the
next depth level. It uses a queue data structure to keep track of the nodes to be
explored.

Breadth-First Search (BFS) Algorithm Using G(V, E)

Input: A graph G(V,E) a starting vertex s, and an optional goal vertex g.

Output: The BFS traversal of the graph or the path to the goal vertex g if specified.
Algorithm:

1.​ Initialize:
o​ Create a queue Q.
o​ Enqueue the starting vertex s into Q.
o​ Mark s as visited.
2.​ While Q is not empty:

0.​ Dequeue a vertex u from Q.


1.​ For each vertex v adjacent to u in G(V,E)
▪​ If v is not visited:
▪​ Mark v as visited.
▪​ Enqueue v into Q.
2.​ If u=g (goal vertex) then:
▪​ Return the path from s to g.
▪​ (Optional) Stop the search.
2.​ End While
3.​ If no goal vertex is specified, return the BFS traversal order.

Steps:

1.​ Start at the root node (or initial state).


2.​ Enqueue the root node.
3.​ While the queue is not empty:
o​ Dequeue a node from the front of the queue.
o​ If this node is the goal, return the path.
o​ Otherwise, enqueue all its adjacent (or child) nodes that haven’t been visited yet.

Example: Consider a simple graph:


A
/ \
B C
/ \ \
D E F

●​ Start at node A.(root node)


●​ Enqueue A. Queue: [A]
●​ Dequeue A, enqueue B and C. Queue: [B, C]
●​ Dequeue B, enqueue D and E. Queue: [C, D, E]
●​ Dequeue C, enqueue F. Queue: [D, E, F]
●​ Continue this process until the goal node is found.

Example to find E(as goal node).


A

/ \

B C

/ \ \

D E F

Example:

●​ Start at node A.
●​ Enqueue A. Queue: [A]
●​ Dequeue A, enqueue B and C. Queue: [B, C]
●​ Dequeue B, enqueue D and E. Queue: [C, D, E]
●​ Dequeue C, enqueue F. Queue: [D, E, F]
●​ Dequeue D. Queue: [E, F]
●​ Dequeue E (goal node found).

Path to E: A -> B -> E


Guided Path is: A->B->C->D->E

Depth-First Search (DFS)


DFS explores as far as possible along each branch before backtracking. It uses a
stack data structure (or recursion) to keep track of the nodes to be explored.

Depth-First Search (DFS) Algorithm Using G(V, E)

Input: A graph G(V,E) a starting vertex s, and an optional goal vertex g.

Output: The DFS traversal of the graph or the path to the goal vertex g if specified.

Algorithm:

1.​ Initialize:
o​ Create an empty stack S.
o​ Push the starting vertex s onto S.
o​ Mark s as visited.
2.​ While S is not empty:

0.​ Pop a vertex u from S.


1.​ For each vertex v adjacent to u in G(V,E):
▪​ If v is not visited:
▪​ Mark v as visited.
▪​ Push v onto S.
2.​ If u=g (goal vertex) then:
▪​ Return the path from s to g.
▪​ (Optional) Stop the search.
2.​ End While
3.​ If no goal vertex is specified, return the DFS traversal order.

Steps:

1.​ Start at the root node (or initial state).


2.​ Push the root node onto the stack.
3.​ While the stack is not empty:
o​ Pop a node from the top of the stack.
o​ If this node is the goal, return the path.
o​ Otherwise, push all its adjacent (or child) nodes that haven’t been visited yet onto
the stack.

Example: Using the same graph:


A
/ \
B C
/ \ \
D E F

●​ Start at node A.
●​ Push A. Stack: [A]
●​ Pop A, push B and C. Stack: [C, B]
●​ Pop B, push D and E. Stack: [C, E, D]
●​ Pop D. Stack: [C, E]
●​ Continue this process until the goal node is found.

Example:
A
/ \
B C
/ \ \
D E F

Where E is a Goal node.

●​ Start at node A.
●​ Push A. Stack: [A]
●​ Pop A, push B and C. Stack: [C, B]
●​ Pop B, push D and E. Stack: [C, E, D]
●​ Pop D. Stack: [C, E]
●​ Pop E (goal node found).

Path to E: A -> B -> E


Guided Path is: A->B->D->E

You might also like