Designing a location database: QuadTrees and Hilbert Curves

Поділитися
Вставка
  • Опубліковано 8 лип 2024
  • Location-based databases are extensively used by apps like Google Maps, Uber, and Swiggy. We explore the data structures and algorithms that allow spatial or location-based queries, like the quadtree and the Hilbert Curve.
    For now, we haven't dived deep into polygon intersections or R-trees.
    00:00 Who should watch this?
    00:27 Pincodes
    01:27 Measurable Distance
    02:04 Proximity
    02:39 Suitable Data Structures
    03:48 2D Representation
    05:13 Bits for X,Y axes
    06:20 Searching in 2D
    07:45 Potential Drawback
    08:16 Quad Trees
    10:07 Range Queries
    10:52 Fractals from 2D to 1D
    16:06 Hilbert Curve Examples
    21:50 Course Questions
    22:15 Thank you!
    Looking to ace your following interview? Try this System Design video course! 🔥
    interviewready.io
    Course chapters:
    1) Design an email service like Gmail
    2) Design a rate limiter
    3) Design an audio search engine
    4) Design a calling app like WhatsApp
    5) Design and code a payment tracking app like Splitwise
    6) Machine coding a cache
    7) Low-level design of an event bus
    The chapters have architectural diagrams and capacity estimates, along with subtitled videos. Use the 'HELLOWORLD' code to get an exclusive discount.
    References:
    Google S2: blog.christianperone.com/2015...
    Hilbert Curve: • Hilbert's Curve: Is in...
    Fractals: • Fractals are typically...
    System Design Playlist: • System Design for Begi...
    Segment Trees: • Segment Trees explaine...
    Z-order curve: en.wikipedia.org/wiki/Z-order...
    You can follow me on:
    LinkedIn: / gaurav-sen-56b6a941
    Twitter: / gkcs_

