You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description: 'Search algorithms are a class of algorithms used to find an optimal solution to a problem by exploring a search space.'
3
+
Description: 'Search algorithms are a class of algorithms used to explore a search space to find a solution, often with the goal of finding an optimal one.'
A **search algorithm** is a type of algorithm used in artificial intelligence to find the best or most optimal solution to a problem by exploring a set of possible solutions, also called a search space. A search algorithm filters through a large number of possibilities to find a solution that works best for a given set of constraints.
17
+
A **search algorithm** is a type of [algorithm](https://www.codecademy.com/resources/docs/general/algorithm) used in artificial intelligence (AI) to find the best or most optimal solution to a problem by exploring a set of possible solutions, also called a search space. A search algorithm filters through a large number of possibilities to find a solution that works best for a given set of constraints.
17
18
18
-
Search algorithms typically operate by organizing the search space into a particular type of graph, commonly a tree, and evaluate the best score, or cost, of traversing each branch of the tree. A solution is a path from the start state to the goal state that optimizes the cost given the parameters of the implemented algorithm.
19
+
Search algorithms typically operate by organizing the search space into a particular type of [graph](https://www.codecademy.com/resources/docs/general/graphs), commonly a tree, and evaluate the best score, or cost, of traversing each branch of the tree. A solution is a path from the start state to the goal state that optimizes the cost given the parameters of the implemented algorithm.
19
20
20
-
Search algorithms are typically organized into two categories:
21
+
## Types of Search Algorithms
21
22
22
-
- Uninformed Search: Algorithms that are general purpose traversals of the state space or search tree without any information about how good a state is. These are also referred to as blind search algorithms.
23
+
Search algorithms are typically organized into two categories:
23
24
24
-
- Informed Search: Algorithms that have information about the goal during the traversal, allowing the search to prioritize its expansion toward the goal state instead of exploring directions that may yield a favorable cost but don't lead to the goal, or global optimum. By including extra rules that aid in estimating the location of the goal (known as heuristics) informed search algorithms can be more computationally efficient when searching for a path to the goal state.
25
+
-**Uninformed/Blind Search**: Algorithms that are general purpose traversals of the state space or search tree without any information about how good a state is.
26
+
-**Informed/Heuristic Search**: Algorithms that have information about the goal during the traversal, allowing the search to prioritize its expansion toward the goal state instead of exploring directions that may yield a favorable cost but don't lead to the goal, or global optimum.
25
27
26
-
## Types of Search Algorithms
28
+
## Uninformed/Blind Search Algorithms
27
29
28
-
There are many types of search algorithms used in artificial intelligence, each with their own strengths and weaknesses. Some of the most common types of search algorithms include:
30
+
Let's go through the different types of uninformed/blind search algorithms one-by-one.
29
31
30
32
### Depth-First Search (DFS)
31
33
@@ -39,24 +41,63 @@ This algorithm explores all the neighbor nodes at the current level before movin
39
41
40
42
This algorithm expands the lowest cumulative cost from the start, continuing to explore all possible paths in order of increasing cost. UCS is guaranteed to find the optimal path between the start and goal nodes, as long as the cost of each edge is non-negative. However, it can be computationally expensive when exploring a large search space, as it explores all possible paths in order of increasing cost.
41
43
42
-
### Heuristic Search
44
+
### Depth-Limited and Iterative Deepening Search
45
+
46
+
These are variations of DFS that limit exploration depth. Depth-limited search restricts how deep the search can go, while iterative deepening search repeatedly increases the depth limit. This balances completeness and efficiency while avoiding infinite loops.
47
+
48
+
## Informed/Heuristic Search Algorithms
49
+
50
+
Let's go through the different types of informed/heuristic search algorithms one-by-one.
51
+
52
+
### Greedy Best-First Search
53
+
54
+
This algorithm selects nodes based on the estimated cost to reach the goal. While it can be efficient, it does not guarantee finding the optimal path since it ignores the cost already incurred.
55
+
56
+
### A\* Search
57
+
58
+
A\* combines the actual path cost from the starting node with a heuristic estimate of the cost to reach the goal. When using an admissible heuristic (one that never overestimates), A\* is both complete and optimal, making it one of the most widely used informed search algorithms.
59
+
60
+
### Hill Climbing
61
+
62
+
This algorithm iteratively moves in the direction that seems best according to the heuristic function. While simple and memory-efficient, it can get stuck in local optima, plateaus, or ridges, preventing it from finding the global optimum.
63
+
64
+
### Iterative Deepening A\* (IDA\*)
65
+
66
+
This is a memory-efficient variant of A\* that uses depth-first exploration combined with heuristic guidance. It gradually increases the cost threshold, ensuring a balance between memory usage and optimality.
67
+
68
+
## Comparison of Search Algorithms
69
+
70
+
| Algorithm | Type | Complete | Optimal | Time Complexity | Space Complexity | Notes |
This algorithm uses a heuristic function to guide the search towards the optimal solution. A\* search, one of the most popular heuristic search algorithms, uses both the actual cost of getting to a node and an estimate of the cost to reach the goal from that node.
82
+
> **Note:** The asterisk (\*) indicates that the corresponding search algorithm is optimal only if all step costs are equal (i.e., in unweighted graphs).
45
83
46
-
## Application of Search Algorithms
84
+
## Applications of Search Algorithms
47
85
48
-
Search algorithms are used in various fields of artificial intelligence, including:
86
+
-**Pathfinding**: Finds the shortest path in graphs or networks; BFS and A\* are commonly used.
87
+
-**Optimization**: Seeks minimum/maximum values under constraints; algorithms like hill climbing or simulated annealing are applied.
88
+
-**Game Playing**: Evaluates possible moves via search trees to choose the best strategy.
89
+
-**Planning and Scheduling**: Used in logistics, project management, and resource allocation to create efficient plans.
49
90
50
-
### Pathfinding
91
+
##Frequently Asked Questions
51
92
52
-
Pathfinding problems involve finding the shortest path between two points in a given graph or network. BFS or A\*search can be used to explore a graph and find the optimal path.
93
+
### 1. What is the most used search algorithm?
53
94
54
-
### Optimization
95
+
A\* is the most widely used search algorithm because it balances efficiency and accuracy. It uses both the path cost and a heuristic estimate, ensuring optimal solutions when the heuristic is admissible.
55
96
56
-
In optimization problems, the goal is to find the minimum or maximum value of a function, subject to some constraints. Search algorithms such as hill climbing or simulated annealing are often used in optimization cases.
97
+
### 2. Why are searching algorithms used?
57
98
58
-
### Game Playing
99
+
Search algorithms are used to explore problem spaces, find solutions, and make decisions. They help in tasks like pathfinding, optimization, planning, and game playing, enabling AI systems to operate intelligently.
59
100
60
-
In game playing, search algorithms are used to evaluate all possible moves and choose the one that is most likely to lead to a win, or the best possible outcome. This is done by constructing a search tree where each node represents a game state and the edges represent the moves that can be taken to reach the associated new game state.
101
+
### 3. Which search algorithm is faster?
61
102
62
-
The following algorithms have dedicated, more in-depth content:
103
+
The speed of a search algorithm depends on the problem and the available information. Greedy Best-First Search can be faster since it uses heuristics to guide the search, but it is not always optimal. A\*, while slightly slower, guarantees optimality with the right heuristic.
0 commit comments