Search Algorithms Part 1
Search Algorithms Part 1
Search Part I
Created @October 14, 2024 8:42 PM
Tags
Examples:
Components:
Agent Types:
1. Search Part I 1
Actions: Possible moves or choices from a given state.
Search Strategies
3. Uniform-Cost Search: Expands nodes with the lowest cost; suitable for
weighted graphs.
2. A* Search: Combines path cost and heuristic to find the most promising node.
Adversarial Search
Competitive Environments: Used in games like chess.
Types:
1. Search Part I 2
Supervised Learning: Uses labeled data (e.g., spam detection).
Neural Networks: Models inspired by the brain; used in deep learning for
complex tasks.
Search Algorithms
Key Components of a Search Problem
1. Initial State:
2. Actions:
The possible moves or decisions the agent can make from a given state.
Function: ACTIONS(s) : Returns the set of actions that can be executed from
state( s ).
1. Search Part I 3
Example: In a maze, possible actions might be "move up," "move down,"
"move left," and "move right."
3. Transition Model:
4. Goal Test:
A numerical cost associated with the path from the initial state to the
current state.
Example: In a weighted graph, the cost could represent the distance, time,
or resources needed to traverse from one node to another.
State Space
State Space:
The set of all states reachable from the initial state through any sequence
of actions.
Example: In a chess game, the state space consists of all possible board
configurations.
Solution:
A sequence of actions that leads from the initial state to the goal state.
Optimal Solution:
1. Search Part I 4
The solution with the lowest path cost among all possible solutions.
Example: The shortest path in a navigation app that minimizes travel time.
Search Approaches
Data Structure:
Goal:
Example:
Code:
import sys
graph = {
'1': ['2', '3'],
'2': ['4'],
'3': ['5'],
'4': ['5'],
'5': ['3', '4']
}
visited = []
queue = []
1. Search Part I 5
visited.append(node)
queue.append(node)
while queue:
currentNode = queue.pop(0)
print (currentNode, end = " ")
Can go down one path until it reaches a dead end, then backtrack.
Data Structure:
Potential Issues:
Can get stuck in deep branches (infinite loops) unless modified with
checks to avoid revisiting nodes.
Example:
Code:
import sys
graph = {
'1': ['2', '3'],
'2': ['4'],
1. Search Part I 6
'3': ['5'],
'4': ['5'],
'5': ['3', '4']
}
visited2 = set()
Explored Set: A record of nodes that have already been expanded to avoid
revisiting them.
Revised Approach:
Include an explored set to track expanded nodes.
1. Search Part I 7
2. Only add new nodes to the frontier if they are not in the explored set or the
frontier.
Optimization Concepts
Weighted Graphs:
Nodes and edges have associated weights or costs.
Path Cost: The sum of weights along a path from the initial state to the goal.
Optimal Solution:
A solution with the lowest path cost among all possible solutions.
1. Search Part I 8