10 , 12 , 17 , 25 . Seguindo nossas regras para uma árvore de pesquisa binária, adicionaremos 12 à direita de 10 , 17 à direita desta e 25 à direita desta. Agora nossa árvore se assemelha a uma lista encadeada e atravessá-la para encontrar 25 exigiria que percorrêssemos todos os itens de maneira linear. Assim, o tempo linear no pior dos casos. O problema aqui é que a árvore está desequilibrada. Veremos um pouco mais sobre o que isso significa nos desafios a seguir. Instruções: Neste desafio, vamos criar um utilitário para a nossa árvore. Escreva um método isPresent que isPresent um valor inteiro como entrada e retorne um valor booleano para a presença ou ausência desse valor na árvore de pesquisa binária. 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 isPresent .
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; return (typeof test.isPresent == "function")})(), "The binary search tree has a method called isPresent.");'
- text: O método isPresent verifica corretamente a presença ou ausência de elementos adicionados à árvore.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.isPresent !== "function") { return false; }; test.add(4); test.add(7); test.add(411); test.add(452); return ( test.isPresent(452) && test.isPresent(411) && test.isPresent(7) && !test.isPresent(100) ); })(), "The isPresent method correctly checks for the presence or absence of elements added to the tree.");'
- text: isPresent manipula casos em que a árvore está vazia.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.isPresent !== "function") { return false; }; return test.isPresent(5) == false; })(), "isPresent handles cases where the tree is empty.");'
```