Method for inversely sorting and assembling tree data

By inverted sorting of tree data, the problem of unpredictable time complexity of tree structure assembly in the existing technology is solved, and the tree structure is quickly constructed, which improves the response speed and system stability.

CN119537368APending Publication Date: 2025-02-28富盛科技股份有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411360502.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-27
Publication Date
2025-02-28

AI Technical Summary

Technical Problem

In the case of large data volumes, the time complexity of assembling tree data structures is unpredictable, resulting in a large amount of time spent on the construction process, affecting the interface response time, and even causing timeout problems.

Method used

The method of assembling tree data is adopted to store the basic node data of the tree structure in a relational database, and sort it invertedly according to the level attribute, establish a mapping relationship between the parent node ID and the child node collection cache, and construct a tree structure step by step through traversal and assembly steps.

Benefits of technology

It significantly reduces the number and depth of recursive calls, avoids the time complexity problem caused by too deep recursive hierarchy and uncertain tree forking, shortens the response time of the tree interface, improves the overall smoothness of the software, and improves resource utilization efficiency and system stability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119537368A_ABST
    Figure CN119537368A_ABST
Patent Text Reader

Abstract

The invention discloses a method for inversely sorting and assembling tree data, which relates to the field of software background development and comprises the following steps: S1, preparing; s2, a sorting step; s3, a cache establishment step; and S4, traversing and assembling. Compared with a traditional assembling mode of arranging from root nodes in sequence and recurring layer by layer, the method for assembling the tree structure data in the inverted sorting mode has the remarkable beneficial effects that the basic data are traversed in the inverted sorting mode, calculation is started from the last-stage node, the lower-stage nodes are set, and the efficiency is improved. According to the method, the complete tree structure can be assembled only through one-time circulation, the number of times and depth of recursion calling are greatly reduced, the time complexity problem (O (1)-O (n2)) caused by too deep recursion hierarchy and uncertain tree branch is avoided, and therefore the response time of a tree interface is remarkably shortened, and the overall running smoothness of software is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the field of software background development, and in particular to a method for assembling tree data in reverse order. Background Art

[0002] In current software development projects, the application scenarios of tree data structures are very common. Tree data structures are widely used in file systems, organizational structures, classification directories and other scenarios due to their intuitive hierarchical display. However, when processing large amounts of data, how to efficiently assemble and display tree data structures has become a technical challenge.

[0003] At present, the method of assembling tree structure data in most scenarios is to start from the root node and proceed recursively layer by layer. This method first searches for the current node, then recursively searches for all child nodes corresponding to the node, and sets these child nodes as the child node attributes of the node. This process will continue to recurse to each child node until all nodes are correctly placed at the level they should be at, thereby assembling a complete tree structure.

[0004] However, this method has obvious drawbacks in the case of large amounts of data. Due to the deep recursive levels and the uncertain number of tree forks, the time complexity of the entire construction process is unpredictable, usually ranging from O(1) to O(n). 2 ), on a large-scale data set, this fluctuation in time complexity will directly lead to a large amount of time spent in the process of building the tree structure, which in turn affects the response time of the interface, resulting in problems such as long response time or even timeout. Summary of the invention

[0005] Based on this, the purpose of the present invention is to provide a method for assembling tree data in reverse order to solve the obvious defects of the existing methods in the case of large amounts of data. Due to the deep recursive level and the uncertain number of tree forks, the time complexity of the entire construction process is unpredictable, usually ranging from O(1) to O(n 2 ), on a large-scale data set, this fluctuation in time complexity will directly lead to a large amount of time spent in the process of building the tree structure, which in turn affects the response time of the interface, causing technical problems such as long response time or even timeout.

[0006] In view of the above problems, the present application provides a method for assembling tree data in reverse order.

