Aymptotic Notation.

Greetings everyone. It is humbly requested to tell me the concepts of running time complexity and Big- O notation. I tried everywhere but can't pick the concepts of it. I tried to figure it out by my own but i can't. I have one example if you tell me what is it. I have following piece of code and can;t find its working.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  yz =0;
xw=0;
for(i=m; i>-6; i=i-6)
{ xw++; }
for (i=n; i>-2015;i=i-5)
{ yz=yz+1;}
for (i=1;i<=n;i=i*5)
{ for (j=1;j<=5n;j*12
{
for(k=n;k<-5; k=k-4)
{
x=x+12
}
}
}
Print x;
While(k<=z)
{
k=k*2
(
for(m=k; m<=-100000; m=m-1
)
}
Print k;.
Could you possibly format in a friendlier manner before I attempt to read it?
I know it's not a lot of code but I takes an awful lot more effort to read when code's not properly indented.

The general concepts to big O notation is that it shows the mathematical representation of how long a program or algorithm execution will take, depending upon its argument size.

O(1) means it's constant, the algorithm will always execute in the same speed no matter what it's argument size is. (This is ideally what every algorithm wants to be)
O(n) means that an algorithm is linear. The time to complete computation on n arguments will be a constant time, times the size of n
O(n^2) means that an algorithm has a squared time complexity. The time to complete computation on n arguments will be a constant time, times the (size of n)^2

Theirs many different complexity types and I don't know much other than those basics. Hopefully that helps a little?
for(k=n;k<-5; k=k-4)
O( infinity ) ?
Last edited on
for(k=n;k<-5; k=k-4)
O( infinity ) ?
We do not see how k is declared. If it is unsigned type, results are well-defined and loop is not infinite.

results are well-defined and loop is not infinite.

Comparing an unsigned to -5 is well defined?
Last edited on
Actually yes:
Standard wrote:
5.9 Many binary operators that expect operands of arithmetic or enumeration type cause conversions and yield result types in a similar way. The purpose is to yield a common type, which is also the type of the result.
This pattern is called the usual arithmetic conversions, which are defined as follows:
[...]
— Otherwise, the integral promotions (4.5) shall be performed on both operands. Then the following rules shall be applied to the promoted operands:
[...]
— Otherwise, both operands shall be converted to the unsigned integer type corresponding to the type of the operand with signed integer type.


4.7.2 If the destination type is unsigned, the resulting value is the least unsigned integer congruent to the source integer (modulo 2n where n is the number of bits used to represent the unsigned type). [ Note: In a two’s complement representation, this conversion is conceptual and there is no change in the bit pattern (if there is no truncation). —end note ]
Basically it would be equal to UINT_MAX - 5
Last edited on
Interesting I would have just assumed undefined behavior as opposed to implementation defined, but good to know.
Topic archived. No new replies allowed.