Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,133 members, 7,814,961 topics. Date: Thursday, 02 May 2024 at 02:07 AM

Time Complexity Guide For Developers - A Short Primer - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Time Complexity Guide For Developers - A Short Primer (860 Views)

For Developers, How Did You Get Your First Remote Job And What Was The Pay. / Explain Time Complexity To Me Like A 5 Year Old / Software developers. A question regarding work-life balance. (2) (3) (4)

(1) (Reply)

Time Complexity Guide For Developers - A Short Primer by harryobas: 2:04pm On Apr 16, 2019
As a developer, time complexity is one of the most interesting concepts you can learn from computer science, and you don’t need a degree to understand it!


It’s interesting because it helps you see why a particular algorithm or program may be slow and what can you do to make it faster.

Slow vs Fast

Is sorting 1 million numbers in 150ms (milliseconds) slow or fast? I think that’s pretty fast, but this is not the question that time complexity is trying to answer. We want to know how an algorithm is going to perform as the “input size” grows.

When we talk about “input size” we are talking about the arguments for the function or method. If a method takes one string as an argument then that’s the input, and the string’s length is the input size.

Big O Notation

With Big O notation we can classify algorithms according to their performance. Some examples of this notation are shown below:

1. O(1) - In this case, O(1) represents a “constant time” algorithm. That means that the algorithm will always take the same time to finish its work, regardless of how much work it has to do.

2. O(n) - In this case, O(n) represents "linear time". Where “n” represents the size of the input (string size, array size, etc). This means that the algorithm will finish its work in a 1:1 relation to input size, so doubling the input size will also double the time it takes to complete the work.

Happy Coding smiley
Re: Time Complexity Guide For Developers - A Short Primer by abula112(m): 7:32pm On Apr 16, 2019
harryobas:
As a developer, time complexity is one of the most interesting concepts you can learn from computer science, and you don’t need a degree to understand it!


It’s interesting because it helps you see why a particular algorithm or program may be slow and what can you do to make it faster.

Slow vs Fast

Is sorting 1 million numbers in 150ms (milliseconds) slow or fast? I think that’s pretty fast, but this is not the question that time complexity is trying to answer. We want to know how an algorithm is going to perform as the “input size” grows.

When we talk about “input size” we are talking about the arguments for the function or method. If a method takes one string as an argument then that’s the input, and the string’s length is the input size.

Big O Notation

With Big O notation we can classify algorithms according to their performance. Some examples of this notation are shown below:

1. O(1) - In this case, O(1) represents a “constant time” algorithm. That means that the algorithm will always take the same time to finish its work, regardless of how much work it has to do.

2. O(n) - In this case, O(n) represents "linear time". Where “n” represents the size of the input (string size, array size, etc). This means that the algorithm will finish its work in a 1:1 relation to input size, so doubling the input size will also double the time it takes to complete the work.

Happy Coding smiley
is that all?
Re: Time Complexity Guide For Developers - A Short Primer by ANTONINEUTRON(m): 9:08pm On Apr 18, 2019
There is also quadratic, logarithmic,exponential,polynomial and many more complexities.

My work diz semester.
Data structures and algorithm is really cool tho!

(1) (Reply)

100dayscodechallenge For Anyone Interested / PHP Developer Needed / When Is The Next Edition Of Coding Competition On Nairaland ?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 12
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.