Worst Sorting Algorithm Ever -
Вставка
- Опубліковано 27 кві 2021
- Complete Java course: codingwithjohn.thinkific.com/...
Bogo sort is a terrible but hilarious sorting algorithm. Let's write it in Java!
Full source available HERE, if you want to use this to yourself: codingwithjohn.com/bogosort-s...
Learn or improve your Java by watching it being coded live!
Hey, I'm John! I'm a Lead Java Software Engineer and I've been in the programming industry for more than a decade. I love sharing what I've learned over the years in a way that's understandable for all levels of Java developers.
Let me know what else you'd like to see!
Links to any stuff in this description are affiliate links, so if you buy a product through those links I may earn a small commission.
📕 THE best book to learn Java, Effective Java by Joshua Bloch
amzn.to/36AfdUu
📕 One of my favorite programming books, Clean Code by Robert Martin
amzn.to/3GTPVhf
🎧 Or get the audio version of Clean Code for FREE here with an Audible free trial
www.audibletrial.com/johnclean...
🖥️Standing desk brand I use for recording (get a code for $30 off through this link!)
bit.ly/3QPNGko
📹Phone I use for recording:
amzn.to/3HepYJu
🎙️Microphone I use (classy, I know):
amzn.to/3AYGdbz
Donate with PayPal (Thank you so much!)
www.paypal.com/donate/?hosted...
☕Complete Java course:
codingwithjohn.thinkific.com/...
codingwithjohn.com
#Shorts - Наука та технологія
But there is still a 0.000000001 % probability that this algorithm might outperform the fastest sorting algorithm known till date. 😂
Is it bogo
@@Pennervomland Checking whether a list is sorted is easy and doesn't require do sort it first. You just need to check for every element whether it's smaller or equal as the next.
@@Pennervomland it doesn’t have to be sorted already. It can be in any order, and after on random shuffle there is a 1/n! probability that it will be sorted. So for the 14 element list in the video there is a 1/14! = 1/87178291200 = 1.147e-11 probability it would have been sorted after one shuffle
@@maurolionelmipianoyyo11 watch pogo
Yes this has a 0.0000001% chance (I know this is an arbitrary number) to outperform the best (but also underperforms lots of others who can also do this on the first line)
You say it's not fast.
I say it CAN be fast.
The guy who is employing people says otherwise. Wake up you would be crying if google used that.
True, it could be the fastest ever developed. Imagine one million items to sort, and it randomly gets it right the first time. No other algorithm can come even close.
But then again, if only the first two are out of order ... mmm
@@rodrigoqteixeira Actually, I'd prefer that compared to seeing Stack Overflow at the top of the list.
Everyone laughs until it gets a million entries right in a single second
Python programmers on Leetcode with their one liner solutions be like😂
🤣
O(1) 💀💀💀💀
@@ELMlKO O(lucky)
@@iuritorreslol
Fr
The algorithm is called bogo sort
i thought it was bogus sort
Buga buga sort.
This isn't bogo sort. Bogo sort calculates every permutation of the given input and searches for the permutation where all the items are sorted. This is just plain random sort.
Um ACtUAly Iz caL dah bozo Zort
Doesnt this code do exactly that?
Bruh, that was genius. I will do this in my algoritms exam tomorrow
Boy they're gonna kick you right on out of that room. 😆
Straight F
Lol
@@pranavnyavanandi9710 already one algorithm exists called bogo sort so Nope!
The caveat with this algorithm is that if the shuffle method isn't a proper pseudo-random shuffle, it may never terminate. I prefer to use cosmic sort instead, which simply waits until the list is sorted by random bit flips caused by cosmic rays. That way you only have to worry about checking if the list is sorted.
Unbelievably, this algorithm also has an O(n) cousin, called quantum bogo sort. It uses entangled particles to randomly shuffle a list, and then checks if the list is sorted. If the list isn't sorted, it destroys the universe. In all the surviving universes, the list was sorted in constant time!
I guess it's faster with a particle accelerator?
it's like the second most popular algorithm to assemble Rubik's cube
That is basically "shuffle and Inshaallah"
This killed me
😂 amen brother
"Bogosort is the slowest"
Bogobogosort joins the chat
Bogobogobogosort joins the chat
Infinite family of Bogobogosorts joins the chat
*Miracle sort joins the chat*
lol this is a good one
If it was bad for you, it is your fault. If you are lucky it will be always the best one. Don't blame the algorithm for your bad luck
Best-case complexity for unsorted array: O(1)
Worst-case though, depending on implementation of shuffle, can be literally infinity.
Won't the worst case be O(n!)
(assuming u r trying all possible permutations of the array)
@@shubhrajit2117 IF you're trying all possible permutations. Probably typical implementations in standard libraries make sure of that, but if someone made a simple shuffle function using pseudo-RNG, there may be such arrays that will never be sorted correctly.
That's discusting, i love it
Fun fact: This is called Bogo sort.
Best case: O(n)
Average case: O(n*n!)
Worst case: ∞
Wouldn’t average be O(n!)
oh god i heard 'shuffle' and physically recoiled
Don't make fun of bogosort, he's just tryna learn!
If it works, it works
If 🤞was a sorting algorithm
HAHAHA, loved this short!
"Bogosort", right?
yes
johnosort
Everybody loves our little Bogo Sort
If you think that's the worst, you clearly haven't heard of bogobogosort.
bogobogosort is like bogosort but instead in picks 2 random numbers and shuffles them, if it's sorted then shuffle again but if it isn't sorted, it's gonna start over again
Hey John! Can you please make some videos to explain in depth what is POJO in Java, interface and abstract class, how arraylist store object in Java, and object pass in method mean,...
Thanks for the ideas! I've got one just about ready to go for this week already, but I'll definitely see if I can do one of those for next week.
😹😹😹That's what I call efficiency
Just laughed till tears. Brilliant humour, man!
BOGO SORT!
BOGO SORT!
Expected runtime O(n!) 😂
bro that's the best sorting algorithm!
Well if you think about it, it could also be the fastest... if you are extremely lucky
This is the equivalent of hitting a tree with a wrench until you make a chair.
You are working really hard. Just remember, you are a champion by programming,. So it counts always :))
Miracle sort is beautiful
This is worst than the sleep sort algorithm
It is the famous Bogo sort
I knew Bogo sort was slow, but not THAT slow.
Everyone is gansta until the miracle sort comes.
Theoretically it is both the fastest and slowest. It can be done on the first shuffle, and it can never be done.
There are a couple algorithms that could theoretically be faster. You got Solar Bitflip and Miracle Sort (basically the same thing) where the output _could_ become sorted before you ever check it.
You also have Dictator Sort, where the list is already sorted and if you disagree you die, and Intelligent Design Sort where clearly the array is meant to be in this order, because there's only a 1/n! chance of this particular order occurring
Miracle sort: Hold my process
In an alternate universe, bogo sort will sort any length data 100% of the time, and no one knows why.
Surprised it took that short lol. We are looking at over 13! permutations here
"...In Java. It's not fast." Man, you're roasting Java so hard.
Vsauce if he was a programmer
this is the worst sorting algorithm and the best at the same time
Bogosort
My brain be like when I'm trying to solve the math problem.
You kind of look like Michael from Vsauce if he were normal
Miracle sort will always be my favorite sorting algorithm that theoretically can succeed.
For the record, this is called Bogo Sort.
You reinvented the wheel (its called bogosort)
Basically Bogo sort
There must exist a universe where Bogo sort is the fastest every time
Bogo sort lesgooo
ever heard of lucky sort?. does nothing, just checked whether the start is sorted, if it's not, it'll check again and hope for a miracle
I wanted to learn some programming but then i see random characters, letters and numbers and i dont want to anymore 😂
Bogo.
miracle sort:
The funny thing is, this sorting algorithm is one of the fastest with quantum computers lol.
I actually managed to sort a list of 10 elements within a second, I feel like a chad now
🏆
you're amazing man 😀
Randomizing the numbers until it’s sorted.
That’s kind of BogoS.
personal favourites: 14:13 for the sounds, 20:05 bc that one is impressive and so cool
Bogo sort XD
When you realize this is harder to implement than the selection sort, and you did it in an interview💀💀💀
Hey, but that best case!
have the same algorithm but instead of sorting it puts money on my wallet lol
Give
O(n²)? Nah, O(n!)
Bogo Sort is fastest and slowest at the same time. Use your luck!
Bogosort
Gotta love bogosort
I'm first' time watching this channel and this guy , kasam se ye banda mereko Jony Sins lag rha hai.😂
Bro this is slower than my internet 💀
I'd like to introduce you to miracle sort.
bogo sort
Amazing! Great sorter
Ah yes, bogo sort.
Could make it *actually* 2 lines by scipping the curly brackets in the while loop
You could make all your programs just 1 line just by replacing all the newlines with spaces: ua-cam.com/video/YpS0Jh5yqIw/v-deo.html
The best sorting algorithm is miracle sort, you just wait until the list magically sorts itself!
You forgot about Bogobogosort
What theme did you use for this video?
when elements are sorted How the program know it is sorted and stop ?
\
Useful skill for the dean of Greendale
I love this -- Hilarious😂
what if you execute this code in ia ??
Nah, there are worse ones, solar bit flip sort for example or my invention (dunno if someone else already came up with that), error sort, you take two devices and send the array back and forth between the 2 without an error correction code and check if it is sorted.
i mean, it has got the potential, now it just need consistency.
The funny thing about BOGO is that it can be both the slowest and the fastest algorithm.
best case scenario O(1). that should be the marketing title 🐸
Worst case, O(♾️)
Ctrl + C *switches to notepad.exe* Ctrl + V
The best sorting Algo out there is miracle sort, just while(!sorted){} and you just hope and pray that some particle (or many particles) interfere with the system in just the right way to sort the list
😂😂😂😂 super fast 😂
Use bogosort algorithm to sorting something
finally a worthy enemy
You look so much like luke from polymathy, I thought he tarted teaching computer science all of a sudden lol.
nah you forgot about quantum bogosort
This is not a sorting algorithm. We can call this just; I'm feeling lucky😂
"Miracle Sort"?
Bogo😂Bogo
How many shuffles did those 5 hours take?
Yeah, it's O(n) might be pretty bad but it runs in O(1) for best case!
Newbie here.
How does it check whether the list is sorted in O(1) time.
Sorry if question doesn't make sense
its not O(1) best case because it has to check the whole list first, so best is O(n)
Wrong it's O(n) as a comment by @umthondo here point out. Worst case is infinite I would guess. Since it can go on and on like in the video shown above.
@@aravind2624 It's O(n) actually. Since the algorithm has to loop over the entire list which is performing n steps to check if the list is in sorted condition. Check the lecture by Abdul Bari on youtube. That's how I kind of got to understanding it.
This is evil