Every problem can be solved in many ways. So we need to take care to select the algorithm which is preferable and best among them.
The performance of algorithm can be measured in terms of time and space consumed by the algorithm. The characteristics of best algorithm is it use less time and space compared to other algorithms.
Time Complexity: Running time of an algorithm.
Space Complexity: Memory space needed by algorithm.
The time and space complexity of algorithm is calculated in two ways. The first one is practically calculating the time and space needed by algorithm. The second one is theoretically calculating the time and space needed by algorithm.
Empirical Approach: Calculate the time and space needed by algorithm by executing it on a computer.
Theoretical Approach: Mathematically calculating the time and space needed by algorithm.
The empirical approach depends on various factors that the machine on which program is executed, programming language which is implemented, etc.
Eg. The same code implemented in C and Python. The executable file of C will execute faster than interpretation of Python code.
But the theoretical approach is independent from these factors. So theoretical approach is believable than.
The performance of algorithm can be measured in terms of time and space consumed by the algorithm. The characteristics of best algorithm is it use less time and space compared to other algorithms.
Time Complexity: Running time of an algorithm.
Space Complexity: Memory space needed by algorithm.
The time and space complexity of algorithm is calculated in two ways. The first one is practically calculating the time and space needed by algorithm. The second one is theoretically calculating the time and space needed by algorithm.
Empirical Approach: Calculate the time and space needed by algorithm by executing it on a computer.
Theoretical Approach: Mathematically calculating the time and space needed by algorithm.
The empirical approach depends on various factors that the machine on which program is executed, programming language which is implemented, etc.
Eg. The same code implemented in C and Python. The executable file of C will execute faster than interpretation of Python code.
But the theoretical approach is independent from these factors. So theoretical approach is believable than.