1.
The reason considering any of the criterions mentioned is that
If the first criterion is taken into account, we may choose the algorithm with lesser execution time as compared to others but just depending upon this we can't judge how efficient the algorithm is. It may provide faster results but if the space is increased then it won't work. Hence considering only the execution view is not suitable.
If the second criterion is taken into account, the higher the statements executed the better. But this will drastically slow down the process. Hence taking the number of statements executed alone will not show the side effects and important factor that is speed.
Now if both the alogorithms are compared in this way, each of it will lack in something.
2.
An ideal solution to compare the algorithms can be considering complexity, both time and space.
Example :
First define the purpose of your algorithm
Merge sort vs Bubble sort-
Space-wise Bubble sort requires less memory, while Merge sort requires more
Time-wise Bubble sort takes more time, while Merge sort requires less
So if we were to choose between these both algorithms, we choose Bubble where memory is limited and Merge when there's a lot of space. But usually the preference would go to Merge if the memory is present as the time complexity is O(nlogn), whereas for Bubble it's O(n).
comment for any clarifications!
Get Answers For Free
Most questions answered within 1 hours.