How ihortarkhan/sorting-algorithms-visualisation works
Project type and purpose
• This is a desktop “sorting algorithm visualization” application implemented in Python.
• It provides a GUI for users to generate arrays (with different orderings), run individual or batch sorting experiments across six algorithms, collect timing/memory data into a local database, and render charts.
File structure
• Top-level files:
• main.py – application entrypoint
• config.ini – database/config settings
• UI/ – GUI components (views):
• Check_box.py, Extract_results.py, Graphs.py, Visualization.py
• calculation/ – business logic:
• controller/benchmark.py – orchestrates a benchmark run
• service/array_generate/ArrayFactory.py – Factory pattern for array creation
• service/sorting/SortAlgorithmSingleton.py – Singleton dispatcher for sorting
• service/sorting/algoritms/… – implementations of each sorting algorithm (Strategy pattern)
• service/sorting/SorterResult.py – captures result of a single sort
• db/Connector.py & sorting_logs_connector.py & AverageSortingLog.py – data access layer for persisting/retrieving logs
• util/FloatUtil.py, PySorter.py – low-level utilities
• entity/ – data models and enums (ArrayOrderEnum, SortAlgorithmEnum, SortingLog, StatisticSortingResponse)
Key insights from README
• MVC-style separation: UI (views) ↔ controller (benchmark) ↔ service (model/business) ↔ DB (persistence)
• Uses Factory (ArrayFactory) for array generation, Strategy (each sorter implements AbstractSorter), Singleton (SortAlgorithmSingleton)
• Outputs time/memory graphs for single runs or full experiments
Components
a. Main components:
• Desktop UI layer (Visualization, CheckBoxes, Graphs, Extraction interface)
• Controller layer (BenchmarkController – triggers experiments)
• Service layer:
– ArrayFactory (array gen.)
– SortAlgorithmSingleton & individual SortAlgorithm implementations
– SorterResult aggregator
– Utility modules (FloatUtil, PySorter)
• Data Access layer (Connector, sorting_logs_connector, AverageSortingLog)
• Database (e.g., SQLite instance configured via config.ini)
• Entities/DTOs (SortingLog, StatisticSortingResponse, Enums)
• Application entrypoint (main.py)
b. Relationships and data flows:
1. main.py initializes UI components and reads config.ini → passes DB connector to controller
2. UI event (e.g., “Run single sample” or “Run full benchmark”) → calls BenchmarkController.run()
3. BenchmarkController
→ uses ArrayFactory to generate input arrays
→ calls SortAlgorithmSingleton to dispatch to a specific sorter (e.g., QuickSorter)
→ SorterResult collects timing & memory metrics (utilizing FloatUtil, PySorter)
→ persists results via sorting_logs_connector into Database
→ retrieves aggregated statistics (AverageSortingLog) if needed
→ returns StatisticSortingResponse DTOs back to controller
4. Controller instructs UI to render graphs (Graphs.py) or update result panels (Extract_results.py, Visualization.py)
c. Architectural patterns & principles:
• MVC / layered architecture – isolates UI, business logic, persistence
• Factory pattern for array generation
• Strategy pattern for pluggable sorting algorithms
• Singleton for central algorithm dispatcher
• DAO for database interactions
d. Key technologies/libraries:
• Python GUI toolkit (e.g., Tkinter or PyQt – inferred from UI files)
• SQLite or lightweight file-based DB via Connector
• matplotlib or similar for chart rendering (in Graphs.py)