Click here to Skip to main content
15,908,673 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm learning about the time complexity of algorithms. As far as I know, the compile-time will take longer the larger the input (larger in this situation means more input). But I wonder, is the input number itself matter?
For example, I have a problem like this, calculate the sum of x numbers, let's say x = 5. So it will be the sum of 5 numbers. As a human sum of 5 small numbers like 1 2 3 4 5 is much easier and faster to calculate, while 5 big numbers like 3243 1236653 21321 112 95678 will be much harder and take longer. I wonder if computers encounter the same problem? Or does the compile-time only depend on the size of x?



What I have tried:

I googled it, but they only mentioned the size of the input, no one mentioned the input itself.
Posted
Updated 9-Apr-22 3:15am

Quote:
As far as I know, the compile-time will take longer the larger the input (larger in this situation means more input).

Compile time is no linked with larger input, but runtime is linked to size of input.
Quote:
But I wonder, is the input number itself matter?

For normal numbers, the answer is no. On 64 bits processors, the cost of an addition is 1 clock cycle til numbers like 1,000,000,000,000,000,000. things change a little when you start to ressort to infinite integers or infinit-e floats.
 
Share this answer
 
Comments
CPallini 9-Apr-22 11:32am    
5.
Patrice T 9-Apr-22 11:39am    
Thank you
If the numbers are constant values in your source code then compile time may be a few attoseconds longer. If they are input to the program at run time then compile time will not be affected.
 
Share this answer
 
Quote:
I'm learning about the time complexity of algorithms. As far as I know, the compile-time will take longer the larger the input (larger in this situation means more input). But I wonder, is the input number itself matter?

No. Compilation takes place once, when the compiler converts your code into "machine code" (or an internal form of machine code called IL) for you and produces an EXE file that you can run as many times as you wish. Inputs aren't considered then unless they are in the form of files which are "built" into that EXE file.
Whatever the user is going to type is input, external files are input, databases are input - but they are only a part of the performance of yortu app while it is running, they have no affect whatsoever on compilation.

Compile time doesn't depend on the size of values to any significant degree, it is only affected by the complexity of code and the modules it has to compile into your application.

Big O notation does not include any "one off" processes like compilation as they are not a part of the algorithm at all!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900