tree generated algorithm