Skip to content

Binary Tree (Random)

Joel Schoolnik edited this page Jan 12, 2017 · 2 revisions

Binary Tree (Random)

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.

Instantiate

let myBinaryTree = new BinaryTree(value)

Binary Tree Methods

Create

  • addChild(value)

Lookup

  • containsId(id)
  • lookUp(id)
  • containsVal(value) (slow)
  • getId(val) (slow)

Update

  • updateId(id, value)

Delete

  • deleteNode(id) (Promotes any children to node's parent)
  • removeDuplicates()

Helper Methods

  • mapToArray(optionalCallback)
  • mapIdToArray()
  • filterToArray(callbackPredicate)

Diagnostic

  • countNodes()
  • deepestGeneration()