Skip to main content

Interactive CLI tool for exploring search algorithms

Project description

๐Ÿ” Search Algorithms Explainer CLI

PyPI version Python 3.7+ License: MIT

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

  1. Start the program

    search-algo
    
  2. Choose a question (Q1, Q2, etc.) or enter numbers manually

    Which question (Q1) or command: Q1
    
  3. Select an algorithm

    1 - Linear Search
    2 - Binary Search (on sorted list)
    3 - Compare Linear vs Binary
    
  4. Enter target number and watch the algorithm execute step-by-step

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

  1. Linear Search: Sequential search through the list
  2. Binary Search: Efficient search on sorted list (automatically sorts input)
  3. 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

๐Ÿ†˜ 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

search_algorithms_explainer-1.0.1.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

search_algorithms_explainer-1.0.1-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file search_algorithms_explainer-1.0.1.tar.gz.

File metadata

File hashes

Hashes for search_algorithms_explainer-1.0.1.tar.gz
Algorithm Hash digest
SHA256 473d2fb4d7896d452e8d8ddddfd50390b3759e71c9837983ed0cb6d53c5c481d
MD5 2331017f3febb6bc3e2f653dcd666887
BLAKE2b-256 26f73a69919118a4a15ec7d8b7c5d3718bd8187d8ce210cf48566e80e0e87771

See more details on using hashes here.

File details

Details for the file search_algorithms_explainer-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for search_algorithms_explainer-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ea22ada5fbfb73cc5e0da21e8a0ae7fdf62ac1b6d256915ae03d7b0bb3a8b57f
MD5 c7cc98be0a9f09ff5d8b614649f5d288
BLAKE2b-256 1f577e31fc23137dc6d77f5d955e27aa395f451053df82d4ca6d8f6b75e79121

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page