[0007] The first aspect of the present application provides a method for assembling tree data in reverse order, comprising the following steps: S1: preparation step: storing a batch of basic node data of a tree structure in a relational database, each node containing the following attributes: id: the unique identifier of the node; pid: the parent node id corresponding to the node; name: the name of the node; level: the level of the node in the tree, with the root node being the first level; lsLeaf: whether the node is a leaf node (a node at the last level in the tree and without a lower level node is a leaf node); Children: a child node set, a child node set corresponding to the node; the database does not store the child node set attribute of the node; S2: sorting step: taking this batch of data from the database, sorting it in reverse order according to the level attribute, and forming a new set named sortedList; S3: cache establishment step: establishing a cache for storing the mapping relationship between the parent node id and the child node set, the cache key is the parent node id, and the value is the child node set corresponding to the parent node, and the cache is named cache; S 4: Traversal and assembly steps: Loop through each node in sortedList and perform the following operations on each node: Get the pid of the current node; if the pid of the current node is empty, ignore subsequent operations and continue to the next loop; take out the child node set corresponding to the pid from the cache, recorded as childItems; if the taken childItems is empty, create a new childItems for the pid in the cache; add the current node to childItems; determine whether the current node is a leaf node. If not, take out the child node set corresponding to the current node id from the cache, recorded as subChildItems, set the children attribute of the current node to subChildItems, and delete the subChildItems from the cache; since sortedList is sorted in reverse order by level, after the traversal is completed, the last node is the root node, and the child node set corresponding to the root node is the assembled tree structure.

[0008] According to a second aspect of the present application, a computer-readable storage medium is provided, on which a computer program is stored, and when the program is executed by a processor, the method for assembling tree-structured data in reverse order according to any one of claims 1 to 7 is implemented.

[0009] According to a third aspect of the present application, an electronic device is provided, comprising a processor and a memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, the method for assembling tree structure data in reverse order according to any one of claims 1 to 7 is implemented.

[0010] In summary, the present invention mainly has the following beneficial effects: The method of assembling tree structure data in reverse order proposed by the present invention has significant beneficial effects compared with the traditional method of arranging in order from the root node and assembling layer by layer recursively. The basic data is traversed in reverse order, and the lower nodes are calculated and set from the last node. The complete tree structure can be assembled in only one cycle. This method greatly reduces the number and depth of recursive calls, and avoids the time complexity problem caused by too deep recursive levels and uncertain tree bifurcation (O(1)-O(n 2 )), thereby significantly shortening the response time of the tree interface and improving the overall running smoothness of the software; in the process of constructing the tree structure, the present invention adopts a cache mechanism to store the mapping relationship between the parent node ID and the child node set. This design reduces the number of database accesses, reduces the consumption of system resources, and improves resource utilization efficiency; since the problems such as stack overflow caused by too deep recursive levels in traditional methods are avoided, the reverse order assembly method of the present invention enhances the stability and reliability of the system and reduces the risk of system crashes; for software applications that need to process a large amount of tree data, the method of the present invention can significantly improve the response speed of the user interface, reduce user waiting time, and thus improve the overall user experience. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] Figure 1 It is a schematic diagram of the tree structure construction process of the present invention. DETAILED DESCRIPTION

[0012] The following will be combined with the accompanying drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be understood as limiting the present invention.

[0013] The following describes an embodiment of the present invention based on its overall structure.

[0014] A method for assembling tree data in reverse order, comprising the following steps: S1: Preparatory steps 1. Database design: First, design a table structure in a relational database to store the basic node data of the tree structure. The table contains at least the following fields: id: integer or string type, used as the unique identifier of the node. This field is required because it ensures the uniqueness of each node in the database, facilitating subsequent queries and references.

[0015] pid: integer or string type, indicating the parent node id of the node. This field is used to establish the parent-child relationship between nodes. If the node is a root node, its pid can be empty (depending on the specific database design and application requirements, it may also be set to a specific value, such as 0 or ''root'').

[0016] name: string type, indicating the name of the node. This field is optional, but is usually used to describe the specific meaning or name of the node to facilitate users to understand and use the tree structure.

[0017] level: integer, indicating the level of the node in the tree, with the root node being the first level. This field is one of the keys to building a tree structure, because it provides information about the relative position of the node in the tree. Through this field, the nodes can be sorted, which facilitates the subsequent assembly process.

[0018] lsLeaf: Boolean type, indicating whether the node is a leaf node (a node at the last level in the tree without any subordinate nodes is a leaf node). This field is optional, but it helps to quickly identify leaf nodes when traversing and assembling the tree structure, so as to perform special processing (such as not needing to create a child node set for it, etc.).

