Click here to Skip to main content
15,884,962 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is there a way to evaluate two algorithms to decide which is best? Two algorithms are use for solve the same equation in two deferent ways.
Posted
Updated 23-Mar-11 23:43pm
v3

No.

You first have to define "best": Best for a sort algorithm might be "fastest": but even then "fastest" will depend on data - if you know the data has a particular pattern, then the "fastest" general algorithm may not be the quickest to sort the specific data.
 
Share this answer
 
Comments
Panchaz 24-Mar-11 6:21am    
This algorithms are use for search trees so both algorithms will be searching the same tree
OriginalGriff 24-Mar-11 6:27am    
So, do as Carlo suggests: check them and see...
Sergey Alexandrovich Kryukov 24-Mar-11 12:52pm    
Best answer. Order "best" on the set of algorithms is not defined. Period.
--SA
Sergey Alexandrovich Kryukov 24-Mar-11 12:54pm    
After looking at other answers, I also see this one the only correct one, my 5.
--SA
Yes, run a test: feed the two algorithms with the same input data (making sure the output is correct) and measure performance.
 
Share this answer
 
Comments
OriginalGriff 24-Mar-11 6:28am    
:thumbsup:
Sergey Alexandrovich Kryukov 24-Mar-11 12:53pm    
Strictly speaking, as OP asks about "best" (not fastest), only Griff's answer is correct.
CPallini 24-Mar-11 14:04pm    
You're right: he used the 'quickest' term. :-D
If there are open-source implmentations available, and there usually are - test that each of them is capable of correct behaviour - sometimes some algorithms are not able to evaluate all possible inputs - so it's a good idea to check that they have the desired behaviour.

You may be interested in Big O Notation[^] - it's used to say something about the performance characteristics of an algorithm.

For some algorithms there is a significant difference between best case and worst case - can you live with the worst case?

Trial runs using realistic input data may in the end be your best choice.

Regards
Espen Harlinn
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 24-Mar-11 12:54pm    
This is good information, my 5, but, strictly, speaking, only Griff provided a correct answer, see my comment.
--SA
Espen Harlinn 24-Mar-11 17:02pm    
He might have taken into account that various algorithms have their limitations - I'm kind of assuming that we are talking about something beyond quicksort vs buble sort - where the worst case may be that one algorithm may run forever as in n! - while another may give an approximate optimal result - or actually be able to determine that no satisfactory result can be found based on the input. This is not unusual when evaluating various optimization methods.
Sergey Alexandrovich Kryukov 24-Mar-11 21:20pm    
Nobody argues against evaluation. I'm making a point of formality. I hope you familiar with the concept of mathematical order theory called partially ordered set. The term "best" suggests there is an implied (at least) partial order over the set of algorithms. Nobody define such order and I seriously suspect such order is impossible to build (impossible to satisfy axioms of partial order).

You mention of infinite algorithms give us a hint why such order is impossible. You could also remember a halting problem which is not computable. One algorithm could be faster with some data and infinite with other and other pathological cases...

--SA
Espen Harlinn 25-Mar-11 4:34am    
Right, that would definitely be the worst case :)
Sergey Alexandrovich Kryukov 25-Mar-11 12:32pm    
This is just for example...
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900