← Back to index

What is a binary search tree?

Created: 2015-12-10 00:33  |  Updated: 2015-12-10 00:43  |  Source: desktop.mac
  1. binary search tree (BST) is a binary tree where each node has a Comparable key (and an associated value) and satisfies the restriction that the key in any node is larger than the keys in all nodes in that node's left subtree and smaller than the keys in all nodes in that node's right subtree. http://algs4.cs.princeton.edu/32bst/

  2. A binary tree is a special kind of tree, one in which all nodes have at most two children. For a given node in a binary tree, the first child is referred to as theleft child, while the second child is referred to as the right child. Figure 2 depicts two binary trees.
    https://msdn.microsoft.com/en-US/library/ms379572(v=vs.80).aspx

  3. In computer sciencebinary search trees (BST), sometimes called ordered or sorted binary trees, are a particular type of containersdata structures that store "items" (such as numbers, names etc.) in memory. They allow fast lookup, addition and removal of items, and can be used to implement either dynamic sets of items, orlookup tables that allow finding an item by its key (e.g., finding the phone number of a person by name).Binary search trees keep their keys in sorted order, so that lookup and other operations can use the principle ofbinary search: when looking for a key in a tree (or a place to insert a new key), they traverse the tree from root to leaf, making comparisons to keys stored in the nodes of the tree and deciding, based on the comparison, to continue searching in the left or right subtrees. On average, this means that each comparison allows the operations to skip about half of the tree, so that each lookup, insertion or deletion takes time proportional to thelogarithm of the number of items stored in the tree. This is much better than the linear time required to find items by key in an (unsorted) array, but slower than the corresponding operations on hash tables.Several variants of the binary search tree have been studied in computer science; this article deals primarily with the basic type, making references to more advanced types when appropriate.
    https://en.wikipedia.org/wiki/Binary_search_tree