[0019] Note that a key feature of this table design is that it does not directly store the Children attribute, that is, it does not directly store the collection of child nodes. This attribute will be dynamically generated in the subsequent assembly process. This design reduces the storage requirements of the database and improves the flexibility of the data.

[0020] 2. Data entry: After the database table structure is designed, a batch of basic node data of the tree structure needs to be entered into the table. This process usually involves the following steps: Prepare data: First, you need to prepare the node data to be entered. This data may come from various sources such as user input, file import, other database tables, etc.

[0021] Data cleaning: Before entering data, it is usually necessary to clean the data to ensure its accuracy and consistency. For example, check whether the ID of each node is unique, whether the pid points to a valid parent node ID, whether the name field contains illegal characters, etc.

[0022] Data entry: Enter the cleaned data into the database table. This process can be implemented in a variety of ways, such as using SQL statements, database management tools, and database operation libraries in programming languages.

[0023] Through the above steps, the preparation stage of the method of assembling tree data in reverse order is completed. At this time, all node data have been stored in the relational database and are ready to be retrieved, sorted and assembled into a tree structure in subsequent steps.

[0024] S2: Sorting step 1. Data extraction: Extract all node data that need to be assembled into a tree structure from the database.

[0025] Use SQL query statements to retrieve all the basic node data of the tree structure from the relational database. These data are usually stored in a table, where each row represents a node and each column represents a certain attribute of the node.

[0026] Make sure that the query results include all necessary node attributes, such as id (node ​​unique identifier), pid (parent node id), name (node ​​name), level (node ​​level), lsLeaf (whether it is a leaf node), etc.

[0027] 2. Reverse sorting: Sort in reverse order according to the level field, starting from the bottom layer of the tree (the largest level) and sorting upward layer by layer until the root node (the smallest level, usually 1).

[0028] Use the SQL ORDER BY clause combined with the DESC keyword to achieve reverse sorting. For example, if the table name is TreeNode, the SQL query statement may be similar to "SELECT * FROM TreeNode ORDER BY level DESC; After executing the above query, a new collection named sortedList will be obtained, and the node data in the collection has been sorted in descending order of the level attribute.

[0029] After reverse sorting, the first node in the sortedList collection will be the highest-level node (i.e. the bottom-level node, which may be multiple leaf nodes), and the last node will be the root node (the lowest-level node). This sorting method greatly facilitates the subsequent traversal and assembly steps, because the tree structure can be built up step by step from the bottom-level node, avoiding the deep recursion and uncertain time complexity that may be caused by starting from the root node in the traditional method.

[0030] S3: Cache creation steps 1. Cache initialization: The establishment of cache is to improve data access efficiency and reduce the number of direct queries to the database, thereby optimizing the assembly process of the tree structure.

[0031] Data structure selection: Use a hash table or dictionary data structure to create a cache in memory. Both data structures provide fast key-value pair lookup and insertion operations, and are very suitable for storing and quickly retrieving the mapping relationship between parent node IDs and child node collections.

[0032] Cache naming: The cache is named cache for easy reference in subsequent steps.

[0033] Cache content: Key: The key of the cache is the ID (pid) of the parent node. Each parent node ID is unique in the cache and is used to quickly locate the corresponding set of child nodes.

[0034] Value: The cached value is the set of child nodes corresponding to the parent node ID. This set can be a list or an array, which is used to store all child nodes directly belonging to the parent node.

[0035] Operation process: Initialize the cache: First, create an empty hash table or dictionary in memory as a cache.

[0036] Setting key-value pairs: As the tree structure assembly process proceeds, whenever a node is encountered, the corresponding child node set is searched in the cache based on its parent node ID (pid).

[0037] If the child node set corresponding to the pid already exists, the current node is directly added to the set; if the child node set corresponding to the pid does not exist (that is, the corresponding key is not found in the cache), a new child node set is created for the pid in the cache, and the current node is added to the set as the first element.

[0038] Through the cache mechanism, it is avoided to query the database every time the child node set needs to be accessed, thereby significantly reducing the number of database accesses and reducing the consumption of system resources. Since the hash table or dictionary provides fast search and insertion operations, the assembly efficiency of the tree structure can be significantly improved.

