balanced tree generation