String permutation algorithm | All permutations of a string

Sdílet
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...

Komentáře • 398

  • @techdose4u
    @techdose4u  Před 9 měsíci +1

    🟣 JOIN our 𝐋𝐈𝐕𝐄 𝐢𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐭𝐫𝐚𝐢𝐧𝐢𝐧𝐠 𝐩𝐫𝐨𝐠𝐫𝐚𝐦 through whatsapp query: +91 8918633037
    🔴 𝐂𝐡𝐞𝐜𝐤𝐨𝐮𝐭 𝐚𝐥𝐥 𝐨𝐮𝐫 𝐂𝐨𝐮𝐫𝐬𝐞𝐬: techdose.co.in/

  • @rhishishrivastava675
    @rhishishrivastava675 Před měsícem +2

    You are a magician, you can make someone believe in himself/herself and not give up on dreams. God bless you.

  • @vcfirefox
    @vcfirefox Před 2 lety +8

    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!

  • @prashantagarwal8877
    @prashantagarwal8877 Před 2 lety +52

    I always had a fear when it comes to find permutation, you have explained it in a very simple way. Thanks a lot!!!!

  • @lancema2894
    @lancema2894 Před 4 lety +36

    Very clear explanation. Finally understand why we need the backtracking after the recall of permute. Thank you very much.

  • @feelgood0108
    @feelgood0108 Před 5 lety +7

    awesome explaination sir.Now I got clear understanding on what is backtracking.Thank you so much

  • @faizanzahid490
    @faizanzahid490 Před 4 lety +82

    Those who have tried coding knows the complexity of outputs for this case where elements of string is not repeating
    Thumbs up bro

    • @techdose4u
      @techdose4u  Před 4 lety +4

      Thanks :)

    • @mitchellbaylor8132
      @mitchellbaylor8132 Před 3 lety

      Pro trick : you can watch series at flixzone. Me and my gf have been using it for watching lots of of movies these days.

    • @graysonalan44
      @graysonalan44 Před 3 lety

      @Mitchell Baylor Definitely, have been watching on flixzone} for months myself =)

    • @hectorotis512
      @hectorotis512 Před 3 lety

      @Mitchell Baylor Yup, been watching on Flixzone} for years myself :)

    • @alexanderamos9961
      @alexanderamos9961 Před 3 lety

      @Mitchell Baylor yup, have been using Flixzone} for since november myself :D

  • @aayushsugandh4036
    @aayushsugandh4036 Před 4 lety +13

    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!

  • @cityhunter1477
    @cityhunter1477 Před 2 lety +2

    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.

  • @jithiny6953
    @jithiny6953 Před 2 lety +3

    Very nicely explained. I saw many videos to understand this, but this was super clear

  • @bitbyte8177
    @bitbyte8177 Před 4 lety +4

    Dude you know what, your method is the most intuitive method I have seen on youtube. Awesome job!!

  • @siddhi1993
    @siddhi1993 Před 3 lety +48

    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.

    • @techdose4u
      @techdose4u  Před 3 lety +5

      Thanks :) glad that you understood

  • @rutachaudhari5774
    @rutachaudhari5774 Před 3 lety +6

    Thank you so much, your explanation is very easy than others. Its very difficult to understand permutation with recursion, but this makes it easy

  • @swapnil1108
    @swapnil1108 Před 4 lety +10

    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.

    • @techdose4u
      @techdose4u  Před 4 lety +1

      Will do it later. I am loaded with question requests now :)

  • @sunilkumaryadav3194
    @sunilkumaryadav3194 Před rokem

    This is for the first time I try to understand it and You nailed it.
    Thank you

  • @JayDonga
    @JayDonga Před 4 lety +18

    Your explanation of the permutation problem is better than most other explanations on the Internet.

  • @duyle-ui4ul
    @duyle-ui4ul Před rokem

    Best explaination I've ever took. Really appriciate it!

  • @user-ok4fx3kl6f
    @user-ok4fx3kl6f Před 9 měsíci

    By far the best explanation of this problem on you tube. Thanks much!

  • @olgyish
    @olgyish Před 3 lety +10

    I was able to code this easily after watching your explanation. That was a great explanation.

  • @debasishpatnaik294
    @debasishpatnaik294 Před 3 lety +4

    Finally Understood it..thanks a lot for the detailed explanation of the algo..

  • @harshpanwar1550
    @harshpanwar1550 Před 3 lety +2

    Beautifully Explained Sir...Thanks a lot!!!

  • @m.p.3688
    @m.p.3688 Před rokem

    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.

  • @Goku-ri3tl
    @Goku-ri3tl Před měsícem

    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

  • @aadridanand
    @aadridanand Před 7 měsíci

    from all the explanation this is one of the most easiest way one can explain,thanks👏👏

  • @shivamgupta3293
    @shivamgupta3293 Před 3 lety +1

    Everytime I found best explanation only in this channel.
    Thanks Man

  • @samudrasen2935
    @samudrasen2935 Před 2 lety

    Really wonderful explanation .all the doubts in string permutations got cleared.

  • @gpavansai7207
    @gpavansai7207 Před rokem +1

    Thank You so much, your lecture is very clear and elaborative.

  • @ranusingh862
    @ranusingh862 Před 2 lety

    Best explanation I could ever get. 👏

  • @bhimsendabby
    @bhimsendabby Před 4 lety +7

    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.

  • @thesadanand6599
    @thesadanand6599 Před 3 lety +6

    I am floored, dude u earned a sub...

  • @rakshitsingh7504
    @rakshitsingh7504 Před 4 lety +1

    Thank you for explaining it, best of all I have seen.

  • @spetsnaz_2
    @spetsnaz_2 Před 5 lety +2

    Great explanation!

  • @markovujanic
    @markovujanic Před rokem

    wow, this is very well explained, especially I liked how you wrote on branches swapping you do. Thanks a lot

  • @ozzyfromspace
    @ozzyfromspace Před 4 lety +4

    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

  • @OP-yw3ws
    @OP-yw3ws Před rokem

    This explaination is so easy to understand, thankyou!

  • @jaskiranmalhotra989
    @jaskiranmalhotra989 Před 3 lety

    This is actually the best explaination thnx alot sir.

  • @vengateshwarang
    @vengateshwarang Před 4 měsíci

    Awesome, thanks for the good explanation

  • @bowenyi-kj3vr
    @bowenyi-kj3vr Před rokem

    This is a great explanation!!!!!!

  • @shreyasvishwakarma8979
    @shreyasvishwakarma8979 Před 2 lety +8

    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 : )

  • @UnknownLearner-od3qn

    your videos are always awesome and ofcourse so much informative & easy to understand ... Thnx 🙏🙏

  • @swanhtet1
    @swanhtet1 Před 2 lety

    This is the best explanation on this problem.

  • @priyanshuchaurasiya6184

    Thanks a lot♥♥ , your explanation is so good the just looking at your pseudo code I am able to code the problem.😊😊

  • @Cybernetic1
    @Cybernetic1 Před 4 lety +1

    Thanks bro...you are the best.

  • @lucasbollella8487
    @lucasbollella8487 Před 6 měsíci +1

    Thanks man, this video is really clear.

  • @tanusrisaha4873
    @tanusrisaha4873 Před 4 lety +1

    Finally understood recursive tree...awesome explanation..going to watch ur full playlist :)

  • @adityaojha2701
    @adityaojha2701 Před 3 lety +4

    Thanks a lot sir. You explained very well!!

  • @suryakangeyan9751
    @suryakangeyan9751 Před 3 lety +1

    just found this gem :) , subscribed !

  • @jugsma6676
    @jugsma6676 Před 4 lety +1

    This is so much clear explanation indeed.

  • @seetharaman6603
    @seetharaman6603 Před 2 lety

    You are great. Nice and thank-you

  • @sejalmah
    @sejalmah Před 3 lety +1

    Very well explained. Thank you !

  • @saisrisai9649
    @saisrisai9649 Před 3 lety +4

    The best tutorial ever..

  • @mallikarjunpidaparthi
    @mallikarjunpidaparthi Před 4 lety +3

    Wow... Clear explanation thanks brother : )

  • @kautukraj
    @kautukraj Před 4 lety +2

    Very helpful!

  • @pawanlok1776
    @pawanlok1776 Před 2 lety

    thank you , this video help me a lot to understand the topicc

  • @hemanthsiripireddy8717
    @hemanthsiripireddy8717 Před 4 lety +1

    Thank you so much
    Perfect explanation 👌

  • @myyoutubeisthis
    @myyoutubeisthis Před rokem

    thank you very much sir for this explanation

  • @debanjanpradhan7633
    @debanjanpradhan7633 Před 2 lety +1

    Great Explanation, Thanks a lot!

  • @user-vn1rx7mp3x
    @user-vn1rx7mp3x Před měsícem

    Thx ur video was of great help

  • @atulkumar-bb7vi
    @atulkumar-bb7vi Před 5 lety +1

    Wow! I found this explanation very helpful and simple to understand. Thanks for this!

  • @theerans723
    @theerans723 Před 2 lety

    Very helpful brother. 🤞🏻Thanks

  • @LegitGamer2345
    @LegitGamer2345 Před 3 lety +1

    FINALLY UNDERSTOOD!!!!!!

  • @debashisdas6593
    @debashisdas6593 Před 2 lety

    very good explanation !!

  • @Ashok-oe3lo
    @Ashok-oe3lo Před 4 lety +4

    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

    • @techdose4u
      @techdose4u  Před 4 lety

      Yea you are ryt. This doesn't handle duplicate characters. I will try to make this case in future.

  • @adithyakiransekar
    @adithyakiransekar Před 3 lety +4

    How can we implement this for string having duplicates?

  • @rohit210995
    @rohit210995 Před 4 lety +7

    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).

    • @gkeranna3543
      @gkeranna3543 Před rokem

      If you want to remove duplicates. just you will add all Strings into HasSet.

    • @georgesaab7609
      @georgesaab7609 Před rokem

      store all results in a vector of strings and then youd be able to filter the duplicates

  • @shailendrakk6226
    @shailendrakk6226 Před 3 lety +1

    Awesome explanation.Loved it

  • @SomnathDas-fg2qc
    @SomnathDas-fg2qc Před 2 lety +1

    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?

  • @shubhampandey7177
    @shubhampandey7177 Před 3 lety +2

    good explanation. It really helped!!!

  • @mr-engin3er
    @mr-engin3er Před rokem

    Good explanation. Thanks for sharing. Keep it up. All the best for your future.

  • @shamshuddinshaik2218
    @shamshuddinshaik2218 Před 4 lety +2

    Excellent bro...keep uploading..I like your teaching..and great content....:)

  • @nagalakshmichithambaranath1147

    The best explanation.

  • @goku_kadhir
    @goku_kadhir Před rokem +1

    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

  • @ChandraShekhar-by3cd
    @ChandraShekhar-by3cd Před 4 lety +6

    The visualization technique is quite helpful in understanding the algorithms .. Thanks a lot TECH DOSE :)

  • @priyasuhag6798
    @priyasuhag6798 Před rokem

    salute you sir, thanks you so much to make it

  • @divyatejaswinivengada6368

    so cool! thanks dude!

  • @kanhashukla6265
    @kanhashukla6265 Před 4 lety +3

    Thanks for the efforts man. This helps a lot. Keep up the good work.

  • @trevorjamesconsideracion1982

    Thanks man!

  • @b_rza
    @b_rza Před rokem +1

    Great explanation. Thank you very much

  • @urvashisharma7415
    @urvashisharma7415 Před 2 lety +1

    interview in 20mins...thank god i watched this

  • @ashutoshbichare
    @ashutoshbichare Před 3 lety +6

    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])

  • @shaamidrees6036
    @shaamidrees6036 Před 2 lety

    Thanks sir finally understood it

  • @kartikenbarnwal
    @kartikenbarnwal Před 3 lety +1

    😍thak gya hu vro iski video like kr krke

  • @kallurijayakumar3850
    @kallurijayakumar3850 Před 3 lety

    Awesome explanation..

  • @biowar5539
    @biowar5539 Před 2 lety

    Really good explanation.

  • @idontusecryptocurrency5870

    Thanks sir.Your video was very good for a beginner

  • @vanessachen6947
    @vanessachen6947 Před 4 lety +3

    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!

    • @techdose4u
      @techdose4u  Před 4 lety +3

      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.

  • @algotorials81
    @algotorials81 Před 3 lety +1

    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 ?

  • @uttarandas8113
    @uttarandas8113 Před 2 lety

    1:15 what you need to understand!!! Thanx sir!
    I don't know why was this video not on top of suggestions =(

  • @jimmy-dk9lo
    @jimmy-dk9lo Před 3 lety +1

    My mind is exhausted, but still I am able to understand, thanks a lot.

  • @amitavamozumder73
    @amitavamozumder73 Před 3 lety +1

    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.

  • @TOMGAMING-hy9hi
    @TOMGAMING-hy9hi Před 3 lety +2

    Comment to banta hai boss for your explanation.....

  • @RajnishSingh-tw4tu
    @RajnishSingh-tw4tu Před 4 lety +1

    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

  • @khakr01
    @khakr01 Před 4 lety +2

    Superb! Keep teaching

  • @souravmissi9234
    @souravmissi9234 Před 2 lety

    Hello sir
    I m confused how the code will jump to last line of for loop skipping the function call

  • @prateekrajput2646
    @prateekrajput2646 Před 3 lety +1

    you explained with god level

  • @glazeds0n
    @glazeds0n Před 3 lety +2

    very good explanation,,, as always

  • @bvwalker1
    @bvwalker1 Před 2 lety

    this was helpful

  • @eugeneyap4208
    @eugeneyap4208 Před rokem

    Love the explanation, I have a better visualization now.

  • @Simon-vj7sk
    @Simon-vj7sk Před 2 lety

    Thanks bro!

  • @kushalappaca5324
    @kushalappaca5324 Před 3 lety +1

    Excellent explanation! Great work👌👌

    • @techdose4u
      @techdose4u  Před 3 lety

      Thanks

    • @kushalappaca5324
      @kushalappaca5324 Před 3 lety +1

      @@techdose4u I have one doubt though.... Why do we need the second swap function? It works without that too... Recursion works that way right?