DEV Community

Cover image for Big O notation For dummies

Big O notation For dummies

Ezpie on June 29, 2024

When it comes to programming there is one thing we all dev suck at... well mostly the new devs. And that's big O notation. So here's what Big O is ...
Collapse
 
davitacols profile image
David Ansa

The whole concept of Datastructures and Algorithms is the most essential aspect every developer should be conscious of.

Collapse
 
ezpieco profile image
Ezpie

Yeah, if you don't do DSA you won't get a job! Of course, there is more to it, but mostly the job factor, and surely becomes a lot easier to understand a problem in a more code perspective. It truly helps.

Collapse
 
nmitic profile image
Nikola Mitic • Edited

Yes absolutely for the job hunting. However, not every developer needs it for day to day work. And with limited time one should be careful about what to study. I hate it that DSA is standard in our job interview. It tells me that one is good or bad at DSA. Not that it has more or less potential to be a great engineer, which is a lot more than coding. Just saying.

Thread Thread
 
ezpieco profile image
Ezpie

I know right? Job interviews are most of the time DSA focus. They just don't seem to get it.

Thread Thread
 
nmitic profile image
Nikola Mitic

My friend, I spent so much time meditating on the concept of "them"

Who are those people? Going a bit offtopic I had so much struggle looking for a job in tech, and always had this thought. Why can't "they" seems to get it?

I believe "they" are actually you and me.

I have seen so many developers who as soon as they are promoted keep doing as everyone else, not changing or challenges status quo.

Thus, nothing changing ever.

So, I don't know you Ezpie, but if you are ever in a position to influence interview process. Maybe you should do it. And if job requires knowledge of DSA, absolutely nothing wrong with testing ones ability to do them.

All the best to you. I am doing my part to the best of my abilities.

Niko

Thread Thread
 
ezpieco profile image
Ezpie

By "they" I meant both the interviewers and us... don't mind my English it's bad I know. And I agree and disagree with this take. You see most people start to get hold over DSA, now I am not saying that DSA is bad my take is, that DSA is great, but only at a certain limit, of course here I wouldn't refer to CSS, but that doesn't mean it's not important, now of course no one would do a CSS interview of course. But the point is, I don't like it once the interviewer goes, "Can you do a dijkstra algorithm", which to me is a concerning question, because it tests if the candidate can solve a problem requiring the dijkstra algorithm, but it does not test if the candidate is capable of really solving a problem, cause I mean how many combinations of dijkstra question is one going to make? I just have to learn the algorithm, do a bunch of dijkstra questions, and done. I can pass an interview. Now of course keep in mind I am not saying that DSA is useless, it is useful, but asking it in an interview? I mean you can ask it, but at a limit, I prefer to go by more role-specific questions, because these questions are the ones that can tell if a candidate fits for the role or not. For a more proper POV, here in India, we have IIT, it's a standard university for entering software engineering, in fact, if you are an IIT graduate, big tech companies come straight to you for an interview, and you don't even have to apply. And I can understand why, because we Indians are really grade focused, here in India if you don't get above 93% you are considered almost useless I would say. And it has its own side effects, most IIT grades know their DSA really well, except that they don't really know how to make production-ready code, take any Indian, they can solve problems in theory but won't be able to solve it practically. And that's a downfall.

This is more of my opinion, not sure how it really goes but this is what I have seen.

Thread Thread
 
nmitic profile image
Nikola Mitic

Wow. Thanks for sharing this. Learned a lot. I agree with literally everything.

Thread Thread
 
davitacols profile image
David Ansa

This thread has been most educative, even I have learned alot and it is a beautiful thing.

Thread Thread
 
ezpieco profile image
Ezpie

It would be best if you stuck around because I am currently working on a very toxic post... it's clean code. That's the most misleading topic and I would like to cover it and show how real production-ready code is written. Of course, now I am not a professional so, that's just an opinion.

Thread Thread
 
davitacols profile image
David Ansa

Greeat.

Thread Thread
 
davitacols profile image
David Ansa

don't forget to please star my opensource project dataDisk. version 1.1.0 is on pypi ready to use, just

pip install dataDisk
Enter fullscreen mode Exit fullscreen mode

Currently working on 1.2.1 with more interesting features and machine learning capabilities.

Thread Thread
 
ezpieco profile image
Ezpie

sure give me the link and I will check it out.

Thread Thread
 
davitacols profile image
David Ansa
Collapse
 
miketalbot profile image
Mike Talbot ⭐ • Edited

I'm not sure I agree that O(1) is a myth - for the entire program? Yes, then it's not possible. But optimising a search using O(1) rather than O(log n) is a massive improvement at the expense of memory and is something you should consider frequently.

If you have 1,000,000 (call it n) items in a set and you want to check 1,000 items against it (call it m) then using a "HashSet" for the n items is going to be dramatically faster than a binary searched sorted array.

HashSet = m * O(1) = m
Binary Search = m * O(log n)

In the example, the binary search is ~20x slower than the HashSet. Clearly, the HashSet implementation will have "some" impact on that improvement, but that's why Big O is so useful to rule-of-thumb things.

Also, creating that sorted array in the first place is 20 times slower than adding them all to a HashSet, so unless its already stored that way, then the O(1) approach is much preferred.