Path algorithm