Static lookup table

Source: Internet
Author: User

Static lookup table order find ordered lookup binary lookup (binary search) Decision tree Binary lookup applies only to ordered tables, and is limited to sequential storage structures (binary lookups that are not valid for linear lists)   Fibonacci lookups: Partitioning according to the characteristics of the Fibonacci sequence, Suppose that the number of records in the table at the beginning is less than 1 of a Fibonacci number (n=fu-1), then the given value key and the [fu-1].key are compared, if you want to find success; if Key<[fu-1].key continues from elem[1] to elem[fu-1-1] child table, or continue to be found in a child table from Elem[fu-1 + 1] to elem[fu-1], the length of the latter child table is fu-2-1. The average performance of Fibonacci lookups is better than binary, but the worst-case scenario is a static tree table lookup that is introduced when the lookup probability of a lookup table is not equal to the binary lookup difference    static tree table lookup. Static optimal find tree (static optimal search trees) approximate optimal find tree (nearly optimal search trees)   sequence (Rl,rl + 1, ..., RN) where R1.key < rl+1. Key  < .... < rh.key the weights corresponding to each record. Wl,wl+1,..., WH now constructs a binary tree, so that the length of this binary tree with the weight of the inner path of the ph value in all of the same weight of the two-fork tree in myopia is minimal, This type of two-fork tree is called a sub-priority search tree (nearly optimal search trees)  void secondoptimal (bitrre& t,elemtype r[], float sw[],int low,int High) {    I=low, Min=abs (Sw[high]-sw[low]); dw=sw[high]+sw[low-1];    for (j=low+1; j<=high; ++j )     {        if (ABS (Dw-sw[j]-sw[j-1]) < min {          i=j; min =abs (Dw-sw[j]-sw[j-1]);   }    T = (bitree) maLloc (sizeof (Bitnode));    T->data = r[i];    if (i==low) T->lchild = null;    Else SEC Ondoptimal (t->lchild,r,sw,low,i-1);    if (i==high) t->rchild=null;    Else Secondoptimal ( T->rchild,r,sw,i+1,high);}  typedef bitree sostree;status createsostree (Sostree & T, sstable ST) {    if (st.length = = 0) T=NULL;& nbsp   Else {      FINDSW (sw,st),//based on the weight domain of the data elements in the ordered table ST sw.      Secondoptimal (T, St.elem,sw,1,st.length);   }    return OK;}   Since the corresponding weights for a single keyword are not taken into account in the second-priority lookup tree, it is possible that the weight of the keyword chosen as the root is smaller than the weight of the key adjacent to it. This should be adjusted appropriately: Select the nearest weighted keyword as the root node of the sub-priority lookup tree .       the lookup block lookup table of Index order table is ordered or block ordered. The so-called "block order" refers to all the records in the second child table are more keywords than the largest keywords in the first table. All the keywords for the third child table are greater than the largest keywords in the second table,..., and so on .  Structure Index table and block table each index entry includes a key item and a pointer item. Find 2 parts , find the child quickly, in the child table in order to find .  faster than the order lookup, less than binary find .    dynamic lookup table binary sorting tree, balanced binary tree (binary sort tree) binary sort trees or an empty tree Or a two-prong tree having the following properties: (1) if its left subtree is not empty, then all the nodes on the left subtree are less than the value of its root node; (2) if its right sub-treeThe tree is not empty, then the value of all nodes on the right subtree is greater than the value of its root node, and (3) its left and the sub-trees are also two-fork sorting trees.  bitree Searchbst (Bitree T, KeyType key) {    if (! T) | | EQ (Key,t->data.key)) return (T);    Else if LT (Key,t->data.key) return (Searchbst (T->lchild,key)); & nbsp   Else return (SEARCHBST (T->rchild,key));}    Two fork sort tree the Insert/delete is different from the suboptimal two fork tree is that the two fork sort tree is dynamically generated during the lookup process.  status Searchbst (Bitree T, KeyType key,bitree& p) {    if ((! T) | | EQ (Key,t->data.key)) return (P=t,return TRUE);    Else if LT (Key,t->data.key) return (Searchbst (t-> lchild,key,p));    Else return (SEARCHBST (t->rchild,key,p));}  status Insertbst (Bitree & T,elemtype e) {    if (! Searchbst (t,e.key,null,p) {        s = (bitree) malloc (sizeof (Bitnode));        s >data = e; S->lchild = S->rchild = null;        if (!p) T = s;        ELSE if LT (E.key, P->data.key) P->lchild = s;      &NBSp else P->rchild = s;        return true;   }    else return FALSE;}   Two fork Sorting tree deletion divided into three situations discussion (1) If the *p node is a leaf node, that is, PL and PR are empty trees, because the deletion of the leaf node does not destroy the entire tree structure,  only need to modify the parent node pointer. (2) If the *P node only left dial hand tree pl or only right subtree PR, at this time to another PL or PR directly become the parent node of the *f left subtree can be. (3) If the Saozi right subtree of the *P node is not empty. Obviously, this cannot be handled as simple as above. There are 2 kinds of practices   One, the left subtree of the other *p is the left subtree of *f, and the right subtree of *p is the right subtree of *s.   Two, another *p direct precursor (or direct successor) instead of *p, then delete its direct precursor (or direct successor) from the two-fork sorting tree  status deletebst (Bitree & T, KeyType key) {  if (! T) return false;  else {    if (EQ (key, T->data.key)) {return Delete (t)};    ELSE if (LT (key,t-& Gt;data.key)) return Deletebst (T->lchild,key);    else return Deletebst (T->rchild,key); }}  status Delete (Bitree & P) {  if (!p->rchild) {    q = p; p = p->lchild; free (q); }&NB Sp else if (!p->lchild) {    q = p; p = p->rchild; free (q); }  else {    q = p; s = P-&G t;lchild;    while (s->rchild) {q = s; s = s->rchild;}//LeftAnd then right to the end     P->data = s->data;                  //s points to truncated precursors     if (q! = p)  q->rchild = s ->lchild;  //re-*q right subtree     Else Q->lchild = s->lchild;        //re-connect *q left subtree     Delete s; }  reutrn TRUE;}

Static lookup Table

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.