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 Constant and Logarithmic Time

1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

Computational Complexity is the length, in time, an algorithm takes relative to the size of data the algorithm operates upon. Algorithms are classified by their complexity. Examples are:

  • O(1) – constant time. Algorithm time is independent of the data set size
  • O(log n) – “log n time”. Algorithm time grows much slower than the data set size. Binary search is an example.
  • O(n) – linear time. Algorithm time grows proportionally the same the data set size grows. Example is inserting into a list since, in worst case, every data item must be compared to inserted value
  • O(n log n) – “n log n time”. Algorithm time grows slightly faster than linear time. Example is merge sort.

Other examples of complexity can be found on Stack Overflow.

Post back if you need more help. Good luck!!!