The time complexity of every algorithms make its value (#1401)

* added timer in bubble sort

* Updated time of execution

* import time in main only

* Update bubble_sort.py

* start = time.process_time()
This commit is contained in:
Sujitkumar Singh 2019-10-20 01:42:54 +05:30 committed by Christian Clauss
parent cd10c944d1
commit 38d7e7073a

View File

@ -6,13 +6,13 @@ def bubble_sort(collection):
:return: the same collection ordered by ascending
Examples:
>>> bubble_sort([0, 5, 3, 2, 2])
>>> bubble_sort([0, 5, 2, 3, 2])
[0, 2, 2, 3, 5]
>>> bubble_sort([])
[]
>>> bubble_sort([-2, -5, -45])
>>> bubble_sort([-2, -45, -5])
[-45, -5, -2]
>>> bubble_sort([-23, 0, 6, -4, 34])
@ -34,6 +34,9 @@ def bubble_sort(collection):
if __name__ == "__main__":
import time
user_input = input("Enter numbers separated by a comma:").strip()
unsorted = [int(item) for item in user_input.split(",")]
start = time.process_time()
print(*bubble_sort(unsorted), sep=",")
print(f"Processing time: {time.process_time() - start}")