Programming Tips 101 - The Right Way To Access Hash table

Sdílet
Vložit
  • čas přidán 7. 09. 2024
  • In this video, I am discussing what most programmers do while accessing the hash map or hash table which they don't need to. What they do is that they just waste CPU cycles and consume more power and they can very easily change the code to be 2x faster and consuming half power.
    This is a new programming tips series I am starting. Let me know in the comments do you find such videos useful or not.
    Please follow me on / think.software.community if you like to get notified about new course chapters getting added or when we will start another round of mock interviews and you want to participate in mock interviews or any other updates. I will also take your suggestions there about the course and the channel.
    Check out our following articles:
    - How to Ace Object-Oriented Design Interviews: / how-to-ace-object-orie...
    - Elevator System Design - A tricky technical interview question: / elevator-system-design...
    - System Design of URL Shortening Service like TinyURL: / tinyurl-design-from-th...
    - File Sharing Service Like Dropbox Or Google Drive - How To Tackle System Design Interview: / how-to-tackle-system-d...
    - Design Twitter - Microservices Architecture of Twitter Service: / design-twitter-microse...
    FAANG #Facebook #Google #Amazon #Apple #Microsoft #Uber #Netflix #Oracle #Lyft #SystemDesign #Interview #ComputerProgramming #ProgrammingTips101

Komentáře • 37

  • @ThinkSoftware
    @ThinkSoftware  Před 4 lety +3

    Please let me know in the comments below, do you find this video useful and do you like me to make more such videos? Also please do like the video on the CZcams website if you find this video useful. Thanks.

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

    A very basic but a good point. Generally people use the 2x approach. Its good that you pointed out

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

    I use -> Value getValue {
    return config.getOrDefault(paramKey, someDefaultValue)
    }

  • @rchromatic
    @rchromatic Před 6 měsíci

    Thanks for the videos, especially about System Design.
    At 5:50 you said that unordered_map throws an exception if there is no such key - this is not true.
    In this case hash map will create a new entry with constructing a default obj and return it.
    Moreover, STL does not throw exceptions if developer uses [] to get to something (vector, map, unordered_map) it does only if you call method at(). It is done for the sake of performance. So developer should be wise and pick the right way to access to the element in the container.

  • @letstalkcareerwithradhika9028

    This is such an unnoticeable but big mistake we make while coding. Thanks! 🙏 keep making such amazing videos!

  • @ibrahimshaikh3642
    @ibrahimshaikh3642 Před 4 lety

    Keep making like this, loving ur videos

  • @HrishiKesav
    @HrishiKesav Před 4 lety

    The trick to avoid the containsKey() - that was very informative. Thank you for sharing the info.
    Looking forward to more videos in this channel.
    I also have the following questions:
    1) The method getData() is a synchronized method. So, shouldn’t we use a ConcurrentHashMap here, I know the major point here was how to avoid accessing the map two times to check if key is there or not, but still checking.
    2) In the second example, in the method getSomeParameterFromConfig(), the map.getOrDefault() would be more appropriate, right?

    • @ThinkSoftware
      @ThinkSoftware  Před 4 lety

      Thanks for the comment. Regarding your questions 1) using concurrent map depends on the use case and this video was not targeting that. 2) yes you can use that in case of Java.

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

    When are you uploading the next video?

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

    A very basic but useful video. Thank you. I have a career question: For most of the roles in tech companies there are some years of experience as criteria mentioned in the job post. For example: for SDE 3 they need 8 years of experience, etc. Is it mandatory to have those many years of experience as mentioned. What if someone has less experience but still can clear the SDE 3 bar. Will the big tech companies consider such candidate?

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

      The company will not offer you SDE 3 simply because you have clear the SDE 3 interview bar in an interview. The company will only offer you SDE 3 if there is a need. E.g. you have enough experience that would require them to justify you as SDE 3 and if they downlevel you then their own management can question the hiring manager. Or you are already at SDE 3 level in your current company and you may not join them as SDE 2 because you tell them during negotiation that you will not take downlevel. Or you have competing offers where other companies are offering you SDE 3 or higher pay which that company can only offer you at SDE 3 level. So it then all boils down to your negotiation skills (after your interview performance) and your circumstances.

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

      @@ThinkSoftware I got your point. Thank you :)

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

    As a Java programmer, I would probably use computeIfAbsent()

    • @ThinkSoftware
      @ThinkSoftware  Před 4 lety

      Yes. The point is to avoid two lookups if possible. Were you doing two lookups till now or one lookup?

  • @yogeshkumargupta265
    @yogeshkumargupta265 Před 3 lety

    Hey, there is no put(obj) method on the map. You will have to put(Key, obj). Please correct it on the first example.
    For the second code, You can use getDefault method on Hashmap interface, which takes a key and a default value. If Key does not exists, it directly returns the default value; which is what you are trying to do here essentially.

    • @ThinkSoftware
      @ThinkSoftware  Před 3 lety

      Just a mistake. For getDefault() it is present in Java but not in C++ and I was giving a general example.

  • @saurabhsharma7123
    @saurabhsharma7123 Před 3 lety

    Thanks for the tip.

  • @IhsaanTyalor
    @IhsaanTyalor Před 4 lety

    For getData, why does the code also include functionality of constructing the object and putting it into the cache?? That was surprising to me.

    • @ThinkSoftware
      @ThinkSoftware  Před 4 lety

      It depends on the functional requirement of the function. Requirement could be getData() always return data, either from local cache or if not in cache then go to DB to get data. However this was not the point of the video.

    • @IhsaanTyalor
      @IhsaanTyalor Před 4 lety

      Think Software That makes sense

  • @kaushalrjain6326
    @kaushalrjain6326 Před 4 lety

    What are your thoughts about the engineering manager career path? In contrast to an individual contributor?

    • @ThinkSoftware
      @ThinkSoftware  Před 4 lety

      They require different jobs, skill-sets and mindset. Some people enjoy doing it and some not. I personally don't like some aspects of this job like performance evaluation, putting people on PIP or layoffs etc.

  • @KaushikGaliya
    @KaushikGaliya Před 3 lety

    this is good

  • @yoyonevertheless7226
    @yoyonevertheless7226 Před 4 lety

    good to know this! but i think this code is not thread-safe ;) that's another problem

    • @ThinkSoftware
      @ThinkSoftware  Před 4 lety

      Thanks for the comment 🙂. Yes it is not but that was not point of this video.

    • @tanayshah275
      @tanayshah275 Před 3 lety

      Hi, I like to learn why it is not thread safe. Can you give some explanation or provide some resource where I can look it up.

  • @AshishGupta-lw5sl
    @AshishGupta-lw5sl Před 4 lety

    how to handle a case when value of a key is NULL/None

  • @obamabinladen5055
    @obamabinladen5055 Před 3 lety

    1 / 10 :D