Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Computer Science Introduction to Algorithms Time Complexity Constant and Logarithmic Time

1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 68,082 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!!!