Binary Tree (Random)
Joel Schoolnik edited this page Jan 12, 2017
·
2 revisions
Binary Tree begins with a root node and nodes are added with the addChild method. The index is created with a random string. Though this does result in some inefficiency, the search is dramatically better than an array or linked list, with on average, no more than 55 operations for a tree of 1,000,000 nodes (when searching by id). Note: root node will always be "VVVVVVVVVVVVVVVVVVVV" which is alphbetically, the exact center. This helps prevent an unbalanced tree.
let myBinaryTree = new BinaryTree(value)
- addChild(value)
- containsId(id)
- lookUp(id)
- containsVal(value) (slow)
- getId(val) (slow)
- updateId(id, value)
- deleteNode(id) (Promotes any children to node's parent)
- removeDuplicates()
- mapToArray(optionalCallback)
- mapIdToArray()
- filterToArray(callbackPredicate)
- countNodes()
- deepestGeneration()