[0039] S4: Traversal and assembly steps 1. Loop traversal: Loop through each node in sortedList, and visit each node in sortedList in order from the largest level to the smallest level (that is, the order of sortedList). By traversing, ensure that each node can be correctly added to the child node set of its parent node, thereby building a complete tree structure.

[0040] 2. Node processing: Get the parent node ID: For each node in sortedList, first get its pid (parent node ID) to determine the parent node of the current node so that the current node can be added to the child node set of its parent node.

[0041] Check the parent node ID: If pid is empty, ignore the node (because it may be the root node, and the root node will be the last to be processed after the reverse sort), and continue the next loop to avoid unnecessary processing of the root node, because the root node has no parent node and will automatically become the top of the tree structure in the last step.

[0042] Find or create a child node set: try to get the child node set (childItems) corresponding to the current node pid from the cache. If the corresponding childItems is not found in the cache (that is, childItems is empty), create a new child node set for the pid in the cache to ensure that each parent node has a corresponding child node set to store its child nodes in order to build a tree structure.

[0043] Add node to child node collection: add the current node to the childItems retrieved from cache or newly created, associate the current node with its parent node, and form part of the tree structure.

[0044] Processing non-leaf nodes: If the current node is not a leaf node, take out the subnode collection (subChildItems) corresponding to the current node id from the cache, set the children attribute of the current node (although not directly stored in the database, but in memory or as an object attribute) to subChildItems, and delete the subChildItems from the cache (because it has been associated with the parent node). For non-leaf nodes, it is necessary to associate its own child node collection (if any) with it to build a complete tree structure. At the same time, delete the reference to the child node collection from the cache to avoid memory leaks or duplicate references.

[0045] 3. End of traversal: Since sortedList is sorted in reverse order by level, after the traversal is completed, the last node in sortedList is the root node. At this time, the set of child nodes corresponding to the root node is the assembled tree structure. Through one traversal, the tree structure is built up step by step from the last node until a complete tree structure is formed with the root node as the top.

[0046] S5: Subsequent processing 1. Error handling: During the traversal and assembly process, any errors or exceptions encountered need to be handled, including but not limited to recording error logs, throwing exceptions, or performing error rollbacks to ensure data consistency and system stability.

[0047] Record error logs: When an error is detected, you first need to record the error details in a log file. The log information should include the time and location of the error (such as which specific node or operation), error type, error message, and possible stack trace information. Logging helps to locate and solve subsequent problems.

[0048] Throwing exceptions: In some cases, throwing exceptions directly may be a better choice, especially when the error cannot be ignored or automatically recovered. By throwing an exception, the current operation can be interrupted immediately and the control flow is transferred to the exception handling code, which helps prevent the error from propagating further in the system and provides clear error feedback to the caller.

[0049] Perform error rollback: If previous operations have modified the data in the database or cache, then after an error is detected, an error rollback operation may be required, which means that all previous modifications need to be undone and the system restored to the state before the error occurred, which helps maintain data consistency and integrity.

[0050] These error handling measures ensure that any errors or abnormalities in the process of traversing and assembling tree data can be discovered and handled properly in a timely manner, thus avoiding system crashes or data corruption.

[0051] 2. Structure verification: After step S4, the assembled tree structure is verified to ensure the correctness and integrity of the tree structure. The verification process may include checking whether the parent node ID of each node correctly points to its parent node, whether the lsLeaf attribute of the leaf node is correctly set, etc.

[0052] Check the parent node ID of each node: Verify whether the pid (parent node ID) of each node correctly points to its parent node. This is the basis for ensuring that the hierarchical relationship of the tree structure is correct. If it is found that the pid of a node points to a non-existent node or points to an incorrect node, an error needs to be recorded and the tree structure may need to be rebuilt.

[0053] Check the lsLeaf attribute of leaf nodes: Verify whether the lsLeaf attribute of leaf nodes is correctly set to true (or the corresponding representation method). Leaf nodes are the bottom-level nodes in the tree structure and have no child nodes. Therefore, their lsLeaf attributes should be clearly identified. If it is found that the lsLeaf attribute of a leaf node is set incorrectly, you need to correct the attribute and re-verify the tree structure.

[0054] Verify other key attributes: In addition to the above two points, you can also verify other key attributes in the tree structure as needed, such as the name and level of the node. The correctness and consistency of these attributes are also important factors in ensuring the accuracy of the tree structure.

