7-3 tree homogeneity (25 points)

Source: Internet
Author: User

Address: https://pintia.cn/problem-sets/15/problems/711

Solution:

Determine whether the tree is homogeneous and whether the children (or parent nodes) of the nodes that store the same information are consistent;

We recommend that you use struct arrays to store trees. input node subscripts are 0 => n-1.

Root Node judgment: Based on the input information of the question, the left child and the Right child are the node information. Therefore, the node that has not appeared in the Child Information is the root node.

Sample Analysis: To determine the parent node of a node.

  

The following table is obtained based on the input information of the two shards.

Left A B C D E G G H
Index 0 1 2 3 4 5 6 7
Value -1 0 0 1 1 2 4 5

 

 

 

 

  A B C D E G G H
Index 0 1 2 3 4 5 6 7
Value -1 0 0 1 1 2 4 5

 


For each node in the two trees, their parent nodes are consistent. They are homogeneous. If there is an inconsistency, they are considered non-homogeneous.

For the following two regions

    

  G B F A H C D E
Index 0 1 2 3 4 5 6 7
Value 1 3 7 -1 0 3    
Value 5 3 6 -1 0 3    

 

 

 

 

 

 

 

 

7-3 tree homogeneity (25 points)

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.