B-Trees are souped-up version of Binary Search Trees. These data structures allow for more than 2 children per node, which keeps the tree’s depth more condensed & speeds up the time to traverse the tree.
Binary Search Trees have a lookup time complexity of
log(n) base 2, where n is the number of stored items. B-Trees get a higher base value, defined as the ‘order’ of the tree, making for quicker lookups.
It’s got some handy methods like:
this.insert(value)– Insert the value into this, at the appropriate place, and handle rebalancing the tree.
this.print()– Print out an array of values of all nodes, depth first, including and descending from
this.multiInsert(val1, val2, val3, val4...)– Insert multiple values, instead of invoking
this.insert()manually for each value. Takes multiple arguments, as many as needed.
this.print(), but prints out
this.parent.valuesof all nodes including and descending from
And here’s a super useful visualization of how B-Trees work.