This project helps visualize how the running time of algorithms grows as the input size increases.
It includes:
- A Python time complexity visualizer that benchmarks algorithms and plots input size vs running time.
- A Java merge sort visualizer that displays an animated bar chart as the array gets sorted.
- Generic
time_complexity_visualizer(algorithm, n_min, n_max, n_step)function. - Measures execution time for different input sizes.
- Plots Input Size vs Running Time (seconds) using Matplotlib.
- Currently includes:
linear_search(n)→ simulates an O(n) search.bubble_sort(n)→ classic O(n²) sorting on random arrays.
- Easy to extend with your own algorithms.
- Visualizes Merge Sort using a bar chart in a Swing window.
- Each bar represents an element in the array.
- Bars update as the algorithm runs, giving an intuitive feel for divide-and-conquer.
The core function:
- Takes an
algorithmfunction that accepts an integern(input size). - Runs the algorithm for values from
n_minton_maxwith step sizen_step. - Uses
time.time()to measure runtime. - Uses
matplotlibto plot the results.
⚠️ Note: This gives an experimental feel for time complexity, not a mathematically perfect one.
Things like CPU load, Python interpreter overhead, and small input sizes can affect measurements.
Input arguments:
algorithm: function to benchmark (takes an integernas input)n_min: minimum input sizen_max: maximum input sizen_step: step size between input sizes
Output:
- A plot showing running time vs input size for the given algorithm.
.
├── python/
│ └── main.py # Time complexity visualizer and algorithms
├── java/
│ └── AlgorithmVisualizer.java # Merge sort visualizer (Swing)
└── LICENSE # GNU GPL v3