Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

The time complexity of every algorithms make its value #1401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 19, 2019
Merged
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
9 changes: 6 additions & 3 deletions sorts/bubble_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -29,11 +29,14 @@ def bubble_sort(collection):
swapped = True
collection[j], collection[j + 1] = collection[j + 1], collection[j]
if not swapped:
break # Stop iteration if the collection is sorted.
break # Stop iteration if the collection is sorted.
return 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=",")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are also counting the time that the user enters the data. Let’s only count sort time...

Please move line 2 to be just above this line and also indent line 42.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay . Thanks a lot for the obersvation. Will do the changes

print(f"Processing time: {time.process_time() - start}")