Find
Personal notes, intrusion
Binary search is also called binary search.
He must askSequential storage structureAnd requiresOrderly。
int Search_Bin(SSTable ST,KeyType key)
{
low=1;
high=ST.length;
while(low<=high)
{
mid=(low+high)/2;
if(ST.R[mid].key==key) return mid;
else if(ST.R[mid]>key) high=mid-1;
else low=mid+1;
}
return 0;
}
Binary arrangement tree
The characteristics of the binary sort tree: all the left subtrees are smaller than the root node, all the right subtrees are larger than the root node, and the subtree is also a binary sort tree.
statement
typedef struct
{
KeyType key; //关键字域
InfoType otherInfo; //其他数据项
}ElemType;
typedef strcut BSTnode;
{
ElemType data;
struct BSTnode *lchild,*rchild;
}BSTndoe,*BSTree;
insert
void InsertBST(BSTree &T,ElemType e)
{
if(!T)
{
BSTree S=new BSTree;
S->data=e;
S->lchild=S->rchild=NULL;
T=S;
}
else if(e.key>T->data.key) InsertBST(T->rchild,e);
else InsertBST(T->lchild,e);
}
create
void CreatBST(BSTree &T)
{
T=NULL;
cin>>e;
while(e.key!=ENDFLAG)
{
InsertBST(T,e);
cin>>e;
}
}
Balanced binary tree
The search performance of a binary sort tree depends on the structure of the binary sort tree, and the shape of the binary tree depends on the data set
If it is ordered, the search time complexity is O (n). If the structure is reasonable, the search time complexity is O(log 2 n). In fact, the smaller the tree height, the faster the search. Therefore, a balanced binary tree, also known as AVL tree, is proposed.
A balanced binary tree or an empty tree has the following characteristics:
(1) The absolute value of the difference between the depth of the left and right subtrees does not exceed 1
(2) The left and right subtrees are also balanced binary trees
Balance adjustment method of balanced binary tree
Obviously, constructing a tree into a balanced binary tree is conducive to search efficiency.
So how to convert an unbalanced binary tree into a balanced binary tree:
If the balance factor (Balance Factor, BF) of a node on a binary tree is defined as the
difference between the depth of the left and right subtrees of the node, then the balance factor of all nodes on the balanced binary tree can only find -1, 0 and 1. As long as
the absolute value of the balance factor of a node on the binary tree is greater than 1, the binary tree is unbalanced
What is the meaning of the M order in the B tree?
B-tree background
Second detection method
to be continued. . . (2021/1/16)