type 'a btree =
Empty
| Node of 'a btree * 'a * 'a btree
let rec btree_height btree =
match btree with
Empty -> -1
| Node(left, _, right) ->
1 + (max (btree_height left) (btree_height right))
let btree_balanced_p btree =
let rec aux btree =
match btree with
Empty -> true, -1
| Node(l, _, r) ->
let bl, hl = aux l and br, hr = aux r in
bl && br && hl = hr, (max hl hr) + 1 in
let balanced, _ = aux btree in balanced