This repository aims to provide a comprehensive starting point for understanding and implementing two fundamental search algorithms: Sequential Search and Binary Search. These search algorithms are implemented in Python and serve as a great introduction to search techniques for beginners and intermediate programmers.
The purpose of this repository is to help users understand and implement two basic search algorithms in Python. It includes detailed explanations, code examples, and usage instructions for both Sequential Search and Binary Search.
Here is a quick demo of how the search algorithms work:
# Sequential Search Example
def sequential_search(arr, target):
for i in range(len(arr)):
if arr[i] == target:
return i
return -1
# Binary Search Example
def binary_search(arr, target):
low = 0
high = len(arr) - 1
while low <= high:
mid = (low + high) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
low = mid + 1
else:
high = mid - 1
return -1
- Implementation of Sequential Search in Python
- Implementation of Binary Search in Python
- Example usage of both search algorithms
- Detailed comments and explanations
- Python
To set up the project locally, follow these steps:
- Clone the repository:
git clone https://github.com/guanshiyin28/Sequential-Search-and-Binary-Search.git
- Navigate to the project directory:
cd Sequential-Search-and-Binary-Search
To run the Python scripts, use the following commands:
- Run the Sequential Search script:
python program_v2.py
- Run the Binary Search script:
python program.py
This project is licensed under the MIT License. See the LICENSE file for details.