Huadian North Wind Blows
Key laboratory of cognitive computing and application, Tianjin University
Date: 2015/9/9
Like hash lists, the search tree data structure also supports dynamic collection operations, including inserts, queries, deletions, minimums, maximums, precursors, successors, and so on.
One or two fork search tree:
Binary Search tree node: Keyword key, satellite data, left child pointer, right child pointer, parent node pointer, other special types (red-Black tree node color, AVL tree high tree).
Binary Search Tree Properties: X is any node in a two-fork search tree. If Y is x record any one of the nodes has x.key>=y.key. If y is the x right subtree, any one of the nodes has x.key<=y.key.
Traversal of a two or two-fork search tree
Pre-sequence Traversal: root node + left subtree + right child tree
Middle sequence traversal: Left dial hand tree + root node + right subtree
Post-post traversal: Left dial hand tree + right Sub-tree + root node
Query for three or two-fork search tree
1. Query the given keyword
According to the nature of binary search tree query can be.
2. Maximum keyword element
Look for the right subtree of the right subtree until the right subtree has no right sub-tree.
3, the minimum keyword element
Look for the left subtree of the left subtree until Zuozi has no left subtree.
4, the predecessor of a given node (middle sequence traversal)
In two cases: 1, if the current node has left dial hand tree, looking for the left subtree of the largest key element, which is the precursor of the current node. 2, if the current node does not have a left subtree, to determine whether the current node is the parent node of the left subtree, if the parent node to make this judgment, know that the occurrence of the judgment node is the parent node of the right subtree, return the parent node of the Judgment node.
5, the successor of a given node (middle sequence traversal)
In two cases: 1, if the current node has a right sub-tree, looking for the right subtree of the smallest key element. 2, if the current node does not have a right subtree, if the current node is the parent node of the right subtree, then the parent node to make this judgment, until the decision node is the parent node of the left subtree, returns the parent node of the Judgment node.
Four or two fork search tree insert
It can be inserted according to the nature of the binary search tree.
Five or two fork search tree Delete
In three different situations:
1. Nodes that need to be removed have no subtrees. Simple deletion can be.
2. The node that needs to be deleted has only one subtree. Only the subtree of the current node needs to be replaced by the current node.
3. Nodes that need to be deleted have left and right subtrees. Replaces the successor of the current node (the smallest key element of the right subtree) to the current node, which is equivalent to deleting the successor node of the current node, since the minimum key element must not have a left subtree, the use of the property at the successor Node 1.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. After the BO Master permission to reprint, must be reproduced in full text, and significant location description of the date and the source link.
Introduction to Algorithms-two-fork search tree (BST)