Yep; and sometimes things like zonal fares can make quite a big difference, too; to get to one of my favourite bars, if I take the train via zone 1, I pay 2.20 (2.80 peak), whereas avoiding zone 1 is 1.50 (1.60); Sometimes, to cross town, the quickest route for me is to head out of town to pick up a faster line coming back in. And that's before you consider real time info on delays, closures, etc, which can make it even trickier.
I don't know what algorithm they use, but unless you're thinking of somewhere very peculiar, or absolutely have to code this yourself, the Metro app probably already covers it - metro.nanika.net