Skip to content
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

Suggestion for sort #10

Open
goyalyashpal opened this issue Jan 26, 2023 · 1 comment
Open

Suggestion for sort #10

goyalyashpal opened this issue Jan 26, 2023 · 1 comment
Assignees

Comments

@goyalyashpal
Copy link

goyalyashpal commented Jan 26, 2023

In the "CS50 2021/2022 - Lecture 3 - Algorithms" , in section of "Sort Race" at the end,
Order of running time came out to be: Merge sort < Selection sort < Bubble sort

  • Here, I think more cautionary light can be shed on why selection sort performed faster than bubble sort.
  • Similar to how the caution was shared at the end of "CS50 2021 Lecture" for the numerical imprecision.

With content something like given below:
(sorry, this ain't related to "Source code for CS50's lectures" ; but lectures... i couldn't think of other place to suggest this)


2:00:29 it's worth noting that

  • even though it seemed that selection sort is doing more steps (1:11:05), but it is actually performing faster than bubble sort!

why?

  • 'cz the actual steps selection sort is performing in inner loop take less time individually...
  • it's O(n) comparisons, but exactly one swap per pass of the inner loop.

But in a single run of inner loop in bubble sort:

  • there were O(n) comparisons, as well as O(n) swaps.
  • So, that contributed to increased runtime of bubble sort
  • This is more getting into the weeds, but something you should be aware of while designing and analysing algorithms
@duffouroppong
Copy link

Is been nice being around .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants