From d23cc7ca592f38ec382977184e851aa27c410fb0 Mon Sep 17 00:00:00 2001 From: Your GitHub Username Date: Sat, 4 Oct 2025 21:40:30 +0530 Subject: [PATCH 1/2] fix: improve output readability in bubble_sort.py --- sorts/bubble_sort.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/sorts/bubble_sort.py b/sorts/bubble_sort.py index 9ec3d5384f38..9e6cc0686f97 100644 --- a/sorts/bubble_sort.py +++ b/sorts/bubble_sort.py @@ -119,14 +119,24 @@ def bubble_sort_recursive(collection: list[Any]) -> list[Any]: 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") + +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") From b466aa503c48e73914924455676c20b26a1a91f7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 4 Oct 2025 16:30:13 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- sorts/bubble_sort.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sorts/bubble_sort.py b/sorts/bubble_sort.py index 9e6cc0686f97..de5a954293a8 100644 --- a/sorts/bubble_sort.py +++ b/sorts/bubble_sort.py @@ -119,7 +119,7 @@ def bubble_sort_recursive(collection: list[Any]) -> list[Any]: timer_iterative = timeit( "bubble_sort_iterative(unsorted[:])", globals=globals(), number=num_runs ) - + print(f"Total runs for benchmark: {num_runs:,}\n") # Iterative version @@ -139,4 +139,3 @@ def bubble_sort_recursive(collection: list[Any]) -> list[Any]: print(f"Time Taken (Recursive): {timer_recursive:.5f}s") print("\n✅ Comparison completed successfully!") -