forest algorithm