[0055] Through structural verification, we can ensure that the assembled tree structure meets the expected requirements and avoid subsequent problems caused by data errors or inconsistencies. If errors or inconsistencies are found during the verification process, they need to be recorded in time and appropriate measures must be taken to correct them.

[0056] Wherein: in step S1, the basic node data also includes other optional attributes in addition to the children attribute, including but not limited to the description information and creation time of the node. These method steps have no effect on the processing of these optional attributes. In the design of node data, in addition to the required attributes, it is also allowed to include additional auxiliary information such as description information and creation time. The existence of this information is to better describe the node characteristics or record the node status, but it is not a direct element for assembling the tree structure. In the subsequent method steps (S2, S3, S4, etc.), the existence or non-existence of these optional attributes will not have a direct impact on the assembly process of the tree structure. That is, whether it is sorting, cache establishment or traversal and assembly steps, the main focus is on those necessary attributes (such as id, pid, level, etc.), and the processing logic of optional attributes is not involved. Allowing the inclusion of optional attributes ensures the integrity of the node data on the one hand, so that each node can carry richer information; on the other hand, it also provides convenience for possible future functional expansion, and new attributes or functions can be added without large-scale modification of the existing data structure. In the process of tree structure assembly, it is reasonable to ignore the processing of optional attributes. Because these attributes are more used for information display or auxiliary analysis, rather than the logical components of the tree structure. Therefore, when assembling a tree structure, we only need to focus on the core attributes that determine the relationship between nodes. In summary, the description of optional attributes in step S1 reflects the flexibility and scalability of the method in data design. It also emphasizes the focus on the core attributes of the data during the tree structure assembly process, ensuring the effectiveness and efficiency of the method.

[0057] A preprocessing step is also included to check the integrity and consistency of the data before sorting it, including checking whether the pid points to a valid parent node and the correctness of the level attribute.

[0058] 1. Check if pid points to a valid parent node Make sure that the pid (parent node ID) of each node points to a real parent node to avoid hanging nodes (i.e. nodes whose parent node ID does not exist in the database).

[0059] Implementation: Read the pids of all nodes from the database.

[0060] For each node's pid, check if there is a corresponding node with id equal to that pid.

[0061] If there are multiple nodes with the same pid but the parent node does not exist, or the pid of a node points to a non-existent node, an error message is logged and an exception may be thrown or an error rollback may be performed.

[0062] 2. Check the correctness of the level attribute Make sure the level attribute of each node matches its actual level in the tree to avoid a chaotic tree structure caused by incorrect levels.

[0063] Implementation: First, confirm that the level of the root node should be 1 (or set to 0 according to specific conventions, 1 is used as an example here).

[0064] Traverse all nodes and trace back the pid of each node until the root node is found.

[0065] Calculate the path length from the root node to the current node (that is, the number of edges passed). This length should be equal to the level value of the current node minus 1 (because the root node level is 1).

[0066] If it is found that the level of a node does not match the level calculated by the path, an error message is recorded, and it may be necessary to correct the level attribute of the node or mark the node as invalid.

[0067] Through the above preprocessing steps, errors and inconsistencies in the data can be discovered and corrected before the data is officially sorted and assembled, thereby ensuring that subsequent steps can be carried out based on accurate and complete data, and ultimately obtaining a correct tree structure. This not only improves the reliability of the data, but also improves the efficiency and stability of the entire processing flow. A computer-readable storage medium stores a computer program, which, when executed by a processor, implements a method for assembling tree-structured data in reverse order; an electronic device includes a processor and a memory, in which a computer program is stored, and when executed by the processor, the computer program implements a method for assembling tree-structured data in reverse order.

[0068] Those skilled in the art will understand that the various digital numbers such as the first and second involved in this application are only for the convenience of description, and are not used to limit the scope of this application, nor do they indicate the order of precedence. "And / or" describes the association relationship of the associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one" refers to one or more. At least two refers to two or more. "At least one", "any one" or similar expressions refer to any combination of these items, including any combination of single items (individuals) or plural items (individuals). For example, at least one item (individual, kind) of a, b, or c can represent: a, b, c, a-b, ac, bc, or abc, where a, b, c can be single or multiple.

