Algorithm complexity can be represented by Big O notation, for example, the following piece of code has
complexity that sums up the array.
s = 0
arr = [1, 2, 3, 4, 5]
for i in arr:
s += i
How do we know which is better: If we have
and
where k is a constant. We can compute its limitation. i.e.

Therefore,
is better than
.
For polynomial expressions, the highest complexity is often counted as the final complexity. For example,
s = 0
arr = [1, 2, 3, 4, 5]
for i in arr:
s += i
cnt = [2, 3, 4, 5, 7]
for i in arr:
for j in cnt:
s += i * j
consists of two parts:
and
. Therefore, the final complexity is represented by 
If
where k is a constant, therefore
is the complexity of
.
Given the above example,
, we can say, the overall complexity is
.
–EOF (The Ultimate Computing & Technology Blog) —
718 wordsLast Post: Sign Area of Irregular Polygon
Next Post: Codeforces: 239A. Two Bags of Potatoes