This project implements a graph-based sorting algorithm to find the longest sequence of 6-digit numbers, where each number starts with the last two digits of the previous number. The script also measures execution time, CPU usage, and memory consumption during its execution.
- Graph-based sorting: Builds a graph to find the longest valid sequence.
- Validation: Ensures input file format and sequence validity.
- Performance metrics: Measures execution time, CPU time, and memory usage.
- Output: Saves the sorted sequence and final merged string to a file.
- Python 3.7+
- Required Python package:
psutil
-
Clone the repository:
git clone https://github.com/ToyLess78/graph-sorter-py.git cd graph-sorter
-
Install dependencies:
pip install psutil
-
Place your input file (e.g., source.txt) in the project directory.
-
Run the script:
python graph_sorter.py
The input file (source.txt) must contain 6-digit numbers, one per line. Example:
123456
564738
384950
- The script validates the input file and calculates the longest valid sequence.
- Outputs the sorted sequence to sortedlist.txt.
- Displays performance metrics in the console:
- Execution time
- CPU time used
- Memory used
- Missing psutil: If you encounter the error ModuleNotFoundError: No module named 'psutil', install the library:
pip install psutil
- File Not Found: Ensure that the input file (source.txt) is in the same directory as the script and has the correct format.
- Execution Time: Total time to process the file and compute the sequence.
- CPU Time: Time spent on CPU operations (user + system time).
- Memory Usage: Difference in memory usage before and after execution.
Bilenko Tetiana