snippetMinor
How to compare algorithms having the same complexity
Viewed 0 times
samethehavingalgorithmshowcomparecomplexity
Problem
I am new to programming and want to learn how to compare algorithms having the same complexity and pick the best one. Certain problems can be sloved using several algorithms which have the same complexity. How do i compare such algorithms
Solution
By "having the same complexity" I assume you mean having the same time complexity.
If you have done fine analysis of time complexity of these algorithms then there may be hidden constants or factors of lower degree polynomials which are ignored when you compare using big-O notation but have effect in practice. For example, if one algorithm always takes $n^2 + 100n + 10000$ steps and the second one takes $0.3n^2$ then the second one would be a better choice, though both run in $O(n^2)$.
You could also consider their space complexity and choose one which consumes less memory if the memory consumption matters and more important than the time complexity.
If you aim to implement these algorithms yourself and use it in your commercial application (or something like that) then you could think about how easy they are implemented and how easy these algorithms scale.
If you have done fine analysis of time complexity of these algorithms then there may be hidden constants or factors of lower degree polynomials which are ignored when you compare using big-O notation but have effect in practice. For example, if one algorithm always takes $n^2 + 100n + 10000$ steps and the second one takes $0.3n^2$ then the second one would be a better choice, though both run in $O(n^2)$.
You could also consider their space complexity and choose one which consumes less memory if the memory consumption matters and more important than the time complexity.
If you aim to implement these algorithms yourself and use it in your commercial application (or something like that) then you could think about how easy they are implemented and how easy these algorithms scale.
Context
StackExchange Computer Science Q#81890, answer score: 3
Revisions (0)
No revisions yet.