Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Computer Science Introduction to Algorithms Time Complexity Efficiency of an Algorithm

hamdan hassan
PLUS
hamdan hassan
Courses Plus Student 589 Points

What is big O?

I didn't understand what big O is. Can some explain it in a simpler way?

3 Answers

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 Points

Big O measures how efficient (or inefficient) your algorithm is as the input grows. When you're website or app scales to many users doing many things, the efficiency of your algorithms starts to really matter. A user waiting 1 second to see the result of a query is fine, but not 10 seconds or 100 seconds. Businesses also spend thousands or millions on cloud computing, so you wouldn't want to spend any more money than you have to.

An algorithm with big O(n) is going to mean as the input (n) grows, the time efficiency grows linearly. Linear search is an example of O(n). So if searching through 100 records takes 1 second, searching through 1000 records would take 10 seconds. Binary search is an example of O(log n), so if searching through 100 records takes 1 second, searching through 1000 records would take 2 seconds. (I'm pretty sure...someone correct me if my math is wrong.)

For small amounts, this doesn't really matter. But if you're a big website and you have millions of records, this starts to really matter - the difference between long wait times or not, or millions of dollars in computing costs.

Mike Hatch
Mike Hatch
14,940 Points

Thank you. This is really only important to know if you have big developer dreams of working at a big tech company like Google or Facebook, right? This isn't necessary to know for small time developers who may just want to work for small to medium size companies, or better yet, on their own?

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 Points

Are you aiming to be a small time developer? If so, why? A lot of small businesses now are just making their website with something like Squarespace. They don't necessarily need a bespoke website coded from scratch. You also might find yourself at a small firm that still has to deal with scale anyway in their particular niche (like doing some analysis on big data). Software is difficult and expensive to build, so it kind of makes sense that we use it to solve big problems rather than small problems. Solving bigger problems also increases your potential salary, since you're likely to earn a salary that's some proportion of the value you're creating for others.

As far as the job interview process goes, I've had a mixed experience whether or not this stuff matters. Some interviews put a lot of emphasis on algorithms and big 0, and others were more about general knowledge of languages, frameworks, software development process. I recommend reading Cracking the Coding Interview. There's a chapter where the author explains how employers sometimes see competency in topics like algorithms as a proxy for other things. They can't really put all their complex business logic in front of you and see how you grapple with it. But they can watch you try and work out an efficient algorithm for a problem, and their bet is that competency in one correlates with competency in the other. She also has a youtube playlist with HackerRank that's excellent.

Mike Hatch
Mike Hatch
14,940 Points

No, I'm not aiming small but I also know what is realistic and what isn't. Ryan Carson himself said that it's impossible to get a job at companies like Facebook or Google without a CS degree. He said this was a good thing as it opens up a lot of doors for the rest of us. The other companies can't get the CS grads.

This stuff has been helpful and is proving me with a new thought process when looking at and writing code. I've been in tutorial mode for a year now and I'd rather not take courses that aren't going to get me closer to an actual job in coding. That's more or less what I was getting at,

So I thought the same thing, That i'd never get anywhere without a cs degree, and while I struggled to find basic internships I almost started questioning whether these courses on treehouse were worth it. But i'd highly disagree, you definitely can get a job at those big companies without a cs degree. Thats partly why im taking this course right now. Opportunities can spring up, It never hurts to learn. ;)

Rochelle Burrows
Rochelle Burrows
8,528 Points

Can I just add that I know people who are living proof that you don't need a degree - yes I said degree as a whole, not just a CS degree - to get a job at the big companies. Hard work, determination and a willingness to learn are key. It has happened for many people and it can happen for you. It might be harder, yes, but it is not impossible. If you want something, go for it. Don't listen to anyone who tells you it's not possible. Good luck!