A small problem encountered when traversing multi-tree

Source: Internet
Author: User

A small problem encountered when traversing multi-tree
When traversing a multi-tree, If you traverse sub-nodes under a non-node, you must stop them in time !!! Otherwise, not only O () is increased, but also child nodes are increased repeatedly.The following is a small logic written by myself, with the node being 0 => all groups, followed by a training class => term => lesson

The result is as follows:

Because I am stupid, I think about it carefully and find the Algorithm Vulnerability: when traversing the third-level node (semester), if it does not belong to its parent node, it will still traverse its child nodes (class hours), and will repeatedly Add the child nodes of the semester node, resulting in repeated child nodes Therefore, a simple solution is implemented: skip this step when traversing to non-child nodes.

 

The result is normal!

Let's take a look at the small problems encountered at work and record them. We hope to avoid these problems next time and help us.

 

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.