[thelist] [MYSQL] - The most effective algorithm for the shortest path.

Sarah Sweeney mrsanders at designshift.com
Sat Dec 10 11:51:12 CST 2005


> So to go from 1 to 54, the shortest path is 1-5-12-54
> This may be achieved by writing nested queries or joining the table
> with itself etc.
> However it is very resource consuming and as the complexity increases
> the resource consumption increases exponentially.

Try this method (the modified preorder tree traversal method):
http://www.sitepoint.com/article/hierarchical-data-database
It may be a challenge to really "get" the idea at first - at least it 
was for me :) - but once I had it implemented, it was totally worth the 
effort. Now I can get the full path to an item in a database table in 
just one query.

-- 
sarah adams
web developer & programmer
portfolio: http://sarah.designshift.com
blog: http://hardedge.ca



More information about the thelist mailing list