12.29 2-3-4 tree Summary

Source: Internet
Author: User

 

It took two days to complete the 2-3-4 tree summary. Program -- Inserts a 2-3-4 tree. The main reason for this long time is that many detours have been taken and some common-sense errors have been made. To prevent such errors from being repeated, this note is used to deepen your impression. First of all, I did not understand the concept of the 2-3-4 tree when I started writing a program. Although I checked some information, this very abstract thing is still hard to understand, in Wikipedia, we have actually stored 2-3-4 trees Algorithm I wrote it in step 1, but I read it again and again for 20 or 30 times. Let's simply sum up the experience, which is clear.
    1. Do not write details before the framework is ready.Code. First use system. Out. println () for testing. After the test is successful, start the specific implementation.
    2. Do not write any line of code before the algorithm steps are fully understood. It is best to draw a few images first, and then start writing after the figure passes.
    3. Do not change the parameters of the input function. Otherwise, do not reference the input function.
    4. Before writing code, use natural language to describe the algorithm step. These natural statements can be added to comments.
    5. The division of labor between various code segments of the program should be clear.

 

By the way, insert the Wikipedia description of the 2-3-4 Tree Insertion Algorithm:

 

To insert a value, we start at the root of the 2-3-4 tree:

    1. If the current node is a 4-node:

      • Push the middle element of the 4-node up into the parent, leaving a 3-node.
      • Split the remaining 3-node up into a pair of 2-nodes.
      • If this is the root node (which thus has no parent), the middle value becomes the new Root 2-node and the tree height increases by 1. ascend into the root.
        • Otherwise, push the middle value up into the parent node. ascend into the parent node.
    2. Find the child whose interval contains the value to be inserted.
    3. If the child is empty, insert the value into current node and finish.
      • Otherwise, descend into the child and repeat from step 1.

 

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.