implementation of n-ary tree