String permutation algorithm | All permutations of a string
Vložit
- čas přidán 17. 05. 2019
- This lecture explains how to find and print all the permutations of a given string. This lecture involves two example explanations followed by code logic explanation for printing and finding all permutations of a string. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)
CODE LINK: drive.google.com/open?id=1Lwv...
🟣 JOIN our 𝐋𝐈𝐕𝐄 𝐢𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐭𝐫𝐚𝐢𝐧𝐢𝐧𝐠 𝐩𝐫𝐨𝐠𝐫𝐚𝐦 through whatsapp query: +91 8918633037
🔴 𝐂𝐡𝐞𝐜𝐤𝐨𝐮𝐭 𝐚𝐥𝐥 𝐨𝐮𝐫 𝐂𝐨𝐮𝐫𝐬𝐞𝐬: techdose.co.in/
You are a magician, you can make someone believe in himself/herself and not give up on dreams. God bless you.
Love it. Time and time again, I come back to your channel when I need a REALLY good grasp of something that is not explained well in leetcode. Thank you!
I always had a fear when it comes to find permutation, you have explained it in a very simple way. Thanks a lot!!!!
Very clear explanation. Finally understand why we need the backtracking after the recall of permute. Thank you very much.
Welcome :)
awesome explaination sir.Now I got clear understanding on what is backtracking.Thank you so much
Those who have tried coding knows the complexity of outputs for this case where elements of string is not repeating
Thumbs up bro
Thanks :)
Pro trick : you can watch series at flixzone. Me and my gf have been using it for watching lots of of movies these days.
@Mitchell Baylor Definitely, have been watching on flixzone} for months myself =)
@Mitchell Baylor Yup, been watching on Flixzone} for years myself :)
@Mitchell Baylor yup, have been using Flixzone} for since november myself :D
This perhaps used to be one of those problems, which I always use to try in my school life, but could never solve it using for loops, but now in grad life, it has changed!
:)
Thank you! I saw so many blogs and videos with the tree and the code separate. Yours was the first to connect the tree to the code directly! Now I can understand what the swaps are doing exactly and how the iteration works.
Nice 😊
Very nicely explained. I saw many videos to understand this, but this was super clear
Dude you know what, your method is the most intuitive method I have seen on youtube. Awesome job!!
Thanks :)
Yes true.
This is very helpful for me. Thank you. Very good presentation. Now I totally understand the string permutation. The dry run of algorithm is very helpful and impressive.
Thanks :) glad that you understood
Thank you so much, your explanation is very easy than others. Its very difficult to understand permutation with recursion, but this makes it easy
Thanks 😊
I saw this video and went on to explore your playlist and finally subscribed you..LOL. Awesome explanation. I wish you had a second part with DUPLICATE STRINGS.
Will do it later. I am loaded with question requests now :)
This is for the first time I try to understand it and You nailed it.
Thank you
Your explanation of the permutation problem is better than most other explanations on the Internet.
Thanks :)
Best explaination I've ever took. Really appriciate it!
By far the best explanation of this problem on you tube. Thanks much!
I was able to code this easily after watching your explanation. That was a great explanation.
Nice 😊
Finally Understood it..thanks a lot for the detailed explanation of the algo..
Nice :)
Beautifully Explained Sir...Thanks a lot!!!
I watched NeetCode explenation of this problem probably 5 times and could not understand how logic behind it actually relates to code solution. Watching this explenation helped me understand code behind the solution instantly, because logic presented in drawning explenation is simple and actualy demonstrates code logic.
Amazing!! This worked like a charm )) at my first try
I have been trying for many days different tutorials but no one explained as good and easy as you, Thank you so much
Great :)
from all the explanation this is one of the most easiest way one can explain,thanks👏👏
Everytime I found best explanation only in this channel.
Thanks Man
Welcome :)
Really wonderful explanation .all the doubts in string permutations got cleared.
Thank You so much, your lecture is very clear and elaborative.
Best explanation I could ever get. 👏
I always confused with permutation, I mean how to implement permutation in coding but after your explanation, I got the logic of how to code this thank you Sir.
Welcome
@@techdose4u thanks a lot
I am floored, dude u earned a sub...
Thanks :)
Thank you for explaining it, best of all I have seen.
Welcome :)
Great explanation!
wow, this is very well explained, especially I liked how you wrote on branches swapping you do. Thanks a lot
I forgot how to write permutations but need to write such an algorithm for a project I'm doing in recreational maths. Thanks for explaining it :) I was thinking "recursion" so I'm glad you did that approach. I'm gonna write something up in python now
Good luck
This explaination is so easy to understand, thankyou!
This is actually the best explaination thnx alot sir.
Awesome, thanks for the good explanation
This is a great explanation!!!!!!
Today is 2022 and you made this in 2019 . Like 3 year still 96.2k subscribers . You deseve 1M sadly you and i know indians love clickbait stuff . 96.2K shows you are best at teaching not at Clickbait . Keep up the good work sir : )
Thanks 😊
Shut up goofball
your videos are always awesome and ofcourse so much informative & easy to understand ... Thnx 🙏🙏
This is the best explanation on this problem.
Thanks a lot♥♥ , your explanation is so good the just looking at your pseudo code I am able to code the problem.😊😊
Thanks bro...you are the best.
Thanks man, this video is really clear.
Glad it helped!
Finally understood recursive tree...awesome explanation..going to watch ur full playlist :)
Thanks :)
Thanks a lot sir. You explained very well!!
Welcome ☺️
just found this gem :) , subscribed !
Thanks :)
This is so much clear explanation indeed.
Thanks
You are great. Nice and thank-you
Very well explained. Thank you !
Welcome
The best tutorial ever..
Thanks :)
Wow... Clear explanation thanks brother : )
Welcome
Very helpful!
thank you , this video help me a lot to understand the topicc
Thank you so much
Perfect explanation 👌
Thanks :)
thank you very much sir for this explanation
Great Explanation, Thanks a lot!
Welcome :)
Thx ur video was of great help
Wow! I found this explanation very helpful and simple to understand. Thanks for this!
Welcome :)
Very helpful brother. 🤞🏻Thanks
FINALLY UNDERSTOOD!!!!!!
Nice :)
very good explanation !!
really a great explanation and its easy to understand...thanks for all your time. It will be helpful if you can also explain how to handle if the character is duplicate. Thanks
Yea you are ryt. This doesn't handle duplicate characters. I will try to make this case in future.
How can we implement this for string having duplicates?
I think this method won't work for duplicates. It will count the duplicates as separate characters.
Eg.- ABAC. In this case total no. of permutations possible would be 12 (4!/2!).
However, if we follow this method it will end up 24 (4!) combinations, simply because it counts the first and the second occurrence of A as different alphabets.
Meaning - in ABAC, if A in the first place is swapped with A in third place we end up with the same string ABAC, whereas the above logic treats them as different.
(This can be taken care of if we use a counter for each character).
If you want to remove duplicates. just you will add all Strings into HasSet.
store all results in a vector of strings and then youd be able to filter the duplicates
Awesome explanation.Loved it
Thanks :)
Sir i haven't understood what is the need of second swap function, if we didn't write then also it will backtrack go to original string that is ABC?
good explanation. It really helped!!!
Welcome :)
Good explanation. Thanks for sharing. Keep it up. All the best for your future.
Excellent bro...keep uploading..I like your teaching..and great content....:)
Thanks :)
The best explanation.
Thanks :)
Hi,
Can any one tell how this swap function works in C++...
swap((a+l), (a+i));
I am not familiar in c++ and so I don't understand why we are passing the char array (a) + int (index l / i) in swap function
The visualization technique is quite helpful in understanding the algorithms .. Thanks a lot TECH DOSE :)
Thanks
salute you sir, thanks you so much to make it
so cool! thanks dude!
Welcome :)
Thanks for the efforts man. This helps a lot. Keep up the good work.
Welcome :)
Thanks man!
Great explanation. Thank you very much
Welcome 😁
interview in 20mins...thank god i watched this
You got it!!
@@techdose4u thank u so much for the reply 😭
@@techdose4u Update: I got placed 😭
Easier is(without swapping):
def permut(str,k):
if len(str)==0:
print(k)
else:
for i in range(len(str)):
permut(str[i+1:]+str[:i],k+str[i])
Thanks sir finally understood it
😍thak gya hu vro iski video like kr krke
:)
Awesome explanation..
Really good explanation.
Thanks sir.Your video was very good for a beginner
Great ❤️
Thank you for the explanation! I had a question about the runtime complexity : you mentioned that it takes O(n) time to perform one permutation because the depth of the tree is n. However, after you’ve printed out ABCD on the bottom left, would you not backtrack up to ABCD of level 3, then go down to level 4 to print ABDC. Would that not make ABDC’s permutation time complexity O(1) since we don’t repeat the other above recursive calls? Or is that not how it works? Any clarification would be helpful. Thanks!
No, actually you need to calculate worst case time. Let's say string length is 100 and so tree depth is 100. Now only the last characters can be exchanged in 0(1) but suppose we backtracked to level 50 and we want to again come down to the leaf. Will this be O(1)? No.
swap(a+l,a+i);
permute(str,l+1,r);
if [l=0, i=0 A-A swaps] , [ l=1, i=1 B-B swaps] , [l=3, i=3 and so C-C] should swap ? at 2:31
as l changes on each recursive call so do i.
How is it getting swapped i cannot catch ?
1:15 what you need to understand!!! Thanx sir!
I don't know why was this video not on top of suggestions =(
My mind is exhausted, but still I am able to understand, thanks a lot.
Welcome :)
if your string is not called by reference (immutable) then you don't need to do that backtrack thing right? FOr some reason, this method doesn't work or JS, no idea why.
Comment to banta hai boss for your explanation.....
Thanks
Hey the code which u have provided in description doesn't handle duplicate character. Meaning if string is ABC then its perfect but if its ABB then it will repeat few of the string
Superb! Keep teaching
Thanks :)
Hello sir
I m confused how the code will jump to last line of for loop skipping the function call
you explained with god level
Thanks :)
very good explanation,,, as always
Thanks
this was helpful
Love the explanation, I have a better visualization now.
Thanks bro!
Excellent explanation! Great work👌👌
Thanks
@@techdose4u I have one doubt though.... Why do we need the second swap function? It works without that too... Recursion works that way right?