КОМЕНТАРІ • 309

  • @gkcs
    @gkcs  Рік тому +6

    The high-level design of Uber:
    interviewready.io/learn/system-design-course/design-a-cab-aggregator-app-like-uber/requirements-of-a-cab-aggregator
    I should have the high level design of Google Maps out this week. Wish me luck!
    EDIT:
    Google Maps: interviewready.io/learn/system-design-course/design-a-location-based-service-like-google-maps/requirements-of-a-map-application

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

      Is seems similar to geohash, are they both same or different approach?

  • @subamsarkar_
    @subamsarkar_ Рік тому +27

    It's really overwhelming for me but the passion you have it towards making us understand the thinking behind designing a schema !! inspires me Gaurav. More power to you man.

  • @jibrankhan499
    @jibrankhan499 3 роки тому +235

    This guy has more knowledge than all of my Engg clg's faculty combined.

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

      😂😂😂😂😂

    • @swapk99
      @swapk99 3 роки тому +26

      It is so easy to criticize your teachers but have you ever thought why are you enrolled in such a college?

    • @jibrankhan499
      @jibrankhan499 3 роки тому +5

      @@swapk99 just one word "Majburi"

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

      @@jibrankhan499 bhai shi kha aapka to naam bhi jabran hai :P

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

      @@jibrankhan499 Apni Galti ki wajha majburi ko mat do!

  • @RashmiJadhav6612
    @RashmiJadhav6612 3 роки тому +75

    Clearly, you are very passionate about Computer Science and love spreading the knowledge. How do you manage exploring so much around? You must be a very productive person to delve into stuff. It gets overwhelming for me thinking if I’ll ever be this knowledgeable. Thanks for all the inspiration!

    • @gkcs
      @gkcs  3 роки тому +45

      I frequently feel the same (about my productivity and the overwhelming sense that I am slow).
      But every now and then, I look back and feel good again 😁

    • @oml6048
      @oml6048 Рік тому +2

      And the best part about Gaurav is .. .he teaches not for views but for a more higher purpose B)

  • @ayushsharma1943
    @ayushsharma1943 3 роки тому +19

    Bro, I bow down to you. To break down such a big concept into smaller parts and then not only explain the solution but how we reached the particular design. Can find a lot of videos on how something is implemented but this video tells why it is implemented the way it is. Job very well done.

  • @mistercakes
    @mistercakes 3 роки тому +10

    Working in the maps industry I'm really happy to see this come up on my feed. Looking forward to watching. Thanks for all your content. It's very accessible.

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

      😁

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

    Literally 2 days ago I was reading about Google Maps algorithm and it's working, and you have made my wish come true by uploading this

  • @CloudA2Z
    @CloudA2Z 3 роки тому +24

    I would say “Star of the show” is always u , I’m mersmerised with your knowledge in each subject with which u build solutions.. cheers bud .. u r going to give a tough fight to even PhD guys in Berkeley

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

      Thank you 😁

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

    I think I know why I was recommended this, but I wasn't really in the mood - if attention span isn't already a metric, here you go youtube, enhance your algorithm - any way, this was incredibly insightful. I like your thought process. It's very logical and understandable. You're brilliant and I appreciate your insight. Thank you.

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

    You blew my mind up so hard it's spilt all over my computer!! This is amazing!

  • @mahanteshambali
    @mahanteshambali 3 роки тому +48

    "taxiii sharing services" was wicked

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

      that pause! I really laughed out loud xD

  • @priyakantpatel6866
    @priyakantpatel6866 3 роки тому +4

    I loved the way you explained 2d to linear. It can not be simpler than this.

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

    I just don't know , how the heck a person can be this talented , you are intelligent , you are humorous(coming from interview with miss Rainy Jain).I could never even think of exploring so much and i will fight with the one if he says you aren't passionate enough . I know no one will say.YOUR parents must be so proud of you...oh gosh i will stop now

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

      😁

  • @chostislas
    @chostislas 2 роки тому +1

    I do have an onsite tomorrow and I found your channel late, you have so much talent explaining complex topics. It's good you are sharing that talent with the community.

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

    You just opened a whole new world to explore! Very interesting and exciting to expand it's applications.

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

    Your video has come at such a great time. I'm getting started with building a rental car app and I've had a few issues while using maps in the app. This is going to help and I'm waiting for your next video on this topic. Thanks 😊

  • @deadchannel-x2m
    @deadchannel-x2m 3 роки тому +1

    Wow! The concept is really interesting. Thanks, man!

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

    Loved the way you explained the hilbert curve and its application to the problem at hand.

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

    You are awesome at explaining, thank you for all your effort!

  • @user-nu5ff3tm9e
    @user-nu5ff3tm9e Рік тому

    I've never seen such a perfect video explaining hilbert curve!!

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

    wow Gaurav, you are amazing :), happy enough to watch this, as the video was just released, very well done

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

    Intro is solid, content is as usual as dope

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

    Exactly what I was stuck on today... You made it simpler gaurav... Thanks loads.

  • @Sathyachakra
    @Sathyachakra 3 роки тому +10

    Wow the fractal connection was totally unexpected. When you told dimensionality reduction, my mind immediately went to Principal Component Analysis but couldn't figure out how. Fractals was elegant👍

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

      Interesting, I think PCA was a good guess!

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

      I thought of PCA too but I was wondering how he would apply it. Good thing he went to Hilbert Curves and I learnt something new today

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

    This guy has huge knowledge and logic I wish I could have 1% of him...everything went out of my mind I could not understand anything

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

    This video deserves far more views/attention, excellent efforts

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

    One of the best content I have seen, in such a short time !!! Thanks Man !

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

      Thank you!

  • @kumarshashank3954
    @kumarshashank3954 3 роки тому +20

    Wow this is exactly what we were discussing in our project today

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

    Thanks a lot, I'm just 15. I learnt new thing. Bro you can yourself start a bigger company than Google.

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

    Wow! I like your style of teaching. This was very well explained. Keep it up!

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

    The most interesting video I have ever seen!!!
    Thanks!!

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

    This is basically masterclass in system design...inspiring

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

    Hi just commenting on channels which helped me in one way or the other, land a great job offer from a huge firm! Thanks! I shared the channel with other people too!

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

    Thanks for this one. Much anticipated one!

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

      More to come! 😁

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

    Love your videos Gaurav thanks a lot and keep them coming.

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

    Great Effort! Appreciate it!

  • @TheLearnersWay
    @TheLearnersWay 3 роки тому +10

    It's amazing, Literary encounters some new concepts and thoughts, we never heard before.
    Thank you so much, Sir🙂

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

      Thanks 😁

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

    Beautiful explanation and the best part is the way you explained the application of hilbert curve. Kudos!

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

      Thank you 😁

  • @punjtcs
    @punjtcs 6 місяців тому

    Great explanation of hilbert curve! thanks!

  • @nipunmittal19
    @nipunmittal19 3 роки тому +5

    Bro, today you have gained my utter respect for your knowledge and your passion to pursue more knowledge. This video is mind-blowing, So much profound mathematical concepts linking with hardcore real-life applications.

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

    When the Master teaches, us Students listen. thank you for the great video, most of it made sense towards the end,

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

    Always wanted to know this
    Finally 🙌

  • @hymnish_you
    @hymnish_you 3 роки тому +5

    Like before watch. That much, I trust your teaching skills.

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

      Appreciate that 😁

  • @ShubhamSharma-ii9jn
    @ShubhamSharma-ii9jn 3 роки тому

    So cool edits in the video. Perfect.

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

    Wonderful explanation! :)

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

    S_id, Hilbert curves I guess is the short answer? The fractal part was very interesting

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

    Thanks . Much needed

  • @Sumit-dn6ls
    @Sumit-dn6ls 3 роки тому +1

    Your passion for tech shows in your videos.
    I am not even a tech guy and i watched the whole video.

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

      😁

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

    Brilliant video, explained really well. Thanks Gaurav

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

    This is an ideal use of UA-cam.. . Well done GKCS

  • @SumitYadav-rg4di
    @SumitYadav-rg4di 3 роки тому +1

    your editing skills are too good like your teaching skills.

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

    Amazingly explained

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

    Enjoyed the video very much, Thanks gkcs Bhaiya!!

  • @bernard-ng
    @bernard-ng 3 роки тому

    Waouh thanks for your work, this video is what I was looking for

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

    Thanks, learned something new

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

    Gaurav man.. i always wanted to know about these Spatial Database topics concepts. Thanks alot 😊

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

    You really know how to explain. Keep it up 👍

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

    explained well, such a complicated topic.

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

    I was curious about how these apps work before watching this. Now I'm even more curious and feel i don't know anything . this is just great work!

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

      They have some super cool stuff under the hood 😁

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

      @@gkcs yep i hope to work on that under the hood stuff someday :P

  • @SaurabhKumar-mc1is
    @SaurabhKumar-mc1is 3 роки тому

    Respect for your knowledge Gaurav.

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

    Gr8 Content Gaurav ! Keep learning and sharing !

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

    Me: currently working on geo spatial visual representations
    Algorithm: where did that bring you? back to me.

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

    Got an opportunity to learn something new! Thanks so much!

  • @MdMehediHasan-mf9mc
    @MdMehediHasan-mf9mc 3 роки тому

    this is the channel i was looking for...

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

    Love the new intro bro!

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

    wow, this is alot of information in one video :D, ive watched it twice now, and im still confused. Ill get the hang of it though, thanks Guarav!!!

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

    Suppose we are using the Hilbert curve method on a 4 quadrant (A,B,C,D), when we are trying to get proximity of two points in A(top-left) & D(bottom-left). The proximity result would be "faaar away" in spite of being in adjacent quadrants. How do we overcome this problem?

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

    18:00 Hi Gaurav - I'm curious how we have the established configuration of the rotation of Hilbert curves within each quadrant?
    Also - thanks for reviewing that continuity of lines -> infinite partitioning - I forgot this cool property of continuity from epsilon-delta definitions - and showing the intuition of quad trees lending to range queries via the line segment.

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

    This dude is brilliant.

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

    truly beautiful

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

    Awesome... Trying to get this kind of solution for the proximity use case from loong time.. Happy to see this explanation.. Pls make the other video also here, not in your course🤓

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

    most underrated channel bro please do video on competitive program tutorial questions..love from nepal

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

    Very Nice explanation.

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

    I am really looking forward to the food delivery app system design!

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

    Wow! I'm mind blown.

  • @AnilKumar-ig8kk
    @AnilKumar-ig8kk 3 роки тому

    Wow Gaurav, you are amazing :), I learnt this concept from educative but your explanation is too good.

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

      Thanks 😁

  • @prashanttomar1842
    @prashanttomar1842 2 роки тому +1

    Every time I watch your videos I always learn something new and unique, appreciate your efforts. I have a doubt though, I am trying to solve the same range problem for my location-based application using coordinates with the haversine formula in my SQL query, coordinates are stored as 'char'. Please clarify if there's something wrong with my approach.

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

    this was great..

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

    kinda cool the 2 projection works incredibly well on most road systems since they are in effect a 2-D lattice so you are fine with 90 degree turns at some accuracy threshold.

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

      This video series explains a more suitable algorithm (A* search) for Google Maps:
      interviewready.io/learn/system-design-course/design-a-location-based-service-like-google-maps/requirements-of-a-map-application

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

    brilliant!

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

    Hats off !

  • @kashyap.devanshu
    @kashyap.devanshu 3 роки тому +8

    14:53 Why can’t we have 1 in fourth quadrant? Can you please elaborate the reason?
    And also explain why in certain permutation which number cannot be in which quadrant and why.
    thanks.

    • @gkcs
      @gkcs  3 роки тому +10

      We are taking permutations which form unique shapes. Hence we must exclude rotations of the same shape.
      At 14:53, a 1 in the third quadrant will give us a rotation of the first shape (Z).

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

    Nice!

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

    what database are you using? programming language?

  • @MadForCs16
    @MadForCs16 3 роки тому +5

    It is very moralising for me to see youtubers like yourself who make informative videos, and helping the community to push boundaries of the tech unlike those shitty youtubers who make roast/dank/game stream videos..

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

    Love you brother keep growing

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

    @Gaurav Sen : This is very unlike your other videos. Even the 1st 10 minutes is greek and latin perhaps a much longer video is needed for this topic. Neverthless a very interesting topic.

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

      Thanks for the feedback 🙂👍

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

    How Can I Develop A Database Which Stores Any User Decidede Location Rangewise??
    Means 500 meters Around My College.

  • @tssrinathyahoocom
    @tssrinathyahoocom 2 роки тому +1

    Have you considered using Radix/Patricia-Trie for proximity. Like Quad-Tree you just explained, it converts lat-lon into 1D by using an open-source library called Geohash.. After converting a lat-lon into a prefix string, we apply the trie. Proximity just becomes natural. I spent some time trying to run algorithm like finding if a point is in Geofence or not. Had some error but had encouraging result.

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

    Hey @Gaurav Sen can you post a link for the location-based databases which give more intuition on top of how these data apps or food delivery apps are based?

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

    Radically, IMPRESSIVE!!!!

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

      Thank you 😁

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

    I’m wondering, does this mean that problem of edge cases have no resolution and can be ignored? So users from regions 29 and 18 never won’t meet because they have distance of 11 in this representation which will exceeds the threshold?

  • @awreece
    @awreece 3 роки тому +10

    Great presentation, looking forward to seeing more.
    For anyone who wants more details on the theory, this is great: arxiv.org/pdf/1710.06384.pdf (The first ~20 pages are actually quite readable without getting proof heavy).
    They find neighbor cells exactly by recursively walking up and down the (implicit) quad tree formed by the space filling curve. Thus "... the runtime of the algorithm depends on how far one has to walk up and down the tree to find the neighbor. This concept is later introduced as the neighbor-depth of 𝑣. ... The neighbor-depth allows to characterize the runtime of the algorithm. In Theorem 4.1, we will show that the runtime of the algorithm is in 𝒪 (neighbor-depth) (assuming constant-time arithmetic operations). Using a standard geometric series argument, we will then show that the average neighbor-depth at level 𝑙 is 𝒪 (1) for all “normal” SFCs." (page 14)

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

      Good stuff!

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

    the coolest engineer

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

    hi Gaurav. your videos are awesome- I like how you make things simple to understand. Can you please do videos on elevator system design and parking lot management system.

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

    Hello @Gaurav
    Thanks for the nice explanation! I have a question on the partitioning and scalability of the hilbert curve in this solution.
    How would you partition the hilbert curve for maintaining scalability?

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

    Great video and concept as always. I have question-
    How do we find that node 5 is in close proximity of 57 58 59?

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

    Does the concept of proximity relates with a special form of non-Euclidean geometry called Taxicab Geometry developed by Hermann Minkowski ? As the points of locality are identified up with Hilbert space filling curve, the path seems identifiable with this Taxicab Geometry approach. Correct me, if I am going wrong with this.

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

    10:07 That T Shirt change though 🤣

  • @rahulsharma5030
    @rahulsharma5030 2 роки тому +1

    @4:47, can someone explain how this example works? mapping 5 in range 4 to 7?