Skip to content

Commit 8997adf

Browse files
authored
[Edit] AI: Search Algorithms (#7643)
* [Edit] AI: Search Algorithms * Update search-algorithms.md ---------
1 parent aac188d commit 8997adf

File tree

1 file changed

+63
-22
lines changed

1 file changed

+63
-22
lines changed
Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
---
22
Title: 'Search Algorithms'
3-
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.'
44
Subjects:
5-
- 'Machine Learning'
65
- 'Computer Science'
6+
- 'Machine Learning'
77
Tags:
88
- 'AI'
99
- 'Algorithms'
10-
- 'Graphs'
1110
- 'Graph Search'
11+
- 'Graphs'
1212
CatalogContent:
13-
- 'paths/data-science'
13+
- 'prompt-engineering-for-software-engineers'
14+
- 'paths/machine-learning-ai-engineering-foundations'
1415
---
1516

16-
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.
1718

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.
1920

20-
Search algorithms are typically organized into two categories:
21+
## Types of Search Algorithms
2122

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:
2324

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.
2527

26-
## Types of Search Algorithms
28+
## Uninformed/Blind Search Algorithms
2729

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.
2931

3032
### Depth-First Search (DFS)
3133

@@ -39,24 +41,63 @@ This algorithm explores all the neighbor nodes at the current level before movin
3941

4042
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.
4143

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 |
71+
| ------------------------------- | ---------- | -------- | ------- | ---------------------------- | ------------------ | -------------------------------------------------------------------- |
72+
| Depth-First Search (DFS) | Uninformed | No | No | O(b^m) | O(bm) | Explores deep paths first; may get stuck in infinite branches. |
73+
| Breadth-First Search (BFS) | Uninformed | Yes | Yes\* | O(b^d) | O(b^d) | Finds shortest path in unweighted graphs; memory-intensive. |
74+
| Uniform Cost Search (UCS) | Uninformed | Yes | Yes | O(b^(1 + ⌈C\*/ε⌉)) | O(b^(1 + ⌈C\*/ε⌉)) | Expands least-cost nodes; suitable for weighted graphs. |
75+
| Depth-Limited Search | Uninformed | No | No | O(b^l) | O(bl) | DFS with depth limit `l`; avoids infinite descent. |
76+
| Iterative Deepening Search | Uninformed | Yes | Yes\* | O(b^d) | O(bd) | Combines BFS optimality and DFS space efficiency. |
77+
| Greedy Best-First Search | Informed | Yes | No | O(b^m) | O(b^m) | Uses heuristic only; fast but not guaranteed optimal. |
78+
| A\* Search | Informed | Yes | Yes | O(b^d) (with good heuristic) | O(b^d) | Balances path cost + heuristic; optimal with admissible heuristic. |
79+
| Hill Climbing | Informed | No | No | Varies | Varies | Moves toward best heuristic neighbor; can get stuck in local optima. |
80+
| Iterative Deepening A\* (IDA\*) | Informed | Yes | Yes | O(b^d) | O(bd) | Memory-efficient A\* variant using iterative deepening. |
4381

44-
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).
4583
46-
## Application of Search Algorithms
84+
## Applications of Search Algorithms
4785

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.
4990

50-
### Pathfinding
91+
## Frequently Asked Questions
5192

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?
5394

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.
5596

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?
5798

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.
59100

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?
61102

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

Comments
 (0)