findMinHeight e findMaxHeight . Esses métodos devem retornar um valor inteiro para a altura mínima e máxima dentro de uma determinada árvore binária, respectivamente. Se o nó estiver vazio, vamos atribuir uma altura de -1 (esse é o caso base). Finalmente, adicione um terceiro método isBalanced que retorna true ou false dependendo se a árvore está balanceada ou não. Você pode usar os dois primeiros métodos que acabou de escrever para determinar isso. BinarySearchTree existe.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() }; return (typeof test == "object")})(), "The BinarySearchTree data structure exists.");'
- text: A árvore de pesquisa binária tem um método chamado findMinHeight .
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; return (typeof test.findMinHeight == "function")})(), "The binary search tree has a method called findMinHeight.");'
- text: A árvore de pesquisa binária tem um método chamado findMaxHeight .
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; return (typeof test.findMaxHeight == "function")})(), "The binary search tree has a method called findMaxHeight.");'
- text: A árvore de pesquisa binária tem um método chamado isBalanced .
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; return (typeof test.isBalanced == "function")})(), "The binary search tree has a method called isBalanced.");'
- text: O método findMinHeight retorna a altura mínima da árvore.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.findMinHeight !== "function") { return false; }; test.add(4); test.add(1); test.add(7); test.add(87); test.add(34); test.add(45); test.add(73); test.add(8); return (test.findMinHeight() == 1); })(), "The findMinHeight method returns the minimum height of the tree.");'
- text: O método findMaxHeight retorna a altura máxima da árvore.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.findMaxHeight !== "function") { return false; }; test.add(4); test.add(1); test.add(7); test.add(87); test.add(34); test.add(45); test.add(73); test.add(8); return (test.findMaxHeight() == 5); })(), "The findMaxHeight method returns the maximum height of the tree.");'
- text: Uma árvore vazia retorna uma altura de -1 .
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.findMaxHeight !== "function") { return false; }; return (test.findMaxHeight() == -1); })(), "An empty tree returns a height of -1.");'
- text: O método isBalanced retorna true se a árvore for uma árvore de pesquisa binária balanceada.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.isBalanced !== "function") { return false; }; test.add(4); test.add(1); test.add(7); test.add(87); test.add(34); test.add(45); test.add(73); test.add(8); return test.isBalanced(); })(), "The isBalanced method returns true if the tree is a balanced binary search tree.");'
```