Implemented state() function for tree and binarytree