Interactive CLI tool for exploring search algorithms
Project description
๐ Search Algorithms Explainer CLI
A professional, interactive command-line tool for learning and comparing search algorithms. This project demonstrates Linear Search, Binary Search, and their performance characteristics with real-time step-by-step execution.
โจ Features
๐ฏ Interactive CLI Interface
- User-friendly menu system
- Real-time step-by-step algorithm execution
- Direct visualization of how algorithms work
๐ Search Algorithms
- Linear Search: Sequential search with O(n) time complexity
- Binary Search: Efficient sorted search with O(log n) time complexity
- Comparison Mode: Run both algorithms side-by-side with the same data
๐ Result Tracking
- Automatic logging of all searches
- Performance metrics (steps taken, time complexity, space complexity)
- Search history with detailed results
- Ability to clear individual results
๐จ Flexible Input
- Pre-loaded questions from JSON
- Manual list input
- Inline number entry (e.g.,
1 2 3 4)
๐ฆ Installation
From PyPI (Recommended)
pip install search-algorithms-explainer
From Source
# Clone or download the project
cd search-algorithms-explainer
# Install in development mode
pip install -e .
# Or just run directly
python -m search_algorithms
Requirements
- Python 3.7 or higher
- No external dependencies (uses only Python standard library)
๐ Quick Start
Start Interactive Mode (Default)
search-algo
# or
python -m search_algorithms
# or
search-algo /start
๐ Usage
Available Commands
| Command | Description |
|---|---|
search-algo /start |
Start interactive program (default) |
search-algo /history |
View all search history |
search-algo /clearresult |
Remove last search result |
search-algo /end |
Exit program |
search-algo --version or -v |
Show version |
search-algo --help or -h |
Show help message |
Quick Start Guide
-
Start the program
search-algo
-
Choose a question (Q1, Q2, etc.) or enter numbers manually
Which question (Q1) or command: Q1 -
Select an algorithm
1 - Linear Search 2 - Binary Search (on sorted list) 3 - Compare Linear vs Binary -
Enter target number and watch the algorithm execute step-by-step
-
View history at any time with
/history
Interactive Mode
$ search-algo /start
======================================================
SEARCH ALGORITHMS EXPLAINER
Version 1.0.0
Interactive Mode Started
======================================================
--------------------------------------
Choose question key from JSON (e.g. Q1)
--------------------------------------
Available keys:
Q1 Q2 Q3 Q4 Q5
--------------------------------------
You may type: Q1 OR manual OR numbers directly (e.g. 1 2 3 4)
Type 'exit' to quit.
--------------------------------------
Input Options
| Input Type | Example | Description |
|---|---|---|
| Predefined Questions | Q1, Q2, Q3 |
Use pre-loaded question data |
| Manual Input | manual |
Enter a custom list manually |
| Inline Numbers | 1 2 3 4 |
Search in inline-entered numbers |
Algorithm Options
- Linear Search: Sequential search through the list
- Binary Search: Efficient search on sorted list (automatically sorts input)
- Compare Both: Run both algorithms and compare results side-by-side
๐ Example Session
$ search-algo /start
Which question (Q1) or command: 5 10 15 20 25
Loaded list for 5 10 15 20 25:
List contents:
5 10 15 20 25
--------------------------------------
--------------------------------------
Choose algorithm:
1 - Linear Search
2 - Binary Search (on sorted list)
3 - Compare Linear vs Binary
b - Back to choose Q-key
exit - Quit program
--------------------------------------
Enter choice (1/2/3/b/exit): 3
Enter target number to search: 15
===== Comparing Linear Search vs Binary Search =====
[1] Running Linear Search...
--------- LINEAR SEARCH ---------
Step 1 : index = 0 , element = 5 , target = 15
=> Not equal, moving next
Step 2 : index = 1 , element = 10 , target = 15
=> Not equal, moving next
Step 3 : index = 2 , element = 15 , target = 15
=> Match found
=> Element 15 found at index 2
Total steps taken (Linear Search): 3
[2] Running Binary Search...
--------- BINARY SEARCH ---------
Note: Binary Search works on a sorted list.
Sorted list used:
List contents:
5 10 15 20 25
Step 1 : low = 0 , high = 4 , mid = 2 , element = 15 , target = 15
=> Match found
=> Element 15 found at index 2 (in sorted list)
Total steps taken (Binary Search): 1
----------- SUMMARY -----------
Linear Search : Found (index 2 in original list)
Binary Search : Found (index 2 in sorted list)
Steps taken:
Linear Search -> 3 steps
Binary Search -> 1 steps
Time Complexity:
Linear Search -> O(n)
Binary Search -> O(log n) (requires sorted list)
-------------------------------
๐ View History
$ search-algo /history
============================================================
SEARCH HISTORY
============================================================
[1] Question: inline: 5 10 15 20 25
Method: Linear Search (Compare Mode)
Result: Found
Steps: 3
Time Complexity: O(n)
Space Complexity: O(1)
[2] Question: inline: 5 10 15 20 25
Method: Binary Search (Compare Mode)
Result: Found
Steps: 1
Time Complexity: O(log n)
Space Complexity: O(1)
============================================================
Total entries: 2
============================================================
๐ How It Works
Linear Search
Linear Search examines each element sequentially until finding the target or reaching the end.
- Time Complexity: O(n) - must check every element in worst case
- Space Complexity: O(1) - no extra space needed
- Use Case: Works on unsorted lists, good for small datasets
Binary Search
Binary Search divides the search space in half repeatedly (requires sorted data).
- Time Complexity: O(log n) - halves search space each iteration
- Space Complexity: O(1) - no extra space needed
- Use Case: Very efficient for large sorted datasets
- Note: Algorithm automatically sorts the input for demonstration
Comparison Mode
Run both algorithms with the same target on the same data to see:
- How many steps each algorithm takes
- Which is more efficient for the given dataset
- Real-time visualization of each algorithm's execution
๐ Learning Objectives
This tool helps you understand:
- How Linear Search works sequentially
- How Binary Search divides the search space
- Time complexity differences (O(n) vs O(log n))
- When to use each algorithm
- Performance comparison with real examples
๐ Project Structure
search-algorithms-explainer/
โโโ search_algorithms/ # Main package
โ โโโ __init__.py
โ โโโ __main__.py # Entry point
โ โโโ config.py
โ โโโ core/ # Core algorithms
โ โ โโโ __init__.py
โ โ โโโ search_algorithms.py
โ โโโ cli/ # Command-line interface
โ โ โโโ __init__.py
โ โ โโโ menu.py
โ โ โโโ commands.py
โ โโโ utils/ # Utility functions
โ โโโ __init__.py
โ โโโ data_handler.py
โ โโโ input_handler.py
โโโ data/ # Data files
โ โโโ questions.json # Pre-loaded questions
โโโ bin/ # Executable scripts
โโโ setup.py # Package setup
โโโ pyproject.toml # Modern Python packaging
โโโ requirements.txt # Dependencies
โโโ README.md # This file
โโโ LICENSE # MIT License
โโโ .gitignore # Git ignore rules
๐พ Result Logging
All search results are automatically saved to results.json with:
- Question identifier
- Algorithm used
- Number of steps taken
- Time and space complexity
- Whether target was found
Example results.json
[
{
"question": "Q1",
"method": "Linear Search",
"time_complexity": "O(n)",
"space_complexity": "O(1)",
"steps": 5,
"found": "Found"
}
]
๐ Data Files
questions.json
Pre-loaded with 30 test questions (Q1-Q30) containing various list configurations:
- Sorted lists
- Reversed lists
- Random lists
- Duplicates
- Special patterns
Location: data/questions.json
๐ ๏ธ Development
Running Tests
pytest tests/
Code Style
This project follows PEP 8 guidelines. Use these tools:
# Format code
black search_algorithms/
# Check style
flake8 search_algorithms/
pylint search_algorithms/
# Check types
mypy search_algorithms/
๐ค Contributing
Contributions are welcome! Feel free to:
- Report bugs
- Suggest new features
- Submit pull requests
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐จโ๐ป Author
Created with โค๏ธ for learning and education
๐ Links
- PyPI Package: https://pypi.org/project/search-algorithms-explainer/
- GitHub Repository: https://github.com/yourusername/search-algorithms-explainer
- Documentation: https://github.com/yourusername/search-algorithms-explainer/wiki
- Issue Tracker: https://github.com/yourusername/search-algorithms-explainer/issues
๐ Support
For issues, questions, or suggestions:
- Check existing documentation
- Review example usage
- Create an issue on GitHub
- Contact via email
๐ Changelog
Version 1.0.0 (2024-12-04)
- โ Initial release
- โ Linear Search implementation
- โ Binary Search implementation
- โ Comparison mode
- โ Result history tracking
- โ Professional CLI structure
- โ Complete documentation
- โ Interactive CLI interface
- โ Search history tracking
- โ Result logging to JSON
- โ Compare mode for algorithms
Happy Learning! ๐
Made with โค๏ธ for education and learning
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file search_algorithms_explainer-1.0.1.tar.gz.
File metadata
- Download URL: search_algorithms_explainer-1.0.1.tar.gz
- Upload date:
- Size: 16.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
473d2fb4d7896d452e8d8ddddfd50390b3759e71c9837983ed0cb6d53c5c481d
|
|
| MD5 |
2331017f3febb6bc3e2f653dcd666887
|
|
| BLAKE2b-256 |
26f73a69919118a4a15ec7d8b7c5d3718bd8187d8ce210cf48566e80e0e87771
|
File details
Details for the file search_algorithms_explainer-1.0.1-py3-none-any.whl.
File metadata
- Download URL: search_algorithms_explainer-1.0.1-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea22ada5fbfb73cc5e0da21e8a0ae7fdf62ac1b6d256915ae03d7b0bb3a8b57f
|
|
| MD5 |
c7cc98be0a9f09ff5d8b614649f5d288
|
|
| BLAKE2b-256 |
1f577e31fc23137dc6d77f5d955e27aa395f451053df82d4ca6d8f6b75e79121
|