Why My Teenage Code Was Terrible: Sorting Algorithms and Big O Notation

Why My Teenage Code Was Terrible: Sorting Algorithms and Big O Notation

Tom Scott

4 года назад

2,606,246 Просмотров

When I was a teenager, I wrote some terrible code. Here's why. • Sponsored by Dashlane — for free on your first device @ https://www.dashlane.com/tomscott

MORE BASICS: https://www.youtube.com/playlist?list=PL96C35uN7xGLLeET0dOWaKHkAlPsrkcha

Written with Sean Elliott https://twitter.com/SeanMElliott/
Directed by Tomek
Graphics by Mooviemakers https://www.mooviemakers.co.uk/
Audio mix by Haerther Productions https://haerther.net/

I'm at https://tomscott.com
on Twitter at https://twitter.com/tomscott
on Facebook at https://facebook.com/tomscott
and on Instagram as tomscott

Тэги:

#tom_scott #tomscott #the_basics #computer_science #big_o_notation #sorting #sort_algorithms #bubble_sort #quick_sort #bogosort
Ссылки и html тэги не поддерживаются


Комментарии:

Lampe2020
Lampe2020 - 31.10.2023 13:51

I'm right now trying to implement a search algorithm for my own website (because somehow Google etc. fail to find almost anything on that site, they only know four of the approximately fifty pages on my website) and realized that I probably should just make the index and then let an existing algorithm search through it…

Ответить
Daniel Radnedge
Daniel Radnedge - 20.10.2023 03:17

I miss this stuff.

Ответить
Reinhard von Lohengramm
Reinhard von Lohengramm - 14.10.2023 02:22

My favorite sorting algorithm is Stalin Sort. If a number is out of order, it gets sent to the gulag. Some data does die, but that is a sacrifice I am willing to make.

Ответить
Jaden Humphries
Jaden Humphries - 07.10.2023 06:58

Bubble sort only goes to index size -1 once.

Ответить
Shibam Roy
Shibam Roy - 06.10.2023 18:30

Isnt the worst case of insertion sort and bubble sort O(nlogn)?

Ответить
Bijesh Shrestha
Bijesh Shrestha - 27.09.2023 13:57

Saw this in my teenage and indeed avoided his mistakes

Ответить
pleappleappleap
pleappleappleap - 22.09.2023 15:16

Theoretically, for sorting algorithms, the theoretical worst big-O you can get, for an algorithm that actually functions correctly as a sorting algorithm, is, as you showed `O(n!)` which is the bogosor algorithm.

The best possible big-O for a sorting algorithm is `O(n)` which is the quantum bogosort algorithm:

1. Randomize the list.
2. Check if it is sorted.
3. If it isn't sorted, destroy the universe.

This makes it so only universes where the list is sorted continue to exist. If the many-worlds interpretation is untrue, however, the results would be... unfortunate.

Ответить
pleappleappleap
pleappleappleap - 22.09.2023 15:08

Big-O ignores all constants. `O((n+1)!)` is the same as `O(n!)` .

Ответить
Touchcreator
Touchcreator - 18.09.2023 04:39

bro really did bogosort 💀

Ответить
D.K.
D.K. - 14.09.2023 10:09

When I was a teenager i didnt know what code was.

Ответить
the tessellater
the tessellater - 02.09.2023 19:24

You might as well been speaking gobble-de-gook for the amount I understood - none !

Ответить
time enough
time enough - 02.09.2023 15:57

❤❤❤love ur effort to explaim

Ответить
Chazdachap
Chazdachap - 19.08.2023 08:49

Bogosort is 50/50 it's either in the correct order or its not.

Ответить
TheRMeerkerk
TheRMeerkerk - 13.08.2023 22:13

I am slightly annoyed that Merge Sort was never mentioned

Ответить
Ron Rommy
Ron Rommy - 13.08.2023 14:46

I used to do bogosort with my rubik's cube.

Ответить
Dallin Despain
Dallin Despain - 04.08.2023 01:19

Man, that story was… relateable.

Ответить
Airat Valiullin
Airat Valiullin - 02.08.2023 12:55

"Why spend 5 minutes doing something when you could spend 5 hours failing to automate it"

Ответить
Alcatraz
Alcatraz - 10.07.2023 05:48

you want O(n!) for the best performance

Ответить
Nick Hellstern
Nick Hellstern - 27.06.2023 19:11

I'm happy to say that after like 1 uear of watching this video, I've fonally found a use for this as my IT school wanted us to learn algorithms in C++

Also, yes I implemented Bogosort, and yes it was approved by the teachers

Ответить
Deriz Nobot
Deriz Nobot - 23.06.2023 23:21

Now code it will grow with one.

Ответить