+ 2
How to calculate complexity and time of program?
19 odpowiedzi
+ 8
You may follow this code to calculate execution time of your algorithm.
#include <stdio.h>
#include<time.h>
int main() {
time_t start ,end;
start =clock();
for(int i=0;i<100;i++)
{
i++;
}
end=clock();
double t = (double)(end-start)/(double)(CLOCKS_PER_SEC);
printf("%lf",t);
return 0;
}
+ 5
It depends on things like if you are using linear traversal of arrays or doing a binary search etc. and also on your levels of nesting in loops.
+ 2
Iaccording to your text, you need calculate time of function and algorithm complexivity.
So algorithm complexivity has 3 diff variants of costing, but all use O anotation. O complexivity is upper bound of your code complexivity
Your function divided on parts and worth method will be the O complex.
Time of function before function set processor time flag, after get current processor time and calculate difference
+ 2
I×Am×Idiot Complexivity calculate as worst complexivity block. gourav m explain complexivity.
a+b is O1, for loop is On where n is loop count, double loop will be On^2
Binary search OlogN, so there are predefined operation and their complexivity.
+ 2
Almost all company estimate time for there project it is based on many parameter. They have many things in estimate and there is always a need estimation. It requires head count, man power, man work hours, grade of workers, criticality of work, contingency plan, quality awareness and audit. All of above with past occurence code reuse and vendors deal decides the project work hours, It's must for Quality Software.
+ 1
Suppose i calculate the prime number between 1 to 100 then how much its complexity
+ 1
I would like to take cases to make you understand and iglf you dont get it much ping me. On hackerrank codechef or codeforces..
1) statement;
Is constant. The running time of the statement will not change in relation to N.
2) for ( i = 0; i < N; i++ )
statement;
Is linear. The running time of the loop is directly proportional to N. When N doubles, so does the running time.
3) for ( i = 0; i < N; i++ ) {
for ( j = 0; j < N; j++ )
statement;
}
Is quadratic. The running time of the two loops is proportional to the square of N. When N doubles, the running time increases by N * N.
while ( low <= high ) {
mid = ( low + high ) / 2;
if ( target < list[mid] )
high = mid - 1;
else if ( target > list[mid] )
low = mid + 1;
else break;
}
4) Is logarithmic. The running time of the algorithm is proportional to the number of times N can be divided by 2. This is because the algorithm divides the working area in half with each iteration.
+ 1
I×Am×Idiot not about running program. Calculation of program running time no possible in case if program is real big application.
But if we talk about cobsole application or simple application, where we have input data and output data after procedures run, we can calculate time and complexivity. In this case we assume that this program is one big function.
On start we can use spec flags (,GetTickCount()) on winapi for example if write on c/c++ or std::crono, then after finish use this func and calculate time of execution. For example
a = GetTickCount();
...
/// Your code here.
...
b = GetTickCount()
So b-a will be time in msec of code running.
+ 1
Yes, you can calculate the time of execution of programs in python by using the time module
+ 1
It seems who, questioned is looking for time estimation of program to be written and find out how much complexity is there in writing program, means how to approach the problem of programming ?
+ 1
There are two models to approach the program top-down or bottom up methodology, After you have a design and interface you can start programming.
First find the flow of program and then write either psudocode and then modules of program.
Second case write small modules of program and then combined all modules with flow of program.
Both are good rather depends on program to use the above two approaches.
To find time the complexity and time we need to build a program. We need look at code reutilize, common modules, and physibility study of program. Hope this can help you how to find out how much time it will take to program writing. Complexity can be derived by how big and inticarte detail is required for starting a program.
+ 1
Have been looking for something like this. Would love its Java version. 👍
0
I wanted more than this, pls ask educators. Why does company looks for team work. It's every one's jobs who ever is doing programming.
0
hello
0
i am new can someone guide me?
0
Leave this discussion section. After facing something removed from discussion forum. Are you payer from beginning?
Then only invade some bodies discussion.
Try to see dark side of this SOLOLEARN FORUM.
0
https://www.geeksforgeeks.org/time-complexity-and-space-complexity/