Write a recursive algorithm in pseudo code that returns the height of a binary tree in linear time iff all nodes meet the balance-property of AVL-trees, and -1 otherwise. You are not allowed to store the height in the nodes.
the function balanced(), takes the root of the tree and a variable for height as input. It recursively checks if the subtrees at a given root are also balanced and also keeps track of the height of the tree at the same time. The getHeight function is just a helper function that calls the balanced function and returns -1 if the avl tree given isn't balanced. The height is maintained only in the variable. The node is assumed to have a left and right pointer.
The balanced function runs in linear time as every node is visited only once, so if there are N nodes in the tree, the time taken will be in the order of O(n).

Write a recursive algorithm in pseudo code that returns the height of a binary tree in...