How did you manage to implement pathfinding that takes exponential time, O((k/2)^n)? What is n? The path length? The number of nodes expanded? If the latter, you probably meant 26*n, which is simply O(n).
n is path length. And no, it really is exponential - if you look at graphs showing what tiles are actually searched during an A* search, a trip more than halfway around the fortress, especially if it is on different floors, or there is a trip that requires going down then back up or the like, will basically search nearly the entire fort on the way to trying to find the path to the target.
That is to say, a trip of a hundred tiles might take testing ten thousand tiles for paths.
Most of these will be checking adjacent tiles to the paths that already exist for optimal path weights (1 weight instead of 2), checking into every single individual dead-end room in a residential sector, and nearly flood-filling the paths.
DF handles this case by preprocessing the map and marking unconnected areas. So it doesn't have to run pathfinding when there's no path to the target.
Unfortunately, not really true - this is why resealing the HFS results in
tremendous FPS lag, as the clowns will continuously try to path into the fortress they cannot reach. Likewise, locking all the doors to keep diplomats out results in constant FPS drain as the diplomat keeps trying to path into your fortress, although since this is only one character, it's less notable.
Again, all of this was handled
quite in depth in previous threads
espeically this one, and you would be better off reading and reviving that thread than continuing this one.