String Permutation Algorithm

Поделиться
HTML-код
  • Опубликовано: 4 ноя 2024

Комментарии • 269

  • @learningguitar562
    @learningguitar562 8 лет назад +419

    came looking for guitar techniques (finger permutations)
    stayed for the computational algorithms

  • @廖俊翔-e1w
    @廖俊翔-e1w 7 лет назад +141

    A lot of online lectures of great universities expect us to be smart, so they don't go into the problems as detailed. But yes, many of us are that stupid and videos like this are exactly what we need. Really helps me visualize and understand recursion better. Thanks!

    • @jvsnyc
      @jvsnyc 6 лет назад +6

      Nobody is smart in every way, there's bound to be lots of people who can benefit and make use of the knowledge that would find some of the more abstruse or obscure presentations useless to them. This is a great video.

    • @uzairakram899
      @uzairakram899 5 лет назад +3

      No they simply don't have the time and so they expect you to do your own research. Although I do think they should provide a reference.

  • @shreyaboinpally5255
    @shreyaboinpally5255 3 года назад +1

    i have been struggling to understand this,i can't tell u how glad I am to u I found this video.

  • @lalitdudheria7955
    @lalitdudheria7955 8 лет назад +41

    I feel happy every time there is something I don't understand and there is a video by you explaining it. :)

  • @darrenlackey586
    @darrenlackey586 5 лет назад +3

    I've watched many algorithm tutorial videos and this is one of the best. Really appreciate how thorough and detailed it on top of presenting it in an organized manner.

  • @Arunk054
    @Arunk054 6 лет назад +3

    Definitely appreciate the effort this guy has put in. I havent seen anyone teaching with so much patience.

  • @akhilguptavibrantjava
    @akhilguptavibrantjava 8 лет назад +19

    Cool. This tutorial made me understand backtracking like charm. Hats off tushar.Keep doing the good job

    • @RockBrentwood
      @RockBrentwood 4 года назад

      Too complicated. This is much simpler!
      // Found at a UFO crash site.
      // All permutations of 5 items generated.
      #include
      #define N 5
      int main(void) {
      int X[N], Y[N];
      for (int n = 0; n < N; n++) X[n] = Y[n] = n;
      Show:
      for (int n = 0; n < N; n++) printf(" %d", X[n]); putchar('
      ');
      for (int n = 0; n < N; n++) {
      int Xn = X[n]; X[n] = X[Y[n]], X[Y[n]] = Xn;
      if (--Y[n] >= 0) {
      int Xn = X[n]; X[n] = X[Y[n]], X[Y[n]] = Xn; goto Show;
      }
      Y[n] = n;
      }
      return 0;
      }
      (The aliens cited are over here: ruclips.net/video/9dTDhCKBA_c/видео.html )

    • @Rhythmswithruby
      @Rhythmswithruby 4 года назад

      @@RockBrentwood That's basically the same concept except using nested for-loop instead of recursion. Also the variable names are so obscure, it's more difficult to read than Tushar's code at the end of the video.

  • @himanigulati6922
    @himanigulati6922 3 года назад +1

    Finally understood how to go about a backtracking tree. Very helpful thank you!

  • @ErfanHossainShoaib
    @ErfanHossainShoaib 8 лет назад

    I am searching a good algorithm for permutation from last 2 years but I found noting good. But at last I find a good way from here. Your lectures are awesome.

  • @bossysmaxx3327
    @bossysmaxx3327 4 года назад +2

    ghood man ghood, you are rheally an amazing theacher, hats off to you thushar...

  • @SocajowaRS
    @SocajowaRS 4 года назад

    Phenomenal example here especially covering duplicates. Very helpful Tushar.

  • @cocoarecords
    @cocoarecords 5 лет назад +10

    The algorithm is:
    Remove the first letter
    Find all the permutations of the remaining letters (recursive step)
    Reinsert the letter that was removed in every possible location

  • @knlshrvstv
    @knlshrvstv 8 лет назад

    I have seen your other videos and I've learnt from them a lot, but, this is by far the best one! Thanks so much, Tushar.

  • @curiosull
    @curiosull 6 лет назад +127

    He will not go trough all permutations, no way .... Wait...he is 😀

    • @HARSHITKUMAR-wj4ex
      @HARSHITKUMAR-wj4ex 4 года назад +1

      :) :) LOL!!!

    • @akhil291194
      @akhil291194 3 года назад

      Actually I think it is important for us since it helps us understand recursion much more clearly.

  • @relaxwithmusic9036
    @relaxwithmusic9036 4 года назад

    Your efforts are highly appreciable sir

  • @reetigarg7398
    @reetigarg7398 7 лет назад

    This was the best explanation I could find on RUclips. Thanks Tushar !

    • @ThePranjalsh88
      @ThePranjalsh88 6 лет назад +1

      look for the Stanford video on backtracking.. thats good too

  • @Sreejith1729
    @Sreejith1729 8 лет назад +1

    My first comment on youtube! This is a great effort and a very helpful one indeed! Thank you!

  • @RanjanKumar-hs5tt
    @RanjanKumar-hs5tt 8 лет назад

    Thanks Tushar, this really helped me to understand completely which I didn't understand from anywhere

  • @saikishore3954
    @saikishore3954 4 года назад +1

    Nice explanation,
    Incase if any one missed the following point
    Sorting of the given input string is done through Treemap. permuteUtil function prints distinct permutations of a string lexicographically only when the input string is sorted.

  • @san4net
    @san4net 2 года назад +1

    this is an awesome explanation hat off Tushar

  • @Surajkumar-pp6co
    @Surajkumar-pp6co 6 лет назад

    thank you! earlier i was reading this code in quora and i could not understand what the author was doing .. but now through your visuals i understood it better and completely. Thanks again;

  • @dearvivekkumar
    @dearvivekkumar 8 лет назад +1

    Guy ... Your effort is highly apreciated

  • @andielippingwell7747
    @andielippingwell7747 7 лет назад

    Thanks! I went looking for a tutorial on this algorithm thinking I'd have to watch it several time to get it but really understood it in the first 10 minutes. Great video!

  • @abhishekj5325
    @abhishekj5325 8 лет назад +14

    Your effort is highly appreciable :)

  • @MixedMatchedVideos
    @MixedMatchedVideos 8 лет назад +1

    Simply amazing videos. I tried to get the feel of recursion for ages, and finally your video did it.
    Really love the format of your videos and your step-by-step approach of explanation is really what makes learning fun.
    I have tried other channels like saurabhschool etc, but your explanation suits me more.
    One minor suggestions though: if after each video you can leave us with practice problems of similar kind.
    For example, now I've understood this problem and can code it easily. But it will really make my understanding even better if I can apply this knowledge to 2-3 different problems (which uses the same logic). So few practice problems of similar kinds would help.

  • @TonyHang614
    @TonyHang614 4 года назад +1

    Great video - thank you!
    As you expand the permutation graph, I'd suggest you add some sort of 'divider' (removal tape?) to provide an indicator of level.
    great content!

  • @yusufsipahi3916
    @yusufsipahi3916 6 лет назад +3

    Hello,
    The only missing thing I guess is you do not clear the last value in "result" array when backtrack happens. Using stack seems more appropriate I guess.
    Thanks for the share. You did very good job!!!

  • @MrDishajain
    @MrDishajain 8 лет назад

    Awesome Video Tushar :) Excellent explanation of code . Now my concept is clear .

  • @yjh3497
    @yjh3497 7 лет назад

    Best algorithms channel by individual contributor!

  • @044_karan9
    @044_karan9 4 года назад +1

    Excellent explanation .. Thanks for putting so much effort to explain :)

  • @samsharaf5257
    @samsharaf5257 7 лет назад

    Structured, simple and thorough...... Great job!

  • @Venkat2811
    @Venkat2811 8 лет назад

    Nice Video Tushar. You videos always increase the level of my understanding. Thanks :)

  • @radhikadesai666
    @radhikadesai666 6 лет назад

    brilliant. Its quite difficult/tedious to visualize recursion. This video helps a lot! Thanks

  • @MrKrecikKret
    @MrKrecikKret 8 лет назад

    Amazing work, thanks for all the effort you've put into making this video!

  • @malharjajoo7393
    @malharjajoo7393 6 лет назад +5

    Easy summary:
    1) when going into recursion, find leftmost non zero count.
    2) when coming out of recursive call, first move pointer 1 step ahead and then find first non zero count. :)

  • @trybeatingthis
    @trybeatingthis 6 лет назад +2

    According to his algorithm its more like O(k^2 * k!). There are k*k! function calls, but each function loops through k times to see what values have been used before.

  • @Miss_iryna_
    @Miss_iryna_ 8 лет назад

    Thank you so much Tushar! Finally I understand how it works.

  • @pavanomanwar1389
    @pavanomanwar1389 6 лет назад

    Great Job!! He frickin backtracked all the permutations manually.

  • @rudreshdixit8368
    @rudreshdixit8368 4 года назад

    thanks sir. your videos are very insightful and explain every aspect of the problem statement

  • @aliasgar1648
    @aliasgar1648 7 лет назад

    I cant't thank you enough for the awesome videos that you make !!

  • @chandrashekar-pb8ym
    @chandrashekar-pb8ym 8 лет назад

    In this case, The counts determine the how many times we can use the character there by eliminating the dups in the output.
    the character counts along with stack level which controls the result table will decide the permutation. The first for loop will ensure the order of the output. Just sharing my understanding

  • @Leo2002cn
    @Leo2002cn 5 лет назад +1

    This is a very intuitive and understandable algorithm. However, it is not optimal for space complexity due to the extra count[] array to store which chars are used or not. There are more space efficient algorithms for permutation.

  • @aswinram8744
    @aswinram8744 3 года назад

    Thanks a lot. Amazing clarity in explanation :)

  • @karana2260
    @karana2260 4 года назад +1

    thanks for the awesome explanation. a suggestion in program:
    we can reduce num of lines in Hash map compute to:
    for (int k =0; k < input.length; k++) {
    countMap.put(input[k], occurence.getOrDefault(input[k], 0) + 1);
    }

  • @mayurijain5029
    @mayurijain5029 6 лет назад

    the very easiest way you have explained this solution. Thanks

  • @crazywasy
    @crazywasy 8 лет назад +1

    Tushar, can you please make these days a video about P, NP, NP complete and NP hard algorithms? From you i can understand them much better than even my university professors. Thank you!

  • @malharjajoo7393
    @malharjajoo7393 7 лет назад

    This is exactly how this should be explained.
    Although it could have helped if you explain what happens if we dont use a count for the repeated elements.
    In the case we don't , the permutations are repeated.

  • @danqingreader8763
    @danqingreader8763 2 года назад

    Clear presentation, thank you!

  • @brucebigbro4079
    @brucebigbro4079 8 лет назад +1

    Dude, this video helps hell out of me, thanks!

  • @parasprince2001
    @parasprince2001 8 лет назад

    Tushar it's simply awesome... i like your explanation.....

  • @akshatkale4355
    @akshatkale4355 8 лет назад

    Nice algorithm. Good work. It helped me for my interview!

  • @arnabbanerjee3404
    @arnabbanerjee3404 5 лет назад

    Best explanation on this topic ever!!

  • @Amamimamihong
    @Amamimamihong 7 лет назад

    Great video! Your explanation is so clear! Thank you!

  • @ihopethiscommentisntabusiv4670
    @ihopethiscommentisntabusiv4670 6 лет назад

    wonderfully elegant solution

  • @DentrifixoRam88
    @DentrifixoRam88 4 года назад

    The best solution that you can find in Internet.

  • @mahesh_kok
    @mahesh_kok 6 лет назад

    Bhai tu hai kaun, Kaha sey aaya hai, , what an awesome stuff to start the permutaion and combination of strings.bro u killed it....cant find any better explanation than yours to simple looking complex implementation of this problem.. cheers to u yarr

  • @arihant951
    @arihant951 7 лет назад

    Keep doing. You are the best teacher

  • @leozilla
    @leozilla 5 лет назад

    Very good explainations! Thank you very much for taking the time to make this videos! *thumbsup*

  • @chenxiang4376
    @chenxiang4376 7 лет назад

    Thank you Tushar! Please upload more great videos!

  • @sarmadsiddiqui1630
    @sarmadsiddiqui1630 6 лет назад

    great lecture makes recursion so much simpler. Love it thanks for this :)

  • @tomislavzoricic5656
    @tomislavzoricic5656 8 лет назад +13

    Great video as usual!
    Could you make time to create video about big numbers (adding, subtracting, multiplication and division)?
    It would help a lot of guys using c++

    • @tomislavzoricic5656
      @tomislavzoricic5656 8 лет назад

      +Tushar Roy Yes, for example to be able to solve SPOJ problem JULKA

    • @cariyaputta
      @cariyaputta 7 лет назад +3

      I suggest just use Java for big numbers, it's very simple.

    • @tomislavzoricic5656
      @tomislavzoricic5656 7 лет назад +2

      I agree, but I wanted to see the algorithm in action.
      Division gives me headache :)

  • @Ap-dv6lg
    @Ap-dv6lg 5 лет назад

    Great explanation!! Best

  • @anandratn8339
    @anandratn8339 8 лет назад

    I really appreciate your effort. Thank you for sharing knowledge. It's the best thing in the world. It would be great if you can share your view about some standard design pattern problem (How one should approach to solve the problem.) For Example, Pub-sub design pattern with concurrency which should be easy to scale for million of topic, messages, subscribers.

  • @sasha_popov
    @sasha_popov 8 лет назад

    You are a legend, thanks for making these.

  • @dontknow6356
    @dontknow6356 4 года назад

    Thanks for the video.it's very helpful

  • @Sourik24
    @Sourik24 8 лет назад

    Brilliant explaination. Keep up the good work.

  • @raviranger52
    @raviranger52 7 лет назад

    awesome Tushar .. awesome .. really appreciate your efforts (Y)

  • @kritikachugh1015
    @kritikachugh1015 4 года назад

    public static void permutation(String str) {

    permutation("", str);
    }
    private static void permutation(String prefix, String str) {
    int n = str.length();
    if (n == 0) System.out.println(prefix);
    else {
    for (int i = 0; i < n; i++)
    permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, n));
    }
    }
    public static void main(String args[]) {
    permutation("AABC");
    }

  • @ananthasubramanian7355
    @ananthasubramanian7355 5 лет назад +1

    You are amazing.. Thank you for this video !!!!

  • @ravi9889
    @ravi9889 8 лет назад

    Great Work!!! I really like your videos. Thanks Man.

  • @wasifzaman1399
    @wasifzaman1399 6 лет назад

    Awesome stuff! This really helped my understanding!

  • @manojmareedu4012
    @manojmareedu4012 8 лет назад

    Very good explanation.. Thanks..

  • @MANISHPANDEY-ib9iu
    @MANISHPANDEY-ib9iu 5 лет назад

    your work is really good. Thank you and keep going

  • @asahikitase5398
    @asahikitase5398 4 года назад +1

    thanks bro, usually I set 1.25 speed for youtube videos, but for you, I have to set 0.75. lol.

  • @GajendraSingh1990
    @GajendraSingh1990 7 лет назад

    Hi Tusar Sir, You made DS topics so simple with your explanation. I want to ask you the complexity of this algorithm.
    and May you please create some video on complexity.
    Thank You.

  • @learnlearn236
    @learnlearn236 8 лет назад +1

    thank you so much to doing such type of videos really great work..thanks..thanks..thanks.!

  • @lucasberg2090
    @lucasberg2090 8 лет назад

    Hey Tushar, nice video as always! But for next one could you do about Big Integer problems. I really like to know your tips for this kind of problem when using C++.

    • @firefox-zzz
      @firefox-zzz 8 лет назад

      it's a class in java to store the big numbers which are not fitting in memory ,I don't know much about it because they don't need it in IOI but it's neseccary for ACM (sorry for my bad english)

    • @nagarjuna119
      @nagarjuna119 8 лет назад

      numbers of size greater than 64 bit, in C++ there is no datatype to store and perform operation on it ?

  • @davidshechtman4746
    @davidshechtman4746 3 года назад

    Soooo...Cantors diagonal argument that proports to prove that there are many infinities relies on just such a list. The problem is that for Cantor to be right the list of permutations MUST be square. That is to say each row must have the same number of entries as each column in order to, diagonally, cover every possible permutation in the list. But as we can see, any such list of permutations on a set (row) will grow by the factorial downwards as it iterates to the right by the addition of each singular element bitwise. This process can never produce a square matrix. Diagonalization never 'works' (produces a new or unique combination of set elements) in the finite world. And to produce aleph null in the first place we must turn to Zermelo where we are guaranteed a very basic, naive and the most axiomatic notion of infinity arrived at by process of....wait for it...iteration. Cantors diagonal argument is a wonderful bit of sophistry certainly. But it is not based on any real or even theoretically possibly constructable list. An infinite world of infinities is a semantic mobius strip.

  • @biprade9807
    @biprade9807 8 лет назад

    Awesome explanation !!

  • @akhilguptavibrantjava
    @akhilguptavibrantjava 8 лет назад

    Many Thanks Tushar.............. Keep up the good work.....best videos :)

  • @mmmbbb8014
    @mmmbbb8014 7 лет назад +1

    Very well explained. Thank you.

    • @mmmbbb8014
      @mmmbbb8014 7 лет назад

      Between here is the link to handle duplicates using different logic : gist.github.com/MBJAVA/87d1ae03a9e0865589473c0aad56d255

  • @sumanreddyg8245
    @sumanreddyg8245 3 года назад

    Hi verygod , but @21.35 needed to explain about backtracking , how permute(0,1,1) count[i--] -->permute(0,0,0) prints -->permute(0,0,1)(i who does count[i++] to be back in state , this one is missing in explanation of code.

  • @AolaDIY
    @AolaDIY 4 года назад

    he is god sent!

  • @pradeepmehra6879
    @pradeepmehra6879 3 года назад

    great explanation tushar _/\_

  • @dungdang8108
    @dungdang8108 5 лет назад

    Really helpful explain, thank you for the tutorial

  • @nightbemine
    @nightbemine 7 лет назад

    Hi Tushar,
    Your technique and explanation is very good and thoughtful.
    I just have one concern here that the explanation and the code part does not go hand in hand. In explanation you said the algo does not give duplicates but in the code you said it will give duplicates. Can you please provide the code as per the explanation.
    Thanks

  • @andriirubtsov5404
    @andriirubtsov5404 6 лет назад +3

    Runtime complexity will actually be O(K * k!), where K = # unique elements in a string

    • @trybeatingthis
      @trybeatingthis 6 лет назад

      According to his algorithm its more like O(k^2 * k!). There are k*k! function calls, but each function loops through k times to see what values have been used before.

  • @subhamoyburman685
    @subhamoyburman685 7 лет назад

    Great video Sir. You earned an subscriber. :)

  • @srikantsharma6430
    @srikantsharma6430 4 года назад

    Appreciate your effort!

  • @satyammeena9474
    @satyammeena9474 6 лет назад

    thanks a lot ,
    that's really helpful to get a understand the concept,

  • @mstervinay
    @mstervinay 7 лет назад

    +Tushar Thanks you so much. waiting for more design related videos..

  • @MainEffort
    @MainEffort 8 лет назад

    Hi Tushar, many thanks for your efforts. Would this be the same approach for integer arrays ? Could you do a video that considers integer array permutations ? Thanks.

  • @bearded-cat
    @bearded-cat 5 лет назад

    Indian teachers always there to save a day...

  • @avinashmv9686894578
    @avinashmv9686894578 5 лет назад

    I know you wouldn't read this comment , but still another great vid. Thanks Man!

  • @songhaoli304
    @songhaoli304 4 года назад

    well explained and well-illustrated. Though the theory part at 2:00 was a bit hard to digest.

  • @baohezhang112
    @baohezhang112 5 лет назад

    great explanation. Thanks!

  • @keshavkumar-ro3zm
    @keshavkumar-ro3zm 6 лет назад

    hatsoff to your hard work sir

  • @samuelzhang8836
    @samuelzhang8836 7 лет назад

    such a good explanation!!

  • @mahesh_kok
    @mahesh_kok 6 лет назад

    Hi Modifications needs to be done . Your code cannot handle duplicates if any in array it gives arrayoutofbound exception ... Solution to it is While defining length of count[] and str[] it should be
    char str[] = new char[str.length];
    int count[]= new int[str.length];
    and not char str[] = new char[countmap.size()];
    and to print all the permutations in lexicographical order PASS the SORTED STRING

  • @desuvult15
    @desuvult15 4 года назад

    This is great. Thank you.