Sparse Table & RMQ (Range Minimum Query)

Поділитися
Вставка
  • Опубліковано 21 лис 2024

КОМЕНТАРІ • 136

  • @ayushgaba7089
    @ayushgaba7089 3 роки тому +222

    He's the best competitive programmer in my opinion. He devotes so much to the community. Thankyou errichto!

  • @vishnusingh4118
    @vishnusingh4118 3 роки тому +55

    This is a work of art and beauty! There are people who can do but can't teach. Then there are those who can maybe teach but can't do. Then there are legends, who can do both at a mediocre level. And then God said, "Let Errichto be". 🙌. You make complex stuff seem so mind-blowingly simple! Can't thank you enough!

    • @Errichto
      @Errichto  3 роки тому +41

      I think you're exaggerating but still - thank you!

    • @Giovanni-rh1pw
      @Giovanni-rh1pw 4 місяці тому

      That's crazy bro

  • @utkarshdevgan6199
    @utkarshdevgan6199 3 роки тому +90

    This is the greatest tutorial I have ever seen, soo detailed and crystal clear!!!!!!

  • @saikumarganganapalli5957
    @saikumarganganapalli5957 3 роки тому +43

    The transition from logorithm to constant complexity for each query had put a smile. That was so cool.😎. Excellent explanation. Keep it going.

    • @Errichto
      @Errichto  3 роки тому +15

      I agree that the transition is nice and satisfying.

  • @loonshott
    @loonshott 9 місяців тому +1

    Thanks for this amazing course. Your explanation is just in another level.

  • @berfubuyukoz353
    @berfubuyukoz353 5 місяців тому

    Watching you is almost like having a 1-1 lecture with you. It's as if you are empathetic to what the learner could think of next, and you answer in the next second (or more accurately, YOU enable the learner think the right way). I get the same experience when reading the book of Martin Kleppmann. I believe this is sth you see only from great explainers. Anyway, just wanted to share. Thanks for all the effort you put through your videos Errichto!

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

    I was looking for sparse table tutorial. When I saw Errichto's video in the list, I knew I couldn't get any luckier.

  • @magnuseifr
    @magnuseifr 3 роки тому +13

    c++ also has builtin function __lg for base-2 logs with integers. Nice and clear explanation (as always)!

    • @Errichto
      @Errichto  3 роки тому +11

      Oh, right.

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

      I think log2 does the same, doesnt it?

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

      @@GGxEpsilon I think __lg belongs to the gcc compiler and is designed to work on integers (or long longs) specifically. log2 should have the same behaviour, but as Errichto mentions in the video: floating point values are scary to work with.

  • @ayamtaken2580
    @ayamtaken2580 3 роки тому +15

    I don't understand anything you're saying, but your voice is so soothing like ASMR to me

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

    today i am practice codeforces Div2 C problem but i am not able to solve efficiently and seen editorial sparse table algorithm is used then learn this from your lecture then simply solve and learn this concept smart way very thankful for you explanation

  • @rajd7002
    @rajd7002 3 роки тому +2

    Finally a video that perfectly explains the core concept. I was able to come up with log n approach before you explained and was so proud of myself. And then you dropped constant time which blew my mind. :D Thanks Errichto!

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

    Errichto this is so nice and simple explanation I read it in book but did not understand you are really nice at explaining

  • @vietnguyenquoc4948
    @vietnguyenquoc4948 3 місяці тому

    You explain this beautifully, thank you so much
    Hopes you comeback with more explaining video

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

    He is really great and down to earth person....always willing to do something good for community....👍👍👍

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

    i love learning from Errichto more than my own profs

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

    You are the best competitive programmer. Very thanks. I understood it very clearly. Thanks for spending a lot of time to explain us. Thank you Errichto!

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

    Read about sparse table 2 days back. I checked if you had made any video on it. And here it is. 💯

  • @BrunoSouza-wy2et
    @BrunoSouza-wy2et 3 роки тому +3

    amazing dude, I've been following your videos for a year now and you are always improving the way u teach. thanks !

    • @Errichto
      @Errichto  3 роки тому +8

      Let's hope that I will keep improving then :)

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

    Woah explained so simple, seems like a complex math but it is not once you understand the intent behind thanks a lot for the video

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

    Clear, concise, and perfect explanation

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

    Please do some Videos on Data Structure.
    Your explanations are simple and precise.

  • @vwv.1d
    @vwv.1d 2 роки тому

    may you get all of what you want in life..i respect you

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

    For computing "k" in the query function we can do k=floor(log2(len)) then we can have 2^k

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

    This is very cool. Eager to learn about the segment tree.
    I didn't know about this. There surely are good use cases for this algorithm. For sure segment trees, or a similar structure, are used in databases.

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

    Best Explanation, you made it so easy to understand. Please keep up the good work 😊

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

    Duma rozpiera, że rodak jest takim mózgiem :)

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

    I don't know why people disliked this video.🤷‍♂️🤷‍♂️

  • @ahmmedsakibnoman2849
    @ahmmedsakibnoman2849 3 роки тому +11

    plz do segment tree.. waiting for a long time..

  • @5590priyank
    @5590priyank 3 роки тому

    Amazing tutorial, for so long I was not sure how queries take constant time and not logN time. I always thought we need to answer each queries such that we divide range into powers of 2... finally your tutorial solved that for me that we need to take largest power of 2 which fits in given range and check from L and R end point and hence it is O(1). thank you so much for clearing this :)
    Also this clears why we can't use sparse table for answering range sum queries in O(1) because we are using overlapping ranges, right?

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

    I agree that using log2(x) is something to be avoided generally, however, if x < 2^31, it is guaranteed that the result of (int)log2(x) will be the same of any the bit tricks, so it might be a good choice if it's faster to code.

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

    Video quality and explanation is soo good.
    Thank-you!!

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

    Hello guys, I am errichto, is so cool to hear

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

    Should have checked this out before, not knowing sparse tables cost me yesterday as the seg tree failed in time.

  • @anowlwithinternet9125
    @anowlwithinternet9125 7 місяців тому

    You never dissappoint!

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

    Wow! its so clear even a 5 year old IQ guy lile me understands , Thank you for the wonderful content Ericchto !

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

    that was indeed a really good explanation to sparse tables. Thank you for this video. :)

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

    Wonderful video. Helped me a lot sir

  • @farhan787
    @farhan787 3 роки тому +7

    Finally Errichto is back :)

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

    Dzięki za pomoc w przygotowaniu do Olimpiady Informatycznej Juniorów (:

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

    The brain on this man

  • @glaucoa.9214
    @glaucoa.9214 3 роки тому

    Erichto you are the best person in the world!

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

    Thank,I just needed this perfect and Crystal clear explanation .Orz

  • @pavankumar-cy6mg
    @pavankumar-cy6mg 3 роки тому +1

    why it is k

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

    Very nice explanation Errichto

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

    I love even more your recent videos

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

    Thanks ☺️ , this lecture was really helpful.

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

    It would be nice if you covered CSES problemset. It has a lot of educational problems that are hard to solve if you don't know the right technique.

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

      check out CPH. CSES is a supplementary problem set to that book. Good luck!

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

    Please make detailed videos on segment tree and it various applications( like, min , max, updating, sum, frequency of max frequent element in the asked range etc...)

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

    Can someone explain me what is “1

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

      Search bitwise left shift and right shift on UA-cam
      Also i think errichto has a video on bit manipulation where he explained left shift and right shift

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

      Here you go :
      ua-cam.com/video/xXKL9YBWgCY/v-deo.html

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

      @@leviackerman9882 Tks u so much

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

      It means 2 to the power k

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

    Very nice explanation

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

    Thank you for this great video
    BTW : Is the __builtin function O(1) or O(log) or what ??

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

      It is O(number of bits), so it is essentially O(1)

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

      @@hitesh6856 It's O(1) rather than O(number of bits). CPU doesn't need to iterate bits one by one, it does it faster just like other basic operations like addition.

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

      ​@@Errichto ohh. I didn't knew that. Thanks! big fan..!

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

      @@Errichto thx for answering

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

    Thank you, Errichto.

  • @BGOPC
    @BGOPC 9 місяців тому

    2 year's in and still waiting for the segment tree video

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

    Amazing tutorial!!! Really enjoyed it and learned a lot!

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

    This reminds of Reversort in Codejam Quali

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

    Keep up these good tutorials. Thanks a lot

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

    Errichto can you please make a video on how to deal with burnouts we face while constant coding?

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

    10:00 this was when I started thinking that sparse tables are clever.

  • @userrand4900
    @userrand4900 Рік тому

    Is the condition in line 30, correct? It does not reflect m[i + (1

  • @beaujamo
    @beaujamo 10 місяців тому

    Thank you! Got mine working now! Awesome tutorial!

  • @dhakad22klx
    @dhakad22klx Рік тому

    Easily explained.

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

    Great explanation.

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

    We can also solve this problem using sliding window concept in O(n) time

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

    Amazing stuff, good explanation

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

    He's sooo clever. Thanks for the video

  • @GGxEpsilon
    @GGxEpsilon 3 роки тому +2

    Errichto orz ❤️

  • @isma--
    @isma-- 2 роки тому

    Hey Errichto, one question, what do you use in order to write your notes, i think you use like a tablet or something

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

    please do segment trees next

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

    Hi , can I know the name of program used to explain pls?

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

    I saw this somewhere to find largest power of 2 less than or equal to n:
    x=n
    While(x&(x-1))
    x&=x-1;
    Now x will be the answer

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

    Can we use sparse table for sum queries if we use the method where we convert ranges to binary and add it like we do in binary lifting (query time = logN)?

  • @i_am_wiz
    @i_am_wiz Рік тому

    Won’t the time complexity for answering a single query still logN as we are computing log2(len) where len is R - L + 1 which in worst case is of the order (N). So won’t the time complexity be logN per query?

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

    Can you have multiple overlapping intervals?

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

    your balance bracket concept apply div2 B problem in contest get Accepted and my rank under 2500 thanks for you good job

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

      :)

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

      What balance bracket concept?
      Could u pls share the link of that video 🙏🙏

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

      ua-cam.com/video/piT58dNLPhg/v-deo.html

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

    the best youtuber

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

    Thanks for this vid - i like your background - so the goal to the get the O(N*log((N) + Q) though N is increasing tremendously ?

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

      It's O(N*log(N) + Q) so it makes a lot of sense if Q is huge.

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

    i dnno, this guy is godtier. I cannot compute. syntax error

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

    How do you find problems on SPOJ? It seems so difficult to find by tags.

  • @Dima-Teplov
    @Dima-Teplov 3 роки тому

    Many thanks!

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

    legend.

  • @joshuawilson6907
    @joshuawilson6907 Рік тому

    I got WA with this code on spoj, do you guys have any ideas?

  • @brucewayne-og8ro
    @brucewayne-og8ro 3 роки тому

    I feel smarter already....

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

    Nice!! Binary is always Beautiful :)

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

    Line 27, shouldn't it be i

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

    It is like segment tree

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

    How would we handle updates?

    • @Errichto
      @Errichto  3 роки тому +2

      You need a segment tree for that.

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

    What an explanation! op

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

    pls do video on disjoint set union

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

    Thanks You

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

    Segment tree can also do the same right? So whats the advantage here?

    • @mohansharma-pt6yk
      @mohansharma-pt6yk Рік тому

      Time complexity becomes O(N+Q*logN) and improves space complexity too

    • @skt7088
      @skt7088 Рік тому

      @@mohansharma-pt6yk in segment tree time complexity is O(QlogN)?

  • @joshuawilson6907
    @joshuawilson6907 Рік тому

    I can AC the cses problem but cant for the spoj :))

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

    Please do make how and when u started doing cp. Love your videos from Bangladesh

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

    Awesome!!

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

    I have no idea what queries are, and i am trying to learn

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

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

    good !

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

    💯💯💯

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

    Amazing👍🏽👍🏽

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

    You're amazing

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

    awesome