String Permutations - Understanding Recursion | Learn Algorithms with Phanto

Sdílet
Vložit
  • čas přidán 27. 07. 2024
  • Calculating the possible permutations of string can be confusing. In this video, we will explain this interesting problem in more detail.

Komentáře • 123

  • @abirajrajendran2327
    @abirajrajendran2327 Před 3 lety +3

    I have been having hard time understanding this problem, a huge thanks!, I got it understand pretty well, please continue making such, your style of teaching not only provides info, but also answers the questions that we have while listening,, keep going!🙌.

  • @Aryan-nm4fh
    @Aryan-nm4fh Před 2 lety +1

    Trying to understand it for so long and now it is crystal clear,
    thanks a lot.

  • @willyoung3601
    @willyoung3601 Před rokem +2

    This was a massive help to me, thank you so much! Got through a bunch of videos before I found this one, and it explains it perfectly. Nicely broken down and taught! Thank you c:

  • @annas8308
    @annas8308 Před rokem +2

    Thanks for the step-by-step code-tracing using a graph. Very helpful.

  • @pratyugna
    @pratyugna Před 3 lety +8

    I went through 5 videos to understand this concept.... And now i am satisfied 😊

    • @ai-powered-coder
      @ai-powered-coder  Před 3 lety

      I’m very glad it helped! Thanks for your positive feedback and stay tuned for more videos :)

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

    This is the best explanation for this problem i have seen on the internet.

    • @ai-powered-coder
      @ai-powered-coder  Před 4 lety

      Thank you for your beautiful feedback! I’m very happy you liked it :)

  • @RushOrbit
    @RushOrbit Před rokem +1

    WOW Thank you!!! This is the best explanation I’ve found for this problem!!!

  • @azolaace5348
    @azolaace5348 Před rokem +1

    Wow, you are the best Bro. THANKS

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

    This is brilliant Sir, please upload more content. Thank You.

  • @monzteredits
    @monzteredits Před 24 dny

    Holy shit man!!! U made me understand this so quickly!! Subscribed

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

    this really a great explanation.

  • @2010Kellykelly
    @2010Kellykelly Před 2 lety +1

    Best explanation ever! Thank you so much!

  • @01ginni
    @01ginni Před 3 lety +1

    Amazing explanation. Looking forward to see more of your videos.

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

    clean explanation , Great work

  • @gunabalang7034
    @gunabalang7034 Před 3 lety

    Keep doing , you are a great teacher.

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

    superb.......... waiting for more videos

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

    Great Explanation - Thanks

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

    Great video.

  • @Ruin3.14
    @Ruin3.14 Před rokem +1

    this is gold, thank you!

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

    that elephant poping up concept was really innovative.keep it up

  • @parthibanvijayan5224
    @parthibanvijayan5224 Před rokem

    Great explained 🙏

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

    good explanation. Love it

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

    Thank u so much....make more videos ...u explain so well!!

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

    Man, the elephant is awesome!

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

    Hey Dear Phanto, That was literally the easiest to understand if someone will try logic on pen and paper. Well Explained

    • @ai-powered-coder
      @ai-powered-coder  Před 3 lety

      Very glad you found it useful. Thank you for sharing your positive feedback :)

    • @bitqahdi6592
      @bitqahdi6592 Před 3 lety

      @@ai-powered-coder Every subscriber of yours appreciate your efforts very much. Keep posting content and we are here to learn and support. Thanks again

    • @ai-powered-coder
      @ai-powered-coder  Před 3 lety +1

      Thanks you very much Bitq! :) we (me and phanto) will continue posting for sure. Stay tuned! :)

  • @arthurcueva
    @arthurcueva Před 4 lety

    thanks this was a great video!!!

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

    Best! Thank you DevBox

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

    Good explanation...
    Keep going😄

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

    This was really a great video!!! Helped me a lot
    I wish u could make more videos!!!!!!

  • @imranmohamed5404
    @imranmohamed5404 Před 4 lety

    great explanation.

  • @nagendranp3961
    @nagendranp3961 Před 3 lety

    very very clear explanation.

  • @charbelgemayel8854
    @charbelgemayel8854 Před 5 lety +1

    GREAT EXPLANATION. THANK YOU!!!!

    • @ai-powered-coder
      @ai-powered-coder  Před 5 lety

      Thanks for your positive feedback. Glad that you liked it :)

  • @srikrishna3121
    @srikrishna3121 Před 4 lety

    Really helpful!!!

  • @payalsagar1808
    @payalsagar1808 Před 4 lety

    oh my my....thankyou! saved my day! thankyou thankyou man!💓

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

    Yes where is your next video!! We would love to see it.

  • @sakshamsangal9270
    @sakshamsangal9270 Před 4 lety +5

    finally, I understood!!

  • @emansorour9074
    @emansorour9074 Před 3 lety

    Great keep going

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

    best explanation and elephant's questions helps to clear my doubts

  • @om7893
    @om7893 Před 4 lety

    Thanks a million :).

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

    i hope u get million subs , now word to explain about explanation and doubts and one thing is asking question is excelent

    • @ai-powered-coder
      @ai-powered-coder  Před 3 lety +1

      Thanks for your positive feedback Uday :)

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

      @@ai-powered-coder But
      If I look into ur channel, no content 🙄
      Please continue to upload daily
      You will get viewers ❤️

    • @ai-powered-coder
      @ai-powered-coder  Před 3 lety +1

      Quality content takes time to create. I will ramp things up in the coming weeks :)

  • @aztech3764
    @aztech3764 Před 2 lety

    Very great

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

    Thank you man

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

    Amazing Explanation!

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

    Amazing explanation!!!

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

    helped me a lot,thank you.

  • @zelimkhankhalidov6620
    @zelimkhankhalidov6620 Před rokem +1

    Thank you for the video! One question regarding the time complexity. Are you sure that it's "n!"? n! is only for the case when left == right, but that condition is not always true. Before left == right, a lot of "calculate" execution takes place, actually n*n! times. Also, swap operation and printing operation also time consuming, it's around O(n), so for each n*n! there is additional O(n). So wouldn't we have O(n^2*n!) complexity?

  • @justinspired4188
    @justinspired4188 Před 4 lety

    best video on this topic!!

  • @bishoyroufael4889
    @bishoyroufael4889 Před 4 lety +6

    What an Egyptian accent

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

    This was a great video . Finaaly I understood and plz make more videos 👌🏻👌🏻👍

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

    Thank you ..

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

    Amazing explanation

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

    This is brilliant

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

    تحياتي لك يا معلم

  • @JGyanRaj
    @JGyanRaj Před 4 lety

    amazing

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

    please make more videos , your videos are awesome

    • @ai-powered-coder
      @ai-powered-coder  Před 3 lety

      a new video is coming in a week or so. Glad you like them :)

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

    would be awesome if you could have shown the dry run beside the code.

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

    recursive backtracking is much more suitable for this kind of problem

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

    Respect.

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

    Please make more videos soon

  • @abdelrhmanahmed1378
    @abdelrhmanahmed1378 Před 3 lety

    how can we get permutations of certain sub set in set i.e {1,2,3,4,5,6,7} i want only to get 3 numbers permutation set from this set, (i tryed to use the right index but it didnot work)

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

    Hi, your accent is Egyptian lol, let me know if I am correct. Great video

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

    I have one question:
    When I ran the solution, I logged the for loop running a total of 9 times.
    Would this still be considered O(N!)?
    If I'm understanding correctly, the algorithm should run for 6 times if N = 3.

    • @ai-powered-coder
      @ai-powered-coder  Před 3 lety

      Which variation of the algorithm did you run? (Recursive, memorization, or tabulation)

    • @aidanfarhi367
      @aidanfarhi367 Před 3 lety

      @@ai-powered-coder I used the example you coded out in Java translated into Python. Recursive, if I'm not mistaken. I'm fairly new to the time complexity stuff, so I just want to make sure I understand.

    • @ai-powered-coder
      @ai-powered-coder  Před 3 lety

      in case of the recursive algorithm, if n=3, then the complexity will be O(2^n) which is 8. That extra time (difference between 9 and 8) is a constant and hence is not that impotrant when it comes to calculating complexity.

  • @excessreactant9045
    @excessreactant9045 Před 4 lety

    10/10 vid

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

    Could you please upload more videos.... it is really helpful...

    • @ai-powered-coder
      @ai-powered-coder  Před 3 lety +1

      Glad you found them helpful. A new video is coming already on the way. ;)

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

      @@ai-powered-coder Thank you 😊👍👍

  • @AbhishekYadav-fx2qp
    @AbhishekYadav-fx2qp Před 3 lety

    Can anyone explain why the backtracking swap was not used here??

  • @longhan7842
    @longhan7842 Před 4 lety

    more video plssss

  • @akshitarora470
    @akshitarora470 Před 4 lety +5

    WHY DON'T YOU MAKE MORE VIDS :(

    • @ai-powered-coder
      @ai-powered-coder  Před 4 lety +6

      I am finalizing a project in hand and will focus back on the channel very soon (in 1-2 months). So if you like the content, subscribe and stay tuned 😊

  • @venkatsaiputtagumpalla4367

    Hey I have a doubt
    When I use an array of numbers instead of string I am getting incorrect order

    • @ai-powered-coder
      @ai-powered-coder  Před 4 lety +1

      Using an array of numbers should not make a difference. Assuming that you include single digit numbers only in the array. (To have all combinations). Would be great if you post the code to have a look to be able to better help.

    • @venkatsaiputtagumpalla4367
      @venkatsaiputtagumpalla4367 Před 4 lety

      @@ai-powered-coder
      import java.util.*; public class stringper {
      public static void main(String args[]) {
      Scanner sc=new Scanner(System.in); int nums[]={1,2,3}; perm(nums,0,nums.length); } static void perm(int[] nums,int left,int right) {
      for(int k=0;k

    • @venkatsaiputtagumpalla4367
      @venkatsaiputtagumpalla4367 Před 4 lety

      I am using two swaps If use one swap I am getting wrong answer

    • @ai-powered-coder
      @ai-powered-coder  Před 4 lety

      I adjusted the example that was explained in the video to work with an array of numbers. Here you go:
      import java.util.Arrays;
      public class PermutationsNumbers {
      public static void main (String[] args) {
      int[] s = {1, 2, 3};
      int n = s.length;
      PermutationsNumbers permutations = new PermutationsNumbers();
      permutations.calculate(s, 0, n-1);
      }
      private void calculate(int[] nums, int left, int right)
      {
      if (left == right) {
      System.out.println(Arrays.toString(nums));
      }
      else {
      for (int i=left; i

    • @venkatsaiputtagumpalla4367
      @venkatsaiputtagumpalla4367 Před 4 lety

      @@ai-powered-coder why are you using swap function two times

  • @sarbjitgahra4667
    @sarbjitgahra4667 Před 3 lety

    Two things I couldn't follow from the video. May be someone could shed some light on this.
    Here is how I envision the stack:
    first call
    calculate ('ABC' , left = 0, right = 2)
    for loop:
    i = 0
    swapped ( 'ABC' , left = 0, i =0) => 'ABC'
    recursive call- calculate('ABC', left+1, right) => calculate('ABC', 1, 2)
    for loop:
    i = 1
    swapped('ABC' , left =1 , i = 1) =>'ABC' ( since again left and i are same)
    recursive call -calculate ('ABC' , left + 1, right) => calculate('ABC' , 2, 2)
    if condition true:
    print('ABC')
    * What happens next ?
    * When is i == left not true ? It seems i is always equal to left

    • @lildawg1685
      @lildawg1685 Před rokem

      Exactly, I feel the same way. The code doesn't work when I envision it. it just swaps itself all through

  • @vaishalinisivakumar6537

    I'm getting thread exception while executing

  • @SunilKumar-hu3ow
    @SunilKumar-hu3ow Před 4 lety +1

    package basicalgos;
    public class Permutations {
    public static void main(String[] args) {
    String s="ABC";
    int n=s.length();
    Permutations p= new Permutations();
    p.calculate(s, 0, n);
    //System.out.println("hello");

    }
    private void calculate(String str,int left,int right)
    {
    if(left==right-1)
    {
    System.out.println(str);
    }
    else
    {
    for(int i=left;i

    • @ai-powered-coder
      @ai-powered-coder  Před 4 lety

      Hi Sunil!
      Here is the code shown in the video:
      public class Permutations {
      public static void main (String[] args) {
      String s = "ABC";
      int n = s.length();
      Permutations permutations = new Permutations();
      permutations.calculate(s, 0, n-1);
      }
      private void calculate(String str, int left, int right)
      {
      if (left == right) {
      System.out.println(str);
      }
      else {
      for (int i=left; i

  • @SunilKumar-hu3ow
    @SunilKumar-hu3ow Před 4 lety

    my code is not working in eclipse

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

    What is this algorithm called?

    • @ai-powered-coder
      @ai-powered-coder  Před 4 lety

      Not really sure if it has a specific name. It is the string permutation algorithm :)

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

    Is this Heap's algorithm?

    • @ai-powered-coder
      @ai-powered-coder  Před 4 lety

      No the heap’s algorithm is a little different. But both of them get the permutations if a string.

  • @ahmadzeed591
    @ahmadzeed591 Před 4 lety

    Please return to make videos

  • @SunilKumar-hu3ow
    @SunilKumar-hu3ow Před 4 lety

    package basicalgos;
    public class Permutations {
    public static void main(String[] args) {
    String s="ABC";
    int n=s.length();
    Permutations p= new Permutations();
    p.calculate(s, 0, n-1);
    //System.out.println("hello");

    }
    private void calculate(String str,int left,int right)
    {
    if(left==right)
    {
    System.out.println(str);
    }
    else
    {
    for(int i=left;i