Algorithms - Solving Recurrence Relations By Substitution

Поділитися
Вставка
  • Опубліковано 1 чер 2024
  • Please support me on Patreon: / thesimpleengineer
    / thesimpengineer / schachte
    ryan-schachte.com
    Don't forget to subscribe! ➨ Website -
    ➨ New Video! - • Docker Client, Images ...
    ➨ / the-simple-engineer-80...
    ➨ Github - github.com/schachte
    ---------------------------------------------------------------
    In this video I talk about what recurrence relations are and how to solve them using the substitution method. We analyze two popular recurrences and derive their respective time complexities.
  • Комедії

КОМЕНТАРІ • 67

  • @khanhchung5207
    @khanhchung5207 Рік тому +3

    Thank you for your explanation of this technique. This is the first video about DSA that I could watch entirely without feeling boring. I hopefully you can make more videos about the techniques that are frequently used in interview problems.

  • @zetrox1870
    @zetrox1870 3 роки тому +1

    What 5 websites, 3 other tutorial videos and my prof couldnt explain well enough for me to get, you have managed to explain perfectly clearly how to do this. Thank you.

  • @christianremwood4817
    @christianremwood4817 4 роки тому +1

    This one video just clarified 4 weeks of confusion for me. Thank you so much!

  • @amruthsar
    @amruthsar 5 років тому +4

    Thank you so much.. I hadn't understood this for years and this one lecture changed it..

  • @rohanwadhavkar5343
    @rohanwadhavkar5343 5 років тому +9

    That was incredible. You explained this much better than my professors or the TAs ever did. Subscribed!

  • @Amande3p25
    @Amande3p25 7 років тому +2

    You've explained this better than any other video on youtube. Finally, I understand this stuff now.. Thanks for posting this

  • @JinayShah
    @JinayShah 6 років тому +1

    Thank you for making the video, you've explained it really well!

  • @user-mj2os2gu9e
    @user-mj2os2gu9e 5 років тому +18

    THANKS i almost cried all other algorithms explanation videos sucked so bad its like they want me to fail the course (bad instructor bad videos) but im saved by you yaaaaaaaaaaay

    • @user-tn8cd9ns7w
      @user-tn8cd9ns7w 5 років тому

      tried ***,,e5tbary bkrh ..pray for me

    • @susantasharma
      @susantasharma 4 роки тому

      you can also checkout this one . Just too good ua-cam.com/video/Ob8SM0fz6p0/v-deo.html

  • @brianstorm597
    @brianstorm597 3 роки тому

    Amazing presentation man. I wish my university professor was as clear as you were in the video. Kudos!

  • @Furighteous
    @Furighteous 5 років тому

    You made this very easy to understand, thank you!

  • @rajdevlive
    @rajdevlive 6 років тому

    Exactly what I was looking for. :-) Thanks.

  • @DebasishOpu
    @DebasishOpu 6 років тому

    Great video. Thank you so much.

  • @riczd
    @riczd Місяць тому

    Thanks for the explanation!!!!!!!!

  • @udenithakshila2069
    @udenithakshila2069 3 роки тому

    Great explanation. thank you

  • @adhwaaalanazi2552
    @adhwaaalanazi2552 6 років тому +1

    you are the BEST, you solve the biggest problem for me in the woooooooorld

  • @Joemakatozi1776
    @Joemakatozi1776 6 років тому

    Great video. Thanks.

  • @gaurav22221
    @gaurav22221 6 років тому +1

    Thank you Brother

  • @Tylermania66
    @Tylermania66 5 років тому +20

    you know there is a very high pitched screech in your into.

    • @phoenixhartmann7121
      @phoenixhartmann7121 3 роки тому +3

      i noticed as well, because of the pain in my ears

    • @giliza
      @giliza 3 роки тому

      I do like his tutorials but I always jump that Intro.

  • @jamesbones1668
    @jamesbones1668 4 роки тому

    wow- that did it for me!

  • @IsaacC20
    @IsaacC20 5 років тому +1

    I found this video very helpful but there needs to be clarification at @12:52. The linear term, n*c, didn't fall from the sky. It comes from the 'merging' operation of elements from two sorted containers (each containing a subset of elements sorted from a more recent recursive call). The merging operation (a sorting algorithm in its own right, I suppose) involves comparing 2 elements at a time, one from each container, until either or both containers are exhausted. The larger (or smaller, depending on whether you sort high-low or low-high) of the two element is inserted into another container to be used in the next recursive step. The comparison and insertion constitute n*c complexity.

    • @IsaacC20
      @IsaacC20 5 років тому

      Also worth noting: 'k' represents how many levels 'deep'/'down' you are in your recursive call.

  • @malinayani
    @malinayani 6 років тому +1

    Category comedy, Nice :P

  • @bulbul6
    @bulbul6 6 років тому +2

    Loved the presentation. 😍 Which software do use to make such amazing stuff?

    • @TheSimpleEngineer
      @TheSimpleEngineer  6 років тому +2

      Thanks! I used a Wacom Intuous tablet for drawing, Camtasia for editing, Adobe Audition for the audio and After effects for the intro.

  • @shivarammuthukumaraswamy7164
    @shivarammuthukumaraswamy7164 5 років тому

    THANKS man

  • @eXtrem1s
    @eXtrem1s 5 років тому

    Very nice video.....understood it all. BTW which software do you use to write?

  • @millermeares6676
    @millermeares6676 4 роки тому +1

    18:00. Much simpler just to say 2^k = n as you already had that instead of doing the complicated log simplifying thing

  • @fleal
    @fleal 3 роки тому

    In case of recurrences like T(n) = T(2n/3) + T(n/3), this method doesn’t work. What kind of methods could we then use?

  • @johnniegilkerson4724
    @johnniegilkerson4724 5 років тому

    @: in video, where did you get the 3rd C?

  • @zainabmostafa7998
    @zainabmostafa7998 4 роки тому

    thanks for your excellent explanation , I have a question : I want to solve the recurrence relation T(n)=T(n−1)+O(n) for n>1, T(1)=1.
    what is O(n)? is O(n) equals to constant or what?

    • @anush9065
      @anush9065 4 роки тому

      There is a convention in macro substituion that states : "a set in a formula rep an anonymous function in set " so the O (n) represents a function h(n)

  • @drwhackadoodle360
    @drwhackadoodle360 4 роки тому

    What is going on with the substitution of the 2t(n-2)+c how do you sub and get rid of all the terms like the T and the -1?

  • @icosmini
    @icosmini 5 років тому

    The time complexity of the first algorithm is NOT 2^N.
    It is N: to obtain the tenth Fibonacci number you just need to compute the previous nine numbers. You definitely don't need 2^10 (one million) computations.

    • @xXxOmarSanchezxXx
      @xXxOmarSanchezxXx 5 років тому +1

      Without memoization you're recomputing values already seen I believe.

    • @srijaljoshi3421
      @srijaljoshi3421 5 років тому +2

      That's correct for the iterative implementation. For a recursive implementation, however, it takes exponential time as shown in the video because of repetitive computations. You can draw a recursion tree to see how the same values are computed multiple times which is why the recursive implementation is generally very slow for large n ( n>=30)

  • @Kellworkie
    @Kellworkie 5 років тому

    Why add the "+C" after the "2T(n-1)" when solving the recurrence of the Fibonacci?

    • @Victim_Crasher
      @Victim_Crasher 5 років тому +1

      I think it's a time taken for other stuff like the addition between T(n-1) and T(n-2) on fibonacci, CMIIW

  • @janssenkuhn4049
    @janssenkuhn4049 2 роки тому

    These are great videos. Too bad they don’t show up in Google results and instead I get stuff from people who are better at SEO than SE.

  • @preet9343
    @preet9343 3 роки тому

    I think I understand the concept, but I can't for the life of me solve them. do you guys have any advice?

  • @shakeelrajput5038
    @shakeelrajput5038 6 років тому +1

    Sir can you explain me what is log2(n)?

    • @anush9065
      @anush9065 4 роки тому

      its actually log n with base 2

  • @hades2504
    @hades2504 4 роки тому

    is the solution in explicit form??

  • @Lucas-ns9hd
    @Lucas-ns9hd 4 роки тому

    I wish any of these steps made sense to me. Why are we guessing about upper bounds all of a sudden? What the hell??

  • @dancerham
    @dancerham 6 років тому +1

    how did you get n/2^k = 1 @ 16:47?

    • @EbenTuff
      @EbenTuff 6 років тому +3

      He says "I want to recurse to the base case, otherwise I'll have a never-ending algorithm". With this, we want T(n/2^k) to become T(1) [[The base case]].
      T(n/2^k) must become T(1). Therefore, in the base case, n/2^k = 1

    • @dancerham
      @dancerham 6 років тому

      OH! Thankyou! :D

    • @amirtv106
      @amirtv106 6 років тому

      Considering integer division, n/2^k will reach 1 eventually.

  • @LordShish
    @LordShish 5 років тому

    08:04 wouldnt that 2^0 be 2^1?

  • @toriacasta9308
    @toriacasta9308 6 років тому

    I need help on solving this recurrence relation. I've been stuck on it. T(1)=5, T(2)=11, T(n)=5T(n-1)- 6T(n-2) PLEASE HELP

    • @TarunMohandas
      @TarunMohandas 6 років тому

      Convert it into a quadratic equation.
      T(n) - 5T(n-1) + 6T(n-2) = 0
      (t^2) - 5t + 6 = 0
      t = 2, t = 3
      T(n) = A(2^n) + B(3^n) [from solution to quadratic equation]
      Now we use base condition
      T(1) = 2A + 3B = 5
      T(2) = 4A + 9B = 11
      Solve for A and B. A = 2, B = 1/3
      T(n) = 2(2^n) + (1/3)(3^n)
      T(n) = 2^(n+1) + 3^(n-1)

  • @aladdin_mck
    @aladdin_mck 3 роки тому +1

    This is the same as this and the same as that and the same as this.... bro what?

  • @akshitarawat1970
    @akshitarawat1970 4 роки тому

    U took 1 ,1 ,2
    So how can it be equal to n-2 ,n-1 ,n ????

    • @anush9065
      @anush9065 4 роки тому

      Its a series . the n represents the positional value . if you take 2 to be in nth place the 1 is in n-1th place or if you take 1 as n the 2 is in n+1 th place . Simply we are indexing them based on 'n'

  • @delavago5379
    @delavago5379 6 років тому +1

    this could have been clearer. sorry but this didn't help. it was nice but you run off once you get into it

  • @hashirkhalid2151
    @hashirkhalid2151 7 років тому +9

    i think you have done this by iteration method and not by subsitution method. Subsitution method requires to take an initial guess , which ofcourse you havent taken here

    • @TheSimpleEngineer
      @TheSimpleEngineer  7 років тому +3

      Hashir Khalid I believe you are referring to non homogeneous linear recurrence relations

    • @hashirkhalid2151
      @hashirkhalid2151 7 років тому

      ^sorry my mistake, i got it now ! BTW thanks for the lecture. Nicely poised and easily understandable

    • @TheSimpleEngineer
      @TheSimpleEngineer  7 років тому +1

      Hashir Khalid My pleasure! I made another lecture on non homogenous LRR's as well if you're curious.