The document discusses binary search trees (BSTs). It defines a BST as a sorted tree structure where the value of each left child is smaller than its parent and the value of each right child is larger. Self-balancing BSTs like AVL trees, red-black trees, and splay trees can automatically rebalance after insertions or deletions to maintain balanced heights. BSTs are commonly used in search applications where data is frequently added or removed, such as maps and sets. Examples of uses include name lookups, reversing path subsections in graphs, and finding square roots. The document also compares BSTs to general binary trees and outlines different types of self-balancing BSTs.
3. Trees
Tree
Eachnode canhave0 or more children
Annode canhaveat most one parent
Binarytree
Treewith 0-2 children per node
AlsoknownasDecisionMakingTree
4. Obscure binary search trees
Items, suchasnames, numbers, etc. canbe stored in memory
in asorted order called binarysearch trees or BSTs.And
someofthese datastructures canautomaticallybalancetheir
height whenarbitrary items are inserted or deleted.
Therefore, they are known as self-balancing BSTs. Further,
there can be different implementations of this type, like the
SplayTrees,A
VLtrees, andred-blacktrees.
5. Difference between BT and BST
Abinarytree issimplyatree in whicheachnode canhaveat
most two children.
ABinarysearchtree isatree that followssomeorder to
arrange the elements, whereasthe binarytree doesnot
followanyorder. InaBinarysearchtree, the valueofthe left
node must be smaller than the parent node, andthe valueof
the right node must be greater than the parent node.
6. Applications of BST
Used in many search applications where data is constantly
entering/leaving, such as the map and set objects in many
languageslibraries.
Storing a set of names, and being able to lookup based on a
prefix ofthe name. (Used in internet routers.)
Storing a path in a graph, and being able to reverse any
subsectionofthe path in O(log n) timr
Findingsquareroot ofgiven number
7. Types of BST
• AVLTree:- AVLtree isselfbalancingBinarySearchTreewhere
the differencebetweenheightsofleft andright subtrees cannot be
more than one for all nodes
• Red-BlackTree:- Ared-black tree isakindofself-balancing
binarysearchtree where eachnode hasanextra bit, andthat bit is
often interpreted asthe colour (red or black).These colours are
usedto ensure that the tree remains balancedduring insertions
and deletions
• SplayTree:- Asplaytree isabinarysearchtree with the additional
property that recently accessedelements are quickto accessagain.
Likeself-balancingbinarysearchtrees, asplaytree performs basic
operations suchasinsertion, look-upandremovalin O(log n)
amortized time.