Java common data structures and algorithms

Source: Internet
Author: User

Tag: int does not have-o structure OLE red black tree break Find atom

Two-fork Tree:

1. No more than two sub-trees per node;

2. The depth of a balanced binary tree is much smaller than the number of nodes N.

Binary search tree:

1. The value of all left subtrees of node x is less than x, and the value of all right subtree is greater than x;

AVL Tree:

1, a two-fork search tree with equilibrium conditions;

2, the Saozi of the right sub-tree depth of each node is the most difference 1.

Red and black Trees:

1, the color of the tree can only be red or black a balanced binary tree;

2, the root node of the tree and the leaf node must be black;

3, the Red node must be a sub-node black, and will exist;

4, any node to its each leaf knot point of the black knot tree the same;

5. The longest possible path from the root to the leaf is no more than twice times longer than the shortest possible path

Red and black tree with balanced binary tree:

Red and black trees give up the pursuit of complete balance, the pursuit of a general balance, in the balance with the time complexity of the binary tree is not a small difference in the case, to ensure that the maximum of three times each insert can be rotated to achieve a balance, the implementation is more simple.

The Balanced binary tree is also known as the AVL tree

Red and black trees have better efficiency, higher statistical performance

Cocktail Order:

<wiz_code_mirror>
Sort (arrys) {
        0;
        For (Arrys.  Length/i+ +) {    
            True
     for (int j = i; j < arrys. Length-i- 1; j++) {         
                if (arrys[j]>arrys[J+1]) {      
                arrys[J];
                arrys[arrys[J+1];   
                arrys[J+tmp;  
                False
                }
            }
            if (issorted) {
                Break
            }
            True
     for (int j = arrys. length-i -1; j > i; j--) {         
                if (arrys[j]<arrys[J-1]) {      
                arrys[J];
                arrys[arrys[J-1];   
                arrys[J-tmp;  
                False
                }
            }
            if (issorted) {
                Break
            }
        }
    }
Quick Sort:<wiz_code_mirror>
Sort (Arrys, high) { 
Low    ;
High    ;
        arrys[start];
        while (end>start) {  
            while (end>start&&arrys[key)//If there is nothing smaller than the key value, compare next until there is a smaller swap position than the key value, And then compare it back       to the past
                End--;
            if (arrys[end]) { 
                arrys[end];
                arrys[arrys[start]; 
                arrys[tmp;
            }
            while (end>start&&arrys[start])     
                Start+ +;
            if (arrys[key) { 
                arrys[end];
                arrys[arrys[start]; 
                arrys[tmp;
            }
            At this point the first loop is finished, and the key value position is determined. The values on the left are smaller than the key values, the values on the right are larger than the key values, but the order of the two sides may be different, making the following recursive calls
        }
        if (Low) {
            Sort (start-1);  Left sequence. First index position to key value index-1   
        }
        if (high>end) {  
            Sort (end+ high);  Right sequence. Index from key value +1 to last   
        }
    }

Java common data structures and algorithms

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.