Problem Solving
Problem Solving
Time complexity
is a function that describes how long an algorithm takes in terms
of the quantity of input it receives.
Space complexity
is a function that describes how much memory (space) an
algorithm requires to the quantity of input to the method.
Note that the time to run is a function of the length of the input and not the
actual execution time of the machine on which the algorithm is running
on.
Meanging of big o
1. O(1) has the least complexity
Often called “constant time”, if you can create an algorithm
to solve the problem in O(1), you are probably at your best.
In some scenarios
2. O(log(n)) is more complex than O(1), but less
complex than polynomials
As complexity is often related to divide and conquer
algorithms, O(log(n)) is generally a good complexity you can
reach for sorting algorithms. O(log(n)) is less complex than
O(√n), because the square root function can be considered a
polynomial, where the exponent is 0.5.
3. Complexity of polynomials increases as the exponent
increases
For example, O(n⁵) is more complex than O(n⁴).
4-Exponentials have greater complexity than
polynomials as long as the coefficients are positive
multiples of n
O(2ⁿ) is more complex than O(n⁹⁹), but O(2ⁿ) is actually less complex
than O(1). We generally take 2 as base for exponentials and
logarithms because things tends to be binary in Computer Science,
but exponents can be changed by changing the coefficients. If not
specified, the base for logarithms is assumed to be 2.