[0069] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in this application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices.

[0070] The steps of the method or algorithm described in this application can be directly embedded in hardware, software units executed by a processor, or a combination of the two. The software unit can be stored in RAM memory, flash memory, ROM memory, EPROM memory, EEPROM memory, register, hard disk, removable disk, CD-ROM or any other form of storage medium in the art. Exemplarily, the storage medium can be connected to the processor so that the processor can read information from the storage medium and write information to the storage medium. Optionally, the storage medium can also be integrated into the processor. The processor and the storage medium can be arranged in an ASIC, and the ASIC can be arranged in a terminal. Optionally, the processor and the storage medium can also be arranged in different components in the terminal. These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are performed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide for implementing the process in the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0071] Although the present application has been described in conjunction with specific features and embodiments thereof, it is obvious that various modifications and combinations may be made thereto without departing from the spirit and scope of the present application. Accordingly, this specification and the accompanying drawings are merely exemplary illustrations of the present application and are deemed to have covered any and all modifications, variations, combinations or equivalents within the scope of the present application. Obviously, a person skilled in the art may make various modifications and variations to the present application without departing from the scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the present application and its equivalents, the present application is intended to include these modifications and variations.

Claims

1. A method for assembling tree data in reverse order, characterized in that: The following steps are involved: S1: Preparation step: Store a batch of basic node data of tree structure in the relational database. Each node contains the following attributes: id: the unique identifier of the node; pid: the parent node id corresponding to this node; name: the name of the node; level: the level of the node in the tree, with the root node being the first level; lsLeaf: whether the node is a leaf node (a node at the last level in the tree with no subordinate nodes is a leaf node); Children: child node set, the child node set corresponding to this node; The database does not store the subnode set attributes of the node; S2: Sorting step: Take this batch of data from the database, sort them in reverse order according to the level attribute, and form a new set named sortedList; S3: Cache establishment step: Establish a cache to store the mapping relationship between the parent node ID and the child node set. The cache key is the parent node ID, and the value is the child node set corresponding to the parent node. The cache is named cache; S4: Traversal and assembly step: Loop through each node in sortedList and perform the following operations on each node: Get the pid of the current node; If the pid of the current node is empty, the subsequent operations are ignored and the next cycle continues; Take out the child node set corresponding to the pid from the cache, record it as childItems; if the taken out childItems is empty, create a new childItems for the pid in the cache; Add the current node to childItems; Determine whether the current node is a leaf node. If not, take out the child node set corresponding to the current node id from the cache, record it as subChildItems, set the children attribute of the current node to subChildItems, and delete the subChildItems from the cache; Since sortedList is sorted in reverse order by level, after the traversal is completed, the last node is the root node. At this time, the set of child nodes corresponding to the root node is the assembled tree structure.

2. The method for assembling tree data in reverse order according to claim 1, characterized in that: The children attribute in the node data is not set when stored in the database, but is dynamically generated during the process of assembling the tree structure.

3. The method for assembling tree data in reverse order according to claim 1, characterized in that: In step S3, the cache is implemented using a hash table or a dictionary data structure to improve the efficiency of searching and adding child node sets.

4. The method for assembling tree data in reverse order according to claim 1, characterized in that: In step S1, the basic node data also includes other optional attributes besides the children attribute, including but not limited to the description information and creation time of the node. These method steps have no effect on the processing of these optional attributes.

5. The method for assembling tree data in reverse order according to claim 1, characterized in that: A preprocessing step is also included to check the integrity and consistency of the data before sorting it, including checking whether the pid points to a valid parent node and the correctness of the level attribute.

6. The method for assembling tree data in reverse order according to claim 1, characterized in that: In step S4, it also includes processing any errors or abnormal situations encountered during the assembly process, including but not limited to recording error logs, throwing exceptions or performing error rollback to ensure data consistency and system stability.

7. The method for assembling tree data in reverse order according to claim 1, characterized in that: The method also includes the step of verifying the assembled tree structure after step S4 to ensure the correctness and integrity of the tree structure.

8. A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method for assembling tree-structured data in reverse order according to any one of claims 1 to 7.

9. An electronic device comprising a processor and a memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, the method for assembling tree structure data in reverse order according to any one of claims 1 to 7 is implemented.