Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When (not how or why) to calculate Big O of an algorithm

I was asked this question in an interview recently and was curious as to what others thought.

"When should you calculate Big O?"

Most sites/books talk about HOW to calc Big O but not actually when you should do it. I'm an entry level developer and I have minimal experience so I'm not sure if I'm thinking on the right track. My thinking is you would have a target Big O to work towards, develop the algorithm then calculate the Big O. Then try to refactor the algorithm for efficiency.

My question then becomes is this what actually happens in industry or am I far off?

like image 264
Brian Phair Avatar asked Apr 03 '19 16:04

Brian Phair


1 Answers

"When should you calculate Big O?"

When you care about the Time Complexity of the algorithm.

When do I care?

When you need to make your algorithm to be able to scale, meaning that it's expected to have big datasets as input to your algorithm (e.g. number of points and number of dimensions in a nearest neighbor algorithm).

Most notably, when you want to compare algorithms!

You are asked to do a task, for which several algorithms can be applied to. Which one do you choose? You compare the Space, Time and development/maintenance complexities of them, and choose the one that best fits your needs.

like image 66
gsamaras Avatar answered Sep 28 '22 11:09

gsamaras