Python - All Possible Permutations w/ Recursion

Python - All Possible Permutations w/ Recursion

Wrt Tech

4 года назад

40,922 Просмотров

Ссылки и html тэги не поддерживаются


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

@CrushOfSiel
@CrushOfSiel - 25.10.2023 02:19

Damn, I was so close to the answer. I just couldn't write the whole thing in any correct order. I had the base case, I knew I needed a loop somewhere with perm[:i] + char + perm[i:] and I knew I needed the function to call itself but I just could'nt put it all together >< so frustrating. Your solution makes perfect sense but I don't know if I could ever get that to all come out of my head the correct way. It seems so complicated, building a list, doing the permutations, going through the list to add more complex permutations...

Ответить
@kevinyuan5232
@kevinyuan5232 - 05.09.2023 08:55

best video explanation of recursion, bro deserves a W👍

Ответить
@abemanyukumar8709
@abemanyukumar8709 - 18.06.2023 18:17

give me a code pls

Ответить
@vinimoreira16
@vinimoreira16 - 04.05.2023 05:51

dont know why i can solve really large and complex problems but when it comes to recursion, no matter the complexity, my brain just freezes LoL

Ответить
@vitorpmh
@vitorpmh - 15.04.2023 17:28

this is fucking great, thx

Ответить
@lepuzki
@lepuzki - 12.01.2023 16:16

This is a nice solution for a few letters but what would be a better algorithm than this? obviously it cant find permutations for let's say 12 characters.

Ответить
@pau657
@pau657 - 31.12.2022 23:59

Dude, I seriously cannot thank you enough for this video. I was struggling with the idea of recursion and you filled in the gaps in my knowledge. Thanks a million

Ответить
@tigranhayrapetyan8357
@tigranhayrapetyan8357 - 30.10.2022 09:49

Tnank you! It was very helpful explanation how it works

Ответить
@ulaitor4186
@ulaitor4186 - 27.09.2022 22:19

I'm getting this instead;
['ca', 'cac', 'cacb', 'ca', 'cac', 'cacb', 'cacbc']

Ответить
@jackzhao4302
@jackzhao4302 - 17.08.2022 00:21

Thank you for this. Very helpful! A quick question, when you got result=['bc', 'cb'], then why perms become ['bc', 'cb']?

Ответить
@MuratJumashev
@MuratJumashev - 26.06.2022 11:05

This video deserves more views! You nailed it!!!

Ответить
@everyzylrian
@everyzylrian - 02.06.2022 07:51

You are an absolute chad

Ответить
@bhimeshk4866
@bhimeshk4866 - 03.05.2022 15:34

Thank you so much!!!

Ответить
@vishakhasangtani3354
@vishakhasangtani3354 - 18.03.2022 15:07

Can someone please help me with time and space complexities here?

Ответить
@sebastianvasquez805
@sebastianvasquez805 - 12.03.2022 18:42

Thank you so much for this video!

Ответить
@AlI-xy9jx
@AlI-xy9jx - 09.03.2022 03:35

Your explanation was the best! Thank you so much. I haave been stuck on this for so long.

Ответить
@keebdude
@keebdude - 28.02.2022 23:45

Thank you 8^)

Ответить
@ajitdhobale6826
@ajitdhobale6826 - 26.02.2022 23:43

Thanks for this video - great explanation!
One request - can you please add time and space complexity to this video?

Ответить
@mrKnown01
@mrKnown01 - 20.02.2022 19:41

This is best available code and explaination i guess

Ответить
@fardeendingankar7318
@fardeendingankar7318 - 08.02.2022 12:47

Trust me man you just nailed this i was trying for long to get being from non-Cs background it was difficult to digest but hats off to you

Ответить
@donpilarsuarezgudino5160
@donpilarsuarezgudino5160 - 10.01.2022 20:14

If I don`t find the result by my own, should I quit programming learning?

Ответить
@emmanuelc.opeters4718
@emmanuelc.opeters4718 - 01.12.2021 21:01

Nice video, but for the second iteration, why did you use the range function and added +1

Ответить
@opinions892
@opinions892 - 01.11.2021 02:07

Your solution rocks my friend
... returns love from India...

Ответить
@xaoqi1157
@xaoqi1157 - 11.10.2021 17:12

thanks for this video,the explanation is amazing!

Ответить
@amitupadhyay6511
@amitupadhyay6511 - 04.08.2021 01:29

Perfect explaination, you sit, take a bow

Ответить
@dbz1132
@dbz1132 - 26.07.2021 11:35

Very well Explained 🔥🔥

Ответить
@walaamaklad181
@walaamaklad181 - 11.06.2021 08:58

what should we change

Ответить
@walaamaklad181
@walaamaklad181 - 11.06.2021 08:49

can you do with repetition of the char

Ответить
@kspv2806
@kspv2806 - 02.06.2021 01:43

thanks a lot man

Ответить
@wagishasingh_2203
@wagishasingh_2203 - 13.04.2021 08:54

You r amazing sir thank you very much

Ответить
@aradog3213
@aradog3213 - 04.04.2021 00:32

it doesnt word anymore i dont know why here is my code:

Ответить
@jodecibirkenfeld1943
@jodecibirkenfeld1943 - 01.04.2021 05:54

What coding program is this and where do I download it?

Ответить
@victor.novorski
@victor.novorski - 18.03.2021 13:36

Saw you in that Rabbit getting scared by its own fart.......

Now your subscriber

Ответить
@user-rp8ip4ik5d
@user-rp8ip4ik5d - 10.02.2021 16:35

Peace be upon you. Can you add the Arabic translation to your videos please🙃🌹

Ответить
@vladkojancar4007
@vladkojancar4007 - 30.01.2021 15:43

does it also cover cases like: aabc ? wont there be like twice as much permutations than there should be ?

Ответить
@alasdairmacintyre9383
@alasdairmacintyre9383 - 30.12.2020 22:47

Dude thank you for that simple explanation "2nd function call, first recursive call." I have been trying to wrap my mind around how code like this works but you really simplified it

Ответить
@julietgenshin5193
@julietgenshin5193 - 16.12.2020 06:23

how do I do it if i want every permutation of a specific length? If my string is ABCS but only wants the permutations of length 3?

Ответить
@glennarandilla5193
@glennarandilla5193 - 06.12.2020 12:29

Hi Wrt Tech I'm new in python and my cousin looking for the solution
on this kind of assignment. you might solve this. Please help.
I'm trying your video tutorial on this matter.


PERMUTATION OF LIST OF STRINGS


Given a list of strings such as arr = ["abc", "de", "fgh"], cycle through/print all the combinations starting from the first word to the last. Implement the recursive function as f(index) and implement a global variable called build for your solution. You may also use global variables to track the number of strings in the list, and the list of strings itself. Input Format

The first line of the input contains n, the number of strings to read The next n lines contains strings composed of small-case alphabetical characters only

Constraints

1 <= n <= 6 1 <= length_of_each_string <= 6 Output Format

permutation1 permutation2 ... permutationK

How should I write the code if the inputs and outputs look like this.

Sample Input 0

3

abc

de fgh

Sample Output 0

adf

adg

adh

aef

aeg

aeh

bdf

bdg

bdh

Ответить
@rajrathod3228
@rajrathod3228 - 17.11.2020 15:36

You made the rock edible for me

Ответить
@Mullemeck83
@Mullemeck83 - 12.11.2020 23:14

Thank a lot, especially for visualizing the execution of the code. It made me fully understand the solution. I have struggled with permutations and have seen a couple of other explanations/solutions, but yours is the only one that walked through the execution in detail and thus made me really understand the code.

Ответить
@TutonicKnight
@TutonicKnight - 02.11.2020 23:19

Thanks for the video. I've been racking my brain on this for a few days because i was under the impression that the return needed to be the function call...

My brain kept coming back to having the recursive call go into a variable, but thought it wasn't allowed in a recursive function. Turns out i failed because i was too strict about what i thought the "rules" were... lol

Here's an updoot and a sub :P

Ответить
@janghyukboo6113
@janghyukboo6113 - 31.10.2020 05:19

Thanks a lot

Ответить
@yiqiongxiao5255
@yiqiongxiao5255 - 30.10.2020 01:27

i struggled so much to understand permutation and this video is so far the best. detailed explanation! awesome and thank you so much

Ответить
@sidharthpunathil
@sidharthpunathil - 25.09.2020 16:02

Keep going! :) please don't stop.

Ответить
@LNMLucasMasiero
@LNMLucasMasiero - 24.09.2020 20:24

Thanks you sooooo soooo much. I was wondering how to do that... I first start looking for patterns. Like for example, using numpy.... with word 'cold'... which is a 4 letter's word... so it means 24 posibble permutations... then i divided by lenght of the word (4) and got that every letter would have to be on the first posittion 6 times... so it would be something like below.... and then repeating thesame for each colum... but it needs to use conditionals to don't take the letter that was in the first column to aviod repetitions.... so i decide to look for something more simple and the answer was tooo much simple but not for me easy to understand it... Thanks you sooo mch ♥♥♥
c x x x
c x x x
c x x x
c x x x
c x x x
c x x x
o x x x
o x x x
o x x x
o x x x
o x x x
o x x x
l x x x
l x x x
l x x x
l x x x
l x x x
l x x x
d x x x
d x x x
d x x x
d x x x
d x x x
d x x x

Ответить
@harshsaxena7716
@harshsaxena7716 - 12.08.2020 10:15

this solution deserves a like ..best explanation

Ответить
@elizabethmoukit8482
@elizabethmoukit8482 - 12.08.2020 04:32

Can a recursive funtion use a for loop? I thought recursion was used instead of a for or while loop.( sorry if this is a dumb question, i'm new to this lol.)

Ответить