How to shuffle an array (Fisher-Yates algorithm) - Inside code

preview_player
Показать описание

NB: This video is ad-free, you can choose to support Inside code by purchasing one of the courses above or dropping a super thanks!
NB2: Discounts of courses above are permanent

Рекомендации по теме
Комментарии
Автор

🔴
/ \
🔵—🔴
| |
🔴—🔵

insidecode
Автор

Very clear and visual explanation of Fisher-Yates, including why it's better. I've used the algorithm in my code without really understanding it. Now I do, which feels good. You are great at explaining things!

MartinOmander
Автор

This was fantastic! Very clear way to teach each of the three shuffling algorithms. I wanted to create a shuffling algorithm in Perl in order to learn the language more deeply, and I was able to create the algorithm (Fisher-Yates Modernized) in a very pleasant fashion thanks to your video! Thank you so much and I wish you have a lovely day!

pupper
Автор

I implemented this algorithm myself for shuffling deck of cards without even knowing that it's already a well known algorithm. Saw your video and noticed it

udaywahi
Автор

2:50 bucket sort can be used in this case and it yields a sorting in O(n)

antoine
Автор

Wonderful explanation/solution. You deserve more subscribers!! And success will follow you

ujjvalsharma
Автор

woow, good one, compact, simplified, understandable, just as content in this genre should be, keep up the good work man

einmax
Автор

So clear for the Fisher-Yate shuffle algorithm, thank you so much!

RYS-zrho
Автор

Elegant algorithm, elegant explanation. Thank you.

IsomerMashups
Автор

The linear time solution isn't truly same as the first two because the last element in the array is always moved away. However, it should have a small chance to stay in its original position in the final result. I think we should add an additional swap to fix this.

baitongli
Автор

It would have been great if you said a point about why generating random number would be O(1) because all 3 solutions need it. Nice video!

AdithyaChakilam
Автор

Great! This channel will get more engaged soon!👍

akshayyadav
Автор

can the fisher-yates shuffle start from the first index as long as we keep track of the unshuffled and shuffled part correctly?

angpanha
Автор

what can I say? Brilliant!!! Brilliant!!!

ihgnmah
Автор

Im a little bit confused because shuffle the deck should be completly random, and correct me if im wrong but in the modern version its not really random cause the last index could never be shuffled into the position which kinda make it 100% for the last card to be diifferent which means is not completly random...
am i missing something or is it just the way it designed?

TacticalPrime_
Автор

Interesting. I did this in similar way to third method. I itereted through an array (0, n) then I took random element from range (0, n) and swapped that with the choosen one. Swap(i, rand(0, n) ; I think this is actually a little better beacuse it is shuffling the last element. In your case 7.

MinecraftWitaminaPL
Автор

Can you make a video about the differences between time and space complexity?
Anyway, thanks for the content, you explain it great.

dfgsdgfdoker
Автор

Damn, Fisher and Yates deserve no credit whatsoever lol. I'm calling it the Durstenfeld shuffle from now on.

bp
Автор

short and sweet ...384 leetcode if someone wants to practice in leetcode

rakeshreddypallepati