Aymptotic Notation.

Nov 20, 2014 at 9:13am
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;.
Nov 26, 2014 at 8:21am
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?
Nov 26, 2014 at 8:39am
for(k=n;k<-5; k=k-4)
O( infinity ) ?
Last edited on Nov 26, 2014 at 8:41am
Nov 26, 2014 at 9:08am
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.

Nov 26, 2014 at 6:05pm
results are well-defined and loop is not infinite.

Comparing an unsigned to -5 is well defined?
Last edited on Nov 26, 2014 at 6:06pm
Nov 26, 2014 at 6:34pm
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 Nov 26, 2014 at 6:35pm
Nov 26, 2014 at 6:48pm
Interesting I would have just assumed undefined behavior as opposed to implementation defined, but good to know.
Topic archived. No new replies allowed.