Why The Logarithm Is So Important For Algorithms & Data Structures

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 มิ.ย. 2024
  • This is why the logarithm is so important for algorithms, data structures, big o notation, and general software engineering.
    AlgoExpert: www.algoexpert.io/clem
    SystemsExpert: www.systemsexpert.io/clem
    MLExpert: www.algoexpert.io/ml
    My LinkedIn: / clementmihailescu
    My Twitter: / clemmihai
    My Instagram: / clement_mihailescu
    Prepping for coding interviews or systems design interviews? Practice with hundreds of video explanations of popular interview questions and a full-fledged coding workspace on AlgoExpert - www.algoexpert.io - and use the promo code "clem" for a discount on the platform!
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 223

  • @juliansteden2980
    @juliansteden2980 2 ปีที่แล้ว +179

    Very good video but the math in your example is wrong ;)
    4 billion nanoseconds are 4 seconds (1 billion = 1e9; 1 ns = 1e-9s).
    Nevertheless the logarithmic calculation is 134,217,728 x faster (2^32 / 32)

    • @lalitac
      @lalitac 2 ปีที่แล้ว +20

      Correct. But how fast the algorithm with logarithmic time complexity is, as compared to algorithm with linear time complexity, depends. For 4 Billion elementary operations, linear one takes 4E9 nanoseconds while the logarithmic one takes 32 nanoseconds. So, in this case the algorithm with logarithmic time complexity is 4E9/32 i.e. 125,000,000x [125 Million times] faster.

    • @clem
      @clem  2 ปีที่แล้ว +105

      Argh! This is why you get someone to review your code (or video, in this case 😛) Yes, of course, 1ns = 10^(-9)s, so 4 billion nanos is 4s. I too quickly trusted what I saw on Google by typing "4 billion nanoseconds in days," which deceived my eyes. The analogy still certainly stands, because the logarithmic algorithm is a whopping 125 million times faster than its linear counterpart, but thank you for the correction!

    • @masternobody1896
      @masternobody1896 2 ปีที่แล้ว +6

      @@clem I want to get a job at google faster than the speed of light

    • @masternobody1896
      @masternobody1896 2 ปีที่แล้ว +2

      @@clem thanks for the inspiration

    • @masternobody1896
      @masternobody1896 2 ปีที่แล้ว +2

      @@clem never ever give up - elon musk. i want to like elon musk and I want to be like you also

  • @galdamez3
    @galdamez3 2 ปีที่แล้ว +62

    I always had a hard time explaining logarithmic time because I didn’t understand the math. Problem solved. This is one of the best explainer videos I’ve seen in a while.

    • @KKkaptan
      @KKkaptan 2 ปีที่แล้ว +7

      Conceptually, think about logarithm base (b) of x as the number of times you need to divide x by b until the answer is

  • @harispapadopoulos4295
    @harispapadopoulos4295 2 ปีที่แล้ว +21

    Hell yeah. I love getting stuff explained to me by clement. I still remember the logarithm video from algoexpert but getting a refresher was nice

  • @peterelst
    @peterelst 2 ปีที่แล้ว +133

    weird edit of the opening but useful topic

    • @whatinthebloodyhell
      @whatinthebloodyhell 2 ปีที่แล้ว +2

      😂

    • @clem
      @clem  2 ปีที่แล้ว +61

      😂I wanted to tempt users into watching the full video with an arguably intriguing glimpse at a clip from later on in the video, but perhaps the edit wasn't that great 😛

    • @avijitpaul4443
      @avijitpaul4443 2 ปีที่แล้ว +2

      @@clem 😂😂😂

    • @milkymoo16472
      @milkymoo16472 2 ปีที่แล้ว +2

      @@clem Nah mate you got me hooked and made me watch it!

  • @sportsgamingcubing1860
    @sportsgamingcubing1860 2 ปีที่แล้ว +13

    Fantastic timing! I am working on a crazy 2 week assignment for a college course at the moment and it has a bunch of runtime complexity problems so this is super useful for me!

  • @rajvis16
    @rajvis16 2 ปีที่แล้ว +5

    You watch so many videos but there are very few videos that make you feel wiser after watching them. This is truly one of them. The way you explained, I hope the professor in the colleges. are able to explain is such a simple way.

  • @jakariasami
    @jakariasami 2 ปีที่แล้ว +25

    This video was amazing! Would LOVE to watch more videos where you explain these types of things. I really mean it.

    • @clem
      @clem  2 ปีที่แล้ว

      I really appreciate it! I'll see if there are other topics I can try to simplify like this one!

  • @farhadpagdiwala1789
    @farhadpagdiwala1789 2 ปีที่แล้ว +2

    Excellent video Clement. Thoroughly enjoyed watching this for refreshing and jogging my memory on why binary search and trees are so important in Algos and DS.

  • @irinagr
    @irinagr 2 ปีที่แล้ว +4

    Thanks for pointing the importance of logarithms! Awesome, short and spot on explaination!

  • @frushlife
    @frushlife 2 ปีที่แล้ว +1

    Clem thank you so much - I've watched countless videos over the last few days trying to wrap my head around Big O and this was my lightbulb moment - Software dev with 5 odd years professional experience with zero math / algorithms background who has ignored this stuff forever

  • @Earth-Worm-Tim
    @Earth-Worm-Tim 2 ปีที่แล้ว +2

    Outstanding! I have always found this to be a rather complex topic to really grasp.

  • @kayra4080
    @kayra4080 2 ปีที่แล้ว

    Thank you so much! This made my newly starting informatics journey much more easier, keep up the great work!

  • @z4ar
    @z4ar 2 ปีที่แล้ว +1

    Can't believe I sat through all of this completley focused and invested lol. Starting my compsci study this fall and this was very insightful. Thanks!!

  • @jaagviveluguleti4271
    @jaagviveluguleti4271 2 ปีที่แล้ว +1

    Most valuable video I have received today and exactly what I was looking for....yesterday I watched your How to learn faster video and there you were stating the importance of logarithms...so I was looking for the free video of yours but couldn't find it in your website....now that you've mentioned it.....what a timing!!!! My manifestation always works.

  • @maxxpellowski2916
    @maxxpellowski2916 2 ปีที่แล้ว +1

    Brilliant explanation, sir. NOW I understand how important they are. Thanks for opening my eyes, yet again.

  • @BhupendraSingh-dl5lj
    @BhupendraSingh-dl5lj 2 ปีที่แล้ว +1

    The best explanation I have seen on the Internet. Perfect

  • @amixengineer
    @amixengineer 2 ปีที่แล้ว

    great video, great explanation, I smashed the subscribe button just to look forward seeing these types of videos. well done and thanks Clément.

  • @sergpodolnii3962
    @sergpodolnii3962 2 ปีที่แล้ว +3

    As a person with STEM background I should say that under normal log or ln we usually imply reverse to e^x operation (in electronics engineering convention for log - reverse to 10^x for multitude of dB units). Exponents and ln operations go hand in hand when you deal with calculus more or less on regular basis. And this guy is Log2, what can be a point of confusion.

  • @Leshpngo
    @Leshpngo ปีที่แล้ว

    This was so cool, it felt like I was grabbing the power lines of cs. Thanks Clement this was a amazing video.

  • @charlesopuoro5295
    @charlesopuoro5295 ปีที่แล้ว

    I absolutely found it insightful. Thanks so much for this.

  • @Jared-Cruz
    @Jared-Cruz 2 ปีที่แล้ว +6

    You explained this in a way that a non-software engineer or even math savvy person could understand. Fantastic job!

    • @eloka9015
      @eloka9015 ปีที่แล้ว +1

      i'm literally a law student and i got it!

  • @AleX_028
    @AleX_028 2 ปีที่แล้ว +1

    Sir what an explanation...I never thought logarithms in such perspective and thank you much for that this knowledge I won't forget for my entire life .
    *Hands down*

  • @suvammondal7053
    @suvammondal7053 2 ปีที่แล้ว

    Beautifully explained, loved it.

  • @sathwicsardana9690
    @sathwicsardana9690 2 ปีที่แล้ว

    Awesome explanation -- simplified, distilled and de-mystified

  • @KaleemKhan-dr4vi
    @KaleemKhan-dr4vi ปีที่แล้ว

    This is the most amazing explanation I have seen.

  • @mettanotation
    @mettanotation ปีที่แล้ว +2

    Great video 👍🏼. Big-O assumes fundamental operations are the same speed, but it’s useful to know IRL they are different and that can make a huge difference. Famously, John Carmack when developing Quake had to optimize the inverse square root operation as part of the algorithms that made the game playable. I was a game dev before I got my CS degree and it always seemed a little odd detailed optimization wasn’t taught. Oh well theory vs practice I guess.

  • @wian7284
    @wian7284 2 ปีที่แล้ว +1

    Hey Clement, great stuff with something like this :)
    also on a slightly different note I felt some energy shift in your overall personality outlook from the video..kinda like did you changed a bit in anyway or with something that's going on lately? :p

  • @MagedMegz95
    @MagedMegz95 2 ปีที่แล้ว

    Amazing. Just amazingly and simply explained. Thanks.

  • @Eww...NotTheHumansAgain
    @Eww...NotTheHumansAgain ปีที่แล้ว

    A very useful explanation. Thank you!

  • @somnathpaul3004
    @somnathpaul3004 2 ปีที่แล้ว

    Superb explanation. It was never that much easy to me before this video.

  • @siphokazimanana7677
    @siphokazimanana7677 2 ปีที่แล้ว

    Well done!!!! Very thoughtful way to explain it

  • @malanbandara
    @malanbandara 2 ปีที่แล้ว

    Wow
    Clement you're really good at teaching. Thank you

  • @brandonblackwell1216
    @brandonblackwell1216 ปีที่แล้ว

    Best explanation I have ever heard. You are one of a kind sir.

  • @KrishnaKaliyuga
    @KrishnaKaliyuga ปีที่แล้ว +1

    Awesome Explanation
    Thank You

  • @mreagantn
    @mreagantn ปีที่แล้ว

    Great explanation. Thank you!

  • @godsdarkestangel4519
    @godsdarkestangel4519 2 ปีที่แล้ว

    Informative. Thanks Clément.

  • @sp3ctrums264
    @sp3ctrums264 2 ปีที่แล้ว

    Thank you! Explanation was so helpful

  • @seandougan8593
    @seandougan8593 หลายเดือนก่อน

    This was good, very to the point on why they are important

  • @thecodingfeast
    @thecodingfeast 2 ปีที่แล้ว +4

    It took me 24 years to realise what lag(x) is, thanks to clem!

  • @olga8687
    @olga8687 ปีที่แล้ว

    The best explanation of logarithm I've ever heard.

  • @AccessCode101
    @AccessCode101 2 ปีที่แล้ว +4

    Wow man, you should do more videos about math. I know that's your major but imagine how many people are looking to learn algebra and linear algebra or whatever type of algebra that can help them better understand algorithms.

  • @pratyushsrivastava4476
    @pratyushsrivastava4476 2 ปีที่แล้ว

    My college didn't prepare me for Time Complexity so I just ran over DSA like it was a normal subject. This really opened my eyes, Time to Learn again

  • @BJTangerine
    @BJTangerine 2 ปีที่แล้ว

    Very nicely explained, even a layman like me was engaged with your content

  • @vishaldhavale5234
    @vishaldhavale5234 2 ปีที่แล้ว

    Really great explanation..Thanks

  • @lethatsinkin
    @lethatsinkin ปีที่แล้ว

    This was super helpful!

  • @ursawarior4ever
    @ursawarior4ever 2 ปีที่แล้ว +1

    algorithms aside, i can tell youve been working out. Good stuff man.

  • @kjanshair
    @kjanshair 2 ปีที่แล้ว

    Brilliant Explanation.

  • @heyheyhey0220
    @heyheyhey0220 2 ปีที่แล้ว +1

    In algorithms we say O(log(n)) because all log bases are the same O set. They differ only by a constant coefficient and therefore are the same O.

  • @rachanasingh9476
    @rachanasingh9476 2 ปีที่แล้ว

    awesome video @Clément Mihailescu

  • @temiyeakinyemi6236
    @temiyeakinyemi6236 2 ปีที่แล้ว +1

    I completely understood this video because I just started learning what Big O notation is... Now I can see why O(log n) is better than O(n).

  • @kell7689
    @kell7689 2 ปีที่แล้ว

    Great explanation!

  • @vigneshravichandran2965
    @vigneshravichandran2965 2 ปีที่แล้ว

    great explanation , now I have realized how the time coplexity is O(log n )

  • @mauroquinteros8783
    @mauroquinteros8783 2 ปีที่แล้ว

    More visual would be excellent, thanks Clement!

  • @list9016
    @list9016 2 ปีที่แล้ว

    wow- i had no idea i was missing out on something this opowerful

  • @mariadmt8569
    @mariadmt8569 2 ปีที่แล้ว

    Mulțumesc pentru explicații!

  • @alambez
    @alambez 2 ปีที่แล้ว

    Thanks for the insights.

  • @tttmsu
    @tttmsu 2 ปีที่แล้ว

    Super helpful, thank you

  • @EwertonSilveiraAuckland
    @EwertonSilveiraAuckland ปีที่แล้ว

    Tks for the explanation 🎊

  • @quantumleap9520
    @quantumleap9520 2 ปีที่แล้ว

    Great Explanation

  • @Nikolai41Volkoff
    @Nikolai41Volkoff 2 ปีที่แล้ว

    dude, you're the man. thank you.

  • @TutorialTechie
    @TutorialTechie หลายเดือนก่อน +1

    I understand every bit he siad great explanation.

  • @kevinz1991
    @kevinz1991 2 ปีที่แล้ว

    Such an awesome video thank you 🙂

  • @ramseykarr6870
    @ramseykarr6870 2 ปีที่แล้ว

    Wonderful explanation 🙂

  • @1991hemanth
    @1991hemanth 2 ปีที่แล้ว

    Amazing explanation. 🔥🔥🔥

  • @marvet9573
    @marvet9573 2 ปีที่แล้ว

    Glad I subbed, logarithms actually mean something now other than a pain in the ass on my math exams lol

  • @luiscesar5450
    @luiscesar5450 2 ปีที่แล้ว

    This was good. Thanks

  • @oltialex
    @oltialex 2 ปีที่แล้ว +6

    "When a measure becomes a target, it ceases to be a good measure." Do you think this fits to the fact that big companies ask for algorithm problems and we blindly try to prepare for them?

  • @srivishnu8983
    @srivishnu8983 ปีที่แล้ว

    interestingly explained !!

  • @sameerplaynicals8790
    @sameerplaynicals8790 ปีที่แล้ว

    great explanation of log

  • @konstantindevelops131
    @konstantindevelops131 2 ปีที่แล้ว

    Understood better than from reading your LinkedIn Post hah Cheers for that!

  • @codecontent9717
    @codecontent9717 2 ปีที่แล้ว

    Hey man, please release a course or playlist for colleg dropout trying to learn computer science. One important thing is in what order to learn what and what to learn in parallel. Please consider maths too in it. It would help a lot of souls. Thanks and amazing work. Appreciate it, really.

  • @danielkakai2877
    @danielkakai2877 ปีที่แล้ว

    Great explanation

  • @jibin7277
    @jibin7277 2 ปีที่แล้ว

    very useful man !

  • @Vino359
    @Vino359 2 ปีที่แล้ว

    Thanks Clement

  • @ranjitbisai9335
    @ranjitbisai9335 ปีที่แล้ว

    very good explanation

  • @techienomadiso8970
    @techienomadiso8970 2 ปีที่แล้ว

    Wow such an interesting realization you've made me have today 💪😃. I never thought of the log this way.
    Now that means if our algorithm divides the list into k groups say 3 groups...we could use log to base k which is 3 in this case.
    🤦🔥🔥🔥💯💯💯 This is amazing

  • @billykotsos4642
    @billykotsos4642 2 ปีที่แล้ว

    Thanks, really helpful

  • @danielcardona5268
    @danielcardona5268 2 ปีที่แล้ว +3

    Nice video, to me thinking of logarithm is more intuitive if you think of it as the operation that tells you how many times you can successively divide by the base, instead of thing of it as a inverted power. Essentially “how many times can I chop in half“

    • @aperture0
      @aperture0 2 ปีที่แล้ว +1

      Nice. I just learnt it using 7 rule.

    • @T-The-K
      @T-The-K 9 หลายเดือนก่อน

      This helped ty!

  • @Jonathan-kx2be
    @Jonathan-kx2be ปีที่แล้ว

    great video helped a lot

  • @fatimalmasri7715
    @fatimalmasri7715 ปีที่แล้ว +1

    Omg i cant believe it u explain math in the best way ever i swear ure awesome

  • @Djangoo-uy1nl
    @Djangoo-uy1nl 2 ปีที่แล้ว +2

    Damn it Mr. Jeffreys this is how you explain stuff to students! Great explanation

  • @bhargavpandya9189
    @bhargavpandya9189 2 ปีที่แล้ว

    Do more technical videos like these please

  • @kyeiiih4422
    @kyeiiih4422 2 ปีที่แล้ว

    Just a dope explanation

  • @anshukmishra4520
    @anshukmishra4520 2 ปีที่แล้ว

    Very Helpful video

  • @asyrafsyahla7868
    @asyrafsyahla7868 2 ปีที่แล้ว

    very useful video to Understand

  • @ForWork-mj9fv
    @ForWork-mj9fv 17 วันที่ผ่านมา

    I just had one wish, why is youtube not Medium where I can give you 50likes, cause you deserve Everything good in life brother. for this beautiful explanation 💯.

  • @mishadaro9759
    @mishadaro9759 2 ปีที่แล้ว

    at last, I understand. Some articles complicate this so much...

  • @_Anna_Nass_
    @_Anna_Nass_ ปีที่แล้ว

    Unrelated but you have some fantastic bone structure, dude.

  • @anshukmishra4520
    @anshukmishra4520 2 ปีที่แล้ว

    TH-cam should promote this kind of video

  • @lalitac
    @lalitac 2 ปีที่แล้ว +7

    I greatly appreciate this video but just want to point out one correction that might help people get the correct understanding of the time complexity problem you presented. First of all, 1 nanosecond = E-9 second [here E is the engineering notation] i.e. 1 Billion nanoseconds make 1 second. Now, if the algorithm with linear time complexity performs 4 Billion [4E9] elementary operations, each taking 1 nanosecond, it will take 4 Billion [4E9] nanoseconds i.e. 4 seconds to execute. On the other hand, if the algorithm has logarithmic time complexity, it will take ~32 nanoseconds to execute 4 Billion elementary operations. Now, this is still really remarkable. We just can't imagine and comprehend how quick 32 nanoseconds really are. To put into perspective, in the time required by the algorithm with linear time complexity to execute i.e. 4 seconds, the algorithm with logarithmic time complexity can be executed 125 Million times. Logarithm is so fascinating!
    - A high school senior

    • @lalitac
      @lalitac 2 ปีที่แล้ว +1

      @Peace Roasted Engineering notation or engineering form is a version of scientific notation in which the exponent of ten must be divisible by three (i.e., they are powers of a thousand, but written as, for example, 10^6 instead of 1000^2). As an alternative to writing powers of 10, SI prefixes can be used, which also usually provide steps of a factor of a thousand.
      Source: Wikipedia

    • @lalitac
      @lalitac 2 ปีที่แล้ว +1

      @Peace Roasted I think it's fairly common.

    • @clem
      @clem  2 ปีที่แล้ว +1

      Argh! This is why you get someone to review your code (or video, in this case 😛) Yes, you're totally right. I too quickly trusted what I saw on Google by typing "4 billion nanoseconds in days," which deceived my eyes. The analogy still certainly stands, as you very nicely highlighted with your perspective, but thank you for the correction!

    • @lalitac
      @lalitac 2 ปีที่แล้ว +1

      @@clem No problem when you've got Peer Reviewers!

    • @kpm25
      @kpm25 2 ปีที่แล้ว

      @@clem.. no offense.. but why would you have to Google 4 billion nano seconds of you are a software engineer?? I was interested to do your course but now you put doubt in my mind.

  • @rhen4610
    @rhen4610 2 ปีที่แล้ว

    I will come back to this few years later after I graduate on my Computer Science college. Philippine College is real slow and basic compare to high standards college like in the US

  • @pablon3115
    @pablon3115 2 ปีที่แล้ว

    I'm not sure if logarithmic time complexity requires to operarate in parallel (with concurrency or multithreading) to make sense. In case of adding the numbers of an array of eight elements, in a logarithmic time complexity, once the array is split in three levels, then it will perform each sum in parallel. For instance, for the first operation, at the same time it will perform: 1+2=3; 3+4=7; 5+6=11; 7+8=15. Then for the second operation, also at the same time: 3+7=10; 11+15=26. And for the third operation, also at the same time 10+26=36.
    Am I right?

  • @eric000
    @eric000 2 ปีที่แล้ว

    In the real computing world for simplicity O(log n) can be thought of as O(1) when weighted against O(n) and O(nlogn) as O(n) when compared to O(n^2) algorithms etc right? to make things simpler right? for worst case big O scenarios.

  • @FahmiEshaq
    @FahmiEshaq 2 ปีที่แล้ว

    man! excellent content

  • @criptik5208
    @criptik5208 2 ปีที่แล้ว +1

    How do you study after tuning light off, domt you form algos in pen and paper

  • @Why_I_am_a_theist
    @Why_I_am_a_theist 2 ปีที่แล้ว

    New ad of SystemExpert

  • @Nnip9
    @Nnip9 2 ปีที่แล้ว

    Fantastic speaker. I wish I had those skills. To those who corrected Clement for not getting it right about how long 4 billion calculations took: please stop. He made it clear he didn't know or need to know to make his point.

  • @TonyBrackins-kt6ie
    @TonyBrackins-kt6ie 5 หลายเดือนก่อน

    Wow. Really good.

  • @avi12
    @avi12 2 ปีที่แล้ว +4

    0:02 Did you forget to edit this out?

    • @Haylem
      @Haylem 2 ปีที่แล้ว +1

      lol it happens

    • @clem
      @clem  2 ปีที่แล้ว +2

      😂It was meant to make people want to watch the video more! I guess it didn't have the intended effect 😬

    • @Haylem
      @Haylem 2 ปีที่แล้ว

      @@clem You're always 2 steps ahead of us, checkmate.

  • @lincolnkroll
    @lincolnkroll 2 ปีที่แล้ว

    Thank you!