How to generate subsets of an array - 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

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

This will definitely be useful some day after university. Thanks!
Tried all of these in Ruby. You could replace the string-conversion in the second approach with a few shifts and bit-ands.
Here is my list, sorted by speed (List was 20 elements long, ran each 25 times in jruby):
1. Your 3rd approach (300ms)
2. My version of the 3rd approach (Similar but with more explicit copying) (530ms)
3. 1st approach (recursive) (780ms)
4. 2nd approach without strings but shifts and & instead. (3100ms)
5. 2nd approach with strings. (6500ms)
Let this be a warning to all: Even if a solution looks smart, it might not be the best and if it looks horrible, it might not be too bad.

TheDarkOne
Автор

deserves 1million views. Thanks a lot. Great animation

mohammedhajomar
Автор

Second solution is Classic. Thank you, Bro. Request to make algorithmic problems like this.

satyajitdas
Автор

My solution in Haskell is just 4 lines:

subsets :: [a] -> [[a]]
subsets [] = [[]]
subsets (x:xs) =
subsets xs ++ map (x:) (subsets xs)

xRyann_
Автор

I wasted a lot of time understanding it, thanks to this amazing video I finally understood :).

DheerajKumar-fnzq
Автор

You finally explained it the correct way. Take for example the classic CCI, where they say that subset can be generated with your method (3) and then they code up the method (1). Like, wth why? You are the only one (aside from neet code) that has the code matching up to the explanation. Many build a tree and then use code that clearly doesnt generate that tree.

luigicennini
Автор

-- full implementation of this function in Haskell:

powerset = filterM (const [False, True])

WilcoVerhoef
Автор

2 nd solution is too good.. and this made me to have clear idea of subsets thank you

spoorthisameera
Автор

As always, such a high quality video explaining the ideas very well. Thanks!

jasonzhang
Автор

Pretty Good video, i really enjoy ur content

mauricio_agchannels
Автор

Do javascript tips and tricks videos please ❤️❤️

prudhvichinnam