Algorithm Complexity


Algorithm complexity can be represented by Big O notation, for example, the following piece of code has tex_caa5d58969fcc95bcd6477b6782501fa Algorithm Complexity algorithms beginner math 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 tex_b1e9e3820e609e93a880949b15a68ba7 Algorithm Complexity algorithms beginner math and tex_204f6dc122370ae559a6301f41029e39 Algorithm Complexity algorithms beginner math where k is a constant. We can compute its limitation. i.e.

tex_7bc311251849d92bde9ab33ab5174470 Algorithm Complexity algorithms beginner math

Therefore, tex_b1e9e3820e609e93a880949b15a68ba7 Algorithm Complexity algorithms beginner math is better than tex_204f6dc122370ae559a6301f41029e39 Algorithm Complexity algorithms beginner math .

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: tex_caa5d58969fcc95bcd6477b6782501fa Algorithm Complexity algorithms beginner math and tex_8fb1f5024a605dc7737c61a8a376e067 Algorithm Complexity algorithms beginner math . Therefore, the final complexity is represented by tex_37998dac4f19e782d2388e281762d317 Algorithm Complexity algorithms beginner math

If tex_e353b50bdb2642682dda041d23c51da7 Algorithm Complexity algorithms beginner math where k is a constant, therefore tex_878f71de1e4f1a6da961d533f43d026e Algorithm Complexity algorithms beginner math is the complexity of tex_f423e0c91ea450ea69cf63ef65c1030b Algorithm Complexity algorithms beginner math .

Given the above example, tex_a84aee69c8521a457244f39c434a5ade Algorithm Complexity algorithms beginner math , we can say, the overall complexity is tex_8fb1f5024a605dc7737c61a8a376e067 Algorithm Complexity algorithms beginner math .

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
735 words
Last Post: Sign Area of Irregular Polygon
Next Post: Codeforces: 239A. Two Bags of Potatoes

The Permanent URL is: Algorithm Complexity

Leave a Reply