I usually either compare the number of iterations of each algorithms after it's done executing or use a timer to know which one is faster. but is there a way to figure out which algorithm 'costs less' meaning which one has the less number of operations involved.
thanks !
I think what you are seeking is determining the "efficiency" of algorithms or in other words, "complexity". You can find some information on internet but I strongly recommend you to learn this concept if you are interested in complexity of algorithms: https://en.wikipedia.org/wiki/Big_O_notation. Besides, number of operations or execution time is not the only factor that determines efficiency. There is another factor, often called "memory efficiency", which is about the measure of the space your program use. Note that there is always a trade-off between "time efficiency" and "memory efficiency", which mean if you make your program more time efficient, that will probably cost more memory or you can make it more memory efficient but then the execution time will be longer.