Note: this article is published on 07/20/2024.

I came from science, I have never had a chance to learn or play a game such as an algorithm in my student career. Most algorithm problems I met are in interviews. In my view, these kinds of tricks are just boby level games, but if you did not have related training previously, you might not get the solution immediately. So, I will open a topic, or series, to record the algorithm questions I met or I played previously (10/03/2021, from my first algorithm article).

This series will include,

I will add more on this topic probably from my notes or practice code.

A - Introduction

This article will discuss the algorithm effiency measurement, including time measurement and space measurement, and the Big O notation calculation. This is the structure of this article,

B - Algorithm Efficiency

C - Measurement of Time Algorithm Efficiency (Complexity)

Some common time complexities are:

D - Measurement of Space Algorithm Efficiency (Complexity)

Some common space complexities are:

E - Big O Notation Calculator

Some common space complexities are:

Measure for two dimention loop:

    for (int i = 0; i < A.Length; i++)
    {
        P[i] = 1;
        for(int j = 0; j < A.Length; j++)
        {
            if(i != j)
            P[i] = P[i]*A[j];
        }
    }

The results from these two calculators:

Measure for One dimention loop:

    for (int i = 0; i < A.Length; i++)
    {
        L[i] = LP;
        LP = LP * A[i];

        R[A.Length - 1 - i] = RP;
        RP = RP * A[A.Length - 1 - i];

        if (R[i] != 0)
        {
            P[i] = L[i] * R[i];
            P[P.Length - 1 - i] = L[L.Length - 1 - i] * R[A.Length - 1 - i];
        }
    }

Results:

 

References: