https://github.com/ashithapallath/ai-searches
The AI Searches repository provides a Jupyter Notebook demonstrating the implementation of various AI search algorithms commonly used in optimization and pathfinding problems. It includes algorithms such as Breadth-First Search (BFS), Depth-First Search (DFS), Uniform Cost Search (UCS), Greedy Best-First Search, and A* Search.
https://github.com/ashithapallath/ai-searches
ai-search-algorithms bfs-search dfs-search greedy-search-algorithm python ucs-search
Last synced: 7 months ago
JSON representation
The AI Searches repository provides a Jupyter Notebook demonstrating the implementation of various AI search algorithms commonly used in optimization and pathfinding problems. It includes algorithms such as Breadth-First Search (BFS), Depth-First Search (DFS), Uniform Cost Search (UCS), Greedy Best-First Search, and A* Search.
- Host: GitHub
- URL: https://github.com/ashithapallath/ai-searches
- Owner: ashithapallath
- Created: 2022-09-15T16:37:15.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-01-14T05:01:02.000Z (9 months ago)
- Last Synced: 2025-01-27T10:12:42.340Z (9 months ago)
- Topics: ai-search-algorithms, bfs-search, dfs-search, greedy-search-algorithm, python, ucs-search
- Language: Jupyter Notebook
- Homepage:
- Size: 5.4 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AI Searches
This repository contains a Jupyter Notebook that demonstrates the implementation of various AI search algorithms. These algorithms form the backbone of many artificial intelligence applications and are essential for solving optimization and pathfinding problems.
## Features
The notebook includes implementations of the following search algorithms:
- **Breadth-First Search (BFS)**: Explores all nodes at the present depth before moving to nodes at the next depth.
- **Depth-First Search (DFS)**: Explores as far as possible along each branch before backtracking.
- **Uniform Cost Search (UCS)**: A variant of BFS that considers the cost of the path.
- **Greedy Best-First Search**: Prioritizes nodes based on a heuristic.
- **A* Search**: Combines UCS and heuristic-based search for optimal pathfinding.
## Prerequisites
Make sure you have the following installed:
- Python 3.8+
- Jupyter Notebook
- Required libraries:
- NumPy
- MatplotlibInstall the dependencies using pip:
```bash
pip install numpy matplotlib
```
## How to Use
1. Clone the repository:
```bash
git clone https://github.com/ashithapallath/AI-Searches.git
cd AI-Searches
```2. Open the Jupyter Notebook:
```bash
jupyter notebook search.ipynb
```3. Follow the step-by-step implementation of the search algorithms. Modify the sample problems to test the algorithms in various scenarios.
## Examples
### Example 1: Breadth-First Search (BFS)
```python
from collections import dequedef bfs(graph, start):
visited = set()
queue = deque([start])
while queue:
node = queue.popleft()
if node not in visited:
visited.add(node)
queue.extend(graph[node] - visited)
return visited
```### Example 2: A* Search
```python
import heapqdef a_star_search(graph, start, goal, h):
open_set = []
heapq.heappush(open_set, (0 + h[start], start))
came_from = {}
g_score = {node: float('inf') for node in graph}
g_score[start] = 0while open_set:
_, current = heapq.heappop(open_set)
if current == goal:
break
for neighbor in graph[current]:
tentative_g_score = g_score[current] + graph[current][neighbor]
if tentative_g_score < g_score[neighbor]:
came_from[neighbor] = current
g_score[neighbor] = tentative_g_score
heapq.heappush(open_set, (g_score[neighbor] + h[neighbor], neighbor))
```## Contribution
Contributions are welcome! Feel free to fork the repository and submit pull requests for improvements, bug fixes, or additional features.
## License
This project is licensed under the MIT License.
## Acknowledgments
Thanks to the AI and open-source communities for providing resources and inspiration to build and share implementations of search algorithms.