Worst Sorting Algorithm Ever -
Вставка
- Опубліковано 18 жов 2024
- Complete Java course: codingwithjohn...
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...
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.audibletria...
🖥️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...
☕Complete Java course:
codingwithjohn...
codingwithjohn...
#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.
LOL love it hahaha!
O(1) if ur lucky
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
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?
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?
it's like the second most popular algorithm to assemble Rubik's cube
That is basically "shuffle and Inshaallah"
This killed me
😂 amen brother
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
"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 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
Don't make fun of bogosort, he's just tryna learn!
oh god i heard 'shuffle' and physically recoiled
If it works, it works
Expected runtime O(n!) 😂
HAHAHA, loved this short!
"2 line sorting algorithm"
The other lines:
Just laughed till tears. Brilliant humour, man!
Everybody loves our little Bogo Sort
This is the equivalent of hitting a tree with a wrench until you make a chair.
Everyone is gansta until the miracle sort comes.
Miracle sort is beautiful
Miracle sort: Hold my process
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.
"...In Java. It's not fast." Man, you're roasting Java so hard.
You are working really hard. Just remember, you are a champion by programming,. So it counts always :))
bro that's the best sorting algorithm!
My brain be like when I'm trying to solve the math problem.
"Bogosort", right?
yes
johnosort
Miracle sort will always be my favorite sorting algorithm that theoretically can succeed.
BOGO SORT!
BOGO SORT!
😹😹😹That's what I call efficiency
this is the worst sorting algorithm and the best at the same time
This is worst than the sleep sort algorithm
For the record, this is called Bogo Sort.
personal favourites: 14:13 for the sounds, 20:05 bc that one is impressive and so cool
Randomizing the numbers until it’s sorted.
That’s kind of BogoS.
I actually managed to sort a list of 10 elements within a second, I feel like a chad now
🏆
I knew Bogo sort was slow, but not THAT slow.
It is the famous Bogo sort
There must exist a universe where Bogo sort is the fastest every time
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
Bogo Sort
Well if you think about it, it could also be the fastest... if you are extremely lucky
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
In an alternate universe, bogo sort will sort any length data 100% of the time, and no one knows why.
I wanted to learn some programming but then i see random characters, letters and numbers and i dont want to anymore 😂
I'm first' time watching this channel and this guy , kasam se ye banda mereko Jony Sins lag rha hai.😂
Vsauce if he was a programmer
You reinvented the wheel (its called bogosort)
Basically Bogo sort
Surprised it took that short lol. We are looking at over 13! permutations here
Bro this is slower than my internet 💀
Ah yes, bogo sort.
I can go slower. While the list is not sorted use the random number generator to select one entry to be swapped, then one different position to swap it in to, including the possibility of swapping that item back into it's original position, then output a complete change log starting from the beginning of time, then check for completion. When complete print the entire change log again ending with the sorted list.
When you realize this is harder to implement than the selection sort, and you did it in an interview💀💀💀
There’s still worse sorting algorithms.
Heard of one where it just does nothing until a bit magically changes its value. (It does nothing)
The best sorting algorithm is miracle sort, you just wait until the list magically sorts itself!
miracle sort:
Hey, but that best case!
Bogo sort lesgooo
The sorting of second number group possibility is one out of 14!.13!. ……. To 1!. That’s INSANE and VERY HUUUUUGE.
You kind of look like Michael from Vsauce if he were normal
Useful skill for the dean of Greendale
Ctrl + C *switches to notepad.exe* Ctrl + V
Bogo.
The funny thing about BOGO is that it can be both the slowest and the fastest algorithm.
i mean, it has got the potential, now it just need consistency.
The funny thing is, this sorting algorithm is one of the fastest with quantum computers lol.
Gotta love bogosort
Bogo sort XD
you're amazing man 😀
I'd like to introduce you to miracle sort.
O(n²)? Nah, O(n!)
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.
bogo sort
have the same algorithm but instead of sorting it puts money on my wallet lol
Give
You forgot about Bogobogosort
Amazing! Great sorter
It might outpace other algorithms in small lists
Bogosort
"Miracle Sort"?
Fun fact: This is called Bogo sort.
Best case: O(n)
Average case: O(n*n!)
Worst case: ∞
Wouldn’t average be O(n!)
It has a complexity of two to the power of n, I see why it’d take so much time.
Bogo Sort is fastest and slowest at the same time. Use your luck!
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
Bogosort
It’s not the worst sorting algorithm ever…. You could make one that never results in a sorted array, or if that’s disallowed (which would disqualify bogo sort), one that cycles through every possible permutation except the sorted one using the maximum amount of average time/memory between permutations, and then reaching the sorted array as the very last possible permutation.
best case scenario O(1). that should be the marketing title 🐸
Worst case, O(♾️)
The propability of sort a list of n elements by shuffling the elements until you sort the list is (1*100/n!)%
It can be the slowest or the fastest.. if you're astronomically lucky.
Bogo😂Bogo
Use bogosort algorithm to sorting something
Time complexity: O(SENDHELP)
the actual answer is O( (n + 1)! )
finally a worthy enemy
best case: O(1)
average case: O(n!)
Worst case: O(∞)
Bogo sort? More like BOZO sort. Gottem