Textbook Source Code section
9th. Find- Balance binary sort (search) tree
--"Data structure"-Min. 聯繫 version
Source code Use instructions link??? data Structure-C language edition (Min, 聯繫 version) textbook source + problem sets analysis using instructions
Textbook source Collection link??? "Data structure" textbook source code compilation
Problem sets full parse link??? analysis of the problem of the data structure problems in the compilation
Source code introduced by the file link? base.c
relevant test data download link? Data Package
document source code and test data storage directory: Data structure \▲ textbook algorithm implementation \▲09 find \07 Balancedbinarysorttree
Overview
Balanced binary sorting (search) trees are often referred to as balanced binary trees (Balanced binary tree), which is referred to as the AVL tree (unlike the AVL algorithm).
parsing
A balanced binary sort (search) tree or an empty tree, or a two-fork sort tree with the following properties:
(1) The Joz tree is not empty, then the value of all nodes on the left subtree is less than the value of its root node;
(2) If the right subtree is not empty, the value of all nodes on the right subtree is greater than the value of its root node;
(3) The left and right sub-trees are also balanced binary sorting trees;
(4) There are no nodes with the same key value.
(5) The absolute value of the difference between the height of the Zuozi and the right subtree is less than or equal to 1; (different from the normal binary sorting tree).
For a typical two-fork search tree, the desired height (i.e., a tree of balance) is log2n, and the time complexity (O (log2n)) of each operation is also determined. However, in some extreme cases (such as when the inserted sequence is ordered), the binary search tree will degenerate into an approximate chain or chain, at which time the complexity of its operation will degenerate into linear, i.e. O (n). We can avoid this situation by randomly establishing a two-fork search tree, but after many operations, we always choose to replace the successor of the node to be deleted because of the deletion, which will cause the number of nodes on the right side to be reduced so that the tree is left biased. This also causes the tree's balance to be destroyed, increasing the time complexity of its operation.
The Balanced Binary search tree (Balanced binary trees) has the following properties: It is an empty tree or its left and right two subtree of the height difference of the absolute value of not more than 1, and the left and right two subtrees are a balanced binary tree. Commonly used algorithms are red-black trees, AVL, treap, stretching trees and so on. In the balanced binary search tree, we can see that its height is generally well maintained at O (log (n)), greatly reducing the time complexity of the operation.
Source Code
file one? BalancedBinarySortTree.h
file two? balancedbinarysorttree.c
file three? balancedbinarysorttree-main.c (test document)
file four? testdata_table.txt (Find table test data)
test results show
more chapters in the Continuous update ...
9-7-balanced binary sorting (search) tree-Find-9th-"Data structure" textbook source code-Min 聯繫 version