Struggling many years to understand this,finally gotcha your video and u made my day bro
@alasdairmacintyre93833 жыл бұрын
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
@wrttech4223 жыл бұрын
I am glad it was helpful!
@lindgren.bjorn14 жыл бұрын
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.
@wrttech4224 жыл бұрын
Glad it helped! I have many more python/ java tutorials with many more to come in the future.
@yiqiongxiao52554 жыл бұрын
i struggled so much to understand permutation and this video is so far the best. detailed explanation! awesome and thank you so much
@wrttech4224 жыл бұрын
Glad it helped!
@zeroanims41133 жыл бұрын
@Gertrudis Gahn bruh
@peytonfrancis48693 жыл бұрын
sorry to be so offtopic but does anybody know a method to get back into an Instagram account? I was dumb forgot the login password. I love any help you can offer me!
@augustryker68223 жыл бұрын
@Peyton Francis instablaster :)
@peytonfrancis48693 жыл бұрын
@August Ryker thanks for your reply. I found the site thru google and im waiting for the hacking stuff now. Looks like it's gonna take quite some time so I will get back to you later when my account password hopefully is recovered.
@crowsnsuch Жыл бұрын
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
@wrttech422 Жыл бұрын
Great to hear!
@MuratJumashev2 жыл бұрын
This video deserves more views! You nailed it!!!
@CrushOfSiel Жыл бұрын
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...
@wrttech422 Жыл бұрын
It just takes a lot of practice. Eventually, problems like this will come a lot easier. If you're new to recursion you should be proud you got as far as you did, because it takes most people a long time before they can solve recursion problems on their own.
@CrushOfSiel Жыл бұрын
@@wrttech422 Thank you for the encouragement. I think I'm slowly getting it more and more. I coded Pascal's Triangle today with recursion. My first attempt worked but it was horrendously slow if I wanted a row larger than n=12. I found another version online after trying and failing to make mine run faster with a dictionary (memoization). The solution I found was very similar to this solution so I guess with practice the pattern will just become easier.
@opinions8923 жыл бұрын
Your solution rocks my friend ... returns love from India...
@harshsaxena77164 жыл бұрын
this solution deserves a like ..best explanation
@wrttech4224 жыл бұрын
Glad you think so!
@hoanghuynh411011 ай бұрын
Love it, due to u with visual explanation, i comprehend now
@kevinyuan5232 Жыл бұрын
best video explanation of recursion, bro deserves a W👍
@wrttech422 Жыл бұрын
Glad you liked it!
@Strawlocka7 ай бұрын
you're a life saver. Thank you for making this video
@wrttech4227 ай бұрын
Glad it helped!
@vivekshinde21074 жыл бұрын
banged head hundred times to understand this..thank u for making it so simple
@wrttech4224 жыл бұрын
Glad it helped!
@AlI-xy9jx2 жыл бұрын
Your explanation was the best! Thank you so much. I haave been stuck on this for so long.
@kushalhu71894 жыл бұрын
THE best Explanation in youtube..............
@victor.novorski3 жыл бұрын
Saw you in that Rabbit getting scared by its own fart....... Now your subscriber
@fardeendingankar73182 жыл бұрын
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
@amitupadhyay65113 жыл бұрын
Perfect explaination, you sit, take a bow
@mrKnown012 жыл бұрын
This is best available code and explaination i guess
@TutonicKnight4 жыл бұрын
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
@rajrathod32284 жыл бұрын
You made the rock edible for me
@ahyungrocks550910 ай бұрын
Wonderful explanation. The question is how am I suppose come up with this if I haven't seen your video? Recursion is very difficult for folks who don't program everyday.
@chakoladavidpaul3920 Жыл бұрын
Thank you, the video has been really helpful, just wanted to point out one error if I may , i.e. at 17:06 for bc would be (abc,bac,*bca instead of cab)
@wrttech422 Жыл бұрын
yes, you are correct
@tigranhayrapetyan83572 жыл бұрын
Tnank you! It was very helpful explanation how it works
@xaoqi11573 жыл бұрын
thanks for this video,the explanation is amazing!
@dbz11323 жыл бұрын
Very well Explained 🔥🔥
@ajitdhobale68262 жыл бұрын
Thanks for this video - great explanation! One request - can you please add time and space complexity to this video?
@tigranhayrapetyan83572 жыл бұрын
I think time coplexity is O(n!)
@sidharthpunathil4 жыл бұрын
Keep going! :) please don't stop.
@cincyohio19464 жыл бұрын
Great video! Very Informative
@glennarandilla51934 жыл бұрын
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
@sebastianvasquez8052 жыл бұрын
Thank you so much for this video!
@vinimoreira16 Жыл бұрын
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
@jonsentio3150 Жыл бұрын
man i can truly relate to that! shi is scaring me
@walaamaklad1813 жыл бұрын
can you do with repetition of the char
@wagishasingh_22033 жыл бұрын
You r amazing sir thank you very much
@walaamaklad1813 жыл бұрын
what should we change
@vladkojancar40073 жыл бұрын
does it also cover cases like: aabc ? wont there be like twice as much permutations than there should be ?
@wrttech4223 жыл бұрын
The function returns all permutations of the string you provide as input. a and a are separate characters and will be included in the output list. There will be 4! permutations just like there will be 4! permutations of any other string of length 4.
@vladkojancar40073 жыл бұрын
@@wrttech422 I understand, so the goal isn't to find all possible permutation for mashed-up string, but for characters in it. BTW very thanks! Your video helped me. Not just with this permutating problem, but also with imrpoving my implementation skills of recursion-typed algorithms 😂🙏.
@everyzan-m2q2 жыл бұрын
You are an absolute chad
@julietgenshin51934 жыл бұрын
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?
@wrttech4224 жыл бұрын
Thats a bit more complicated, but ill be making a video on it soon.
@julietgenshin51934 жыл бұрын
@@wrttech422 thank you sir Im looking forward to it. Also, what if i want certain conditions? For example, the third digit needs to be 2?, what happends then?
@danirieg99106 ай бұрын
thanks so much! just a thought: this doesn't account for repetition of letters. for example if you input 'aba', it will give you 6 solutions but there are only three.
@wrttech4226 ай бұрын
Yeah forsure! This is a solution for all possible permutations of every character irrespective of frequency. You're correct; 'aba' will return 6 permutations since there are 3 characters.(3!)
@lepuzki Жыл бұрын
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.
@wrttech422 Жыл бұрын
There is no super efficient algorithm to solve this problem (ie: O(n), O(n log n), O(n^2) etc)
@elizabethmoukit84824 жыл бұрын
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.)
@natnaelberhane31412 жыл бұрын
I was thinking the exact same thing!
@wrttech4222 жыл бұрын
Recursion and for loops are 2 completely different things. They can be used together, or independent of one another.
@jackzhao43022 жыл бұрын
Thank you for this. Very helpful! A quick question, when you got result=['bc', 'cb'], then why perms become ['bc', 'cb']?
@myfuzzyanimals672 жыл бұрын
Try watching this video on GCD with recursion. kzbin.info/www/bejne/lZnGdGykbc99j7s Its his video, but he explains call stacks a bit better in it. Start at the visualization part around 4:20.
@vishakhasangtani33542 жыл бұрын
Can someone please help me with time and space complexities here?
@emmanuelc.opeter3 жыл бұрын
Nice video, but for the second iteration, why did you use the range function and added +1
@wrttech4223 жыл бұрын
I explain it in the video and again in the visualization of the code, but it is because we need to append the char variable in every possible position. the range function is non inclusive which means for the last iteration, the char variable will be appended to the end .
@LNMLucasMasiero4 жыл бұрын
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
@wrttech4224 жыл бұрын
Absolutely. Recursion is particularly useful when we have problems that can be broken down into smaller repetitive problems. It is especially good for working on things that have many possible branches and are too complex for an iterative approach. So instead of finding all possible permutations of the word cold, length 4, we could instead find all possible permutations of the last letter(length 1). All possible permutations of d, is just d. We could then find all possible permutations of 'ld' by just appending l in every possible position in our list of all possible permutations of d. That would give us [ld, dl]. We keep doing this until we have reached the first letter in our word, giving us all possible permutations of the word cold. So this is what it would look like with the word cold: -all possible permutations of d: result = ['d'] -all possible permutations of ld: (by appending l to all possible positions in our result list) result = ['ld', 'dl'] -all possible permutations of old: (by appending o to all possible positions in our result list) result = ['old', 'lod', 'ldo', 'odl', 'dol', 'dlo'] -all possible permutations of cold: (by appending c to all possible positions in our result list) result = ['cold', 'ocld', 'olcd', 'oldc', 'clod', 'lcod', 'locd', 'lodc', 'cldo', 'lcdo', 'ldco', 'ldoc', 'codl', 'ocdl', 'odcl', 'odlc', 'cdol', 'dcol', 'docl', 'dolc', 'cdlo', 'dclo', 'dlco', 'dloc'] and this works for words of any length.
@LNMLucasMasiero4 жыл бұрын
@@wrttech422 awesome. Thanks you again. ❤️❤️❤️
@jodecibirkenfeld19433 жыл бұрын
What coding program is this and where do I download it?
@aradog32133 жыл бұрын
its called pycharm its much better nowadays
@bhimeshk48662 жыл бұрын
Thank you so much!!!
@janghyukboo61134 жыл бұрын
Thanks a lot
@donpilarsuarezgudino51602 жыл бұрын
If I don`t find the result by my own, should I quit programming learning?
@wrttech4222 жыл бұрын
Definitely not. You should keep practicing and eventually you'll be able to do problems harder than this on your own. Most people cant solve problems like this at first. It takes lots of practice.
@Alkarid24 жыл бұрын
Hi I think at 17:05 the string should be ‘bca’ and not ‘cab’
@wrttech4224 жыл бұрын
Youre correct. Thats what i was meaning to write
@kspv28063 жыл бұрын
thanks a lot man
@keebdude2 жыл бұрын
Thank you 8^)
@vitorpmh Жыл бұрын
this is fucking great, thx
@abemanyukumar8709 Жыл бұрын
give me a code pls
@aradog32133 жыл бұрын
it doesnt word anymore i dont know why here is my code:
@aradog32133 жыл бұрын
def permutations(word): if len(word) == 1: return [word] perms = word[1:] letter = word[0] result = [] for perm in perms: for x in range(len(perm) + 1): result.append(perm[:x] + letter + perm[x:]) return result print(permutations("abcd"))
@wrttech4223 жыл бұрын
Because you're not recursively calling the permutations function. line 4 should be perms = permutations(word[1:]) not perms = word[1:]
@aradog32133 жыл бұрын
@@wrttech422 oh ok thanks!
@ألشعوبتحيابالعلم-ق6ز3 жыл бұрын
Peace be upon you. Can you add the Arabic translation to your videos please🙃🌹
paste your code below and ill fix it and tell you what's wrong.
@ulaitor41862 жыл бұрын
@@wrttech422 def do_permutation(word): if len(word) == 1: return [word] perms = do_permutation(word[1:]) char = word[0] result = [] for perm in perms: for i in range(len(perm)+1): result.append(perm[:1]+ char + perm[:i]) return result print(do_permutation("abc"))
@wrttech4222 жыл бұрын
@@ulaitor4186 you just had a small issue on the line that contains: result.append(perm[:1]+ char + perm[:i]) perm[:1] should = perm[:i] The perm[:i] after the concatenation of the char variable should = perm[i:] The correct code is below. Copy and paste it into your IDE/text editor def do_permutation(word): if len(word) == 1: return [word] perms = do_permutation(word[1:]) char = word[0] result = [] for perm in perms: for i in range(len(perm)+1): result.append(perm[:i]+ char + perm[i:]) return result print(do_permutation("abc")) For a better understanding of the code inside the for loop, I suggest you look at the visualization of the code in the video that starts at 6:54
@ulaitor41862 жыл бұрын
@@wrttech422 You're simply the best, wish we could talk further, you can drop any of your available handles, I'll hit you up.
@wrttech4222 жыл бұрын
@@ulaitor4186 I appreciate that! At this time I am only available on KZbin, but I intend to branch out further once I start making higher quality machine learning, data structures, and algorithms videos.