implementation of binary AE and greedy tree AE