Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions sorts/bubble_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,24 @@
timer_iterative = timeit(
"bubble_sort_iterative(unsorted[:])", globals=globals(), number=num_runs
)
print("\nIterative bubble sort:")
print(*bubble_sort_iterative(unsorted), sep=",")
print(f"Processing time (iterative): {timer_iterative:.5f}s for {num_runs:,} runs")

Check failure on line 122 in sorts/bubble_sort.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

sorts/bubble_sort.py:122:1: W293 Blank line contains whitespace

Check failure on line 122 in sorts/bubble_sort.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

sorts/bubble_sort.py:122:1: W293 Blank line contains whitespace
print(f"Total runs for benchmark: {num_runs:,}\n")

# Iterative version
print("➡️ Iterative Bubble Sort:")
sorted_iter = bubble_sort_iterative(unsorted)
print("Sorted Output:", ", ".join(map(str, sorted_iter)))
print(f"Time Taken (Iterative): {timer_iterative:.5f}s\n")

# Recursive version
unsorted = sample(range(-50, 50), 100)
timer_recursive = timeit(
"bubble_sort_recursive(unsorted[:])", globals=globals(), number=num_runs
)
print("➡️ Recursive Bubble Sort:")
sorted_rec = bubble_sort_recursive(unsorted)
print("Sorted Output:", ", ".join(map(str, sorted_rec)))
print(f"Time Taken (Recursive): {timer_recursive:.5f}s")

print("\n✅ Comparison completed successfully!")

unsorted = sample(range(-50, 50), 100)
timer_recursive = timeit(
"bubble_sort_recursive(unsorted[:])", globals=globals(), number=num_runs
)
print("\nRecursive bubble sort:")
print(*bubble_sort_recursive(unsorted), sep=",")
print(f"Processing time (recursive): {timer_recursive:.5f}s for {num_runs:,} runs")
Loading