tree drawing algorithm