Positioning access method for three-level catalog of energy product
By adopting binary tree data structure and real-time update optimization technology in the third-level directory management of energy and chemical products, the problem of low efficiency and accuracy of directory management in the existing technology is solved, efficient and accurate directory positioning and access is achieved, and user experience and system performance are improved.
Patent Information
- Application Number
- CN202411847059.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-16
- Publication Date
- 2025-03-28
AI Technical Summary
The prior art has problems of low efficiency and accuracy in the third-level catalog management of energy and chemical products, which cannot meet the users' efficient positioning and access needs.
Use binary tree data structure to build a three-level directory of energy-based products, locate the target directory in the binary tree through keyword search or path selection, and provide access methods for list or tree display. At the same time, it supports real-time update of the binary tree to maintain consistency with the actual directory structure, and periodic balanced rotation optimizations to improve system performance.
It realizes efficient, accurate positioning and access to the three-level catalog of energy and chemical products, improves the efficiency and user experience of catalog management, and ensures the stability and performance of the system through real-time updates and optimizations.
Smart Images

Figure CN119719425A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of search algorithms, and in particular to a positioning access method for a three-level directory of energy and chemical products. Background Art
[0002] With the continuous expansion of the energy and chemical product market, the types and quantities of products are increasing. How to efficiently organize and manage these products has become an urgent problem to be solved. Traditional directory management methods often have problems such as low efficiency and inaccurate positioning, and cannot meet the needs of users. For example, the Chinese patent publication number is CN110619066A, which discloses a method and device for obtaining information based on a directory tree, which determines the root node of the directory tree according to a first dictionary; takes the root node as the current node of the directory tree, determines the child node corresponding to the current node according to the correspondence between the keywords and values in the first dictionary, and adds it to the directory tree; determines the leaf node corresponding to the branch node according to the correspondence between each keyword and value in the second dictionary, and adds it to the directory tree to obtain the target directory tree; operates the target directory tree through the terminal to obtain directory information. However, the above scheme still has the following problems that have not been solved: the efficiency and accuracy of directory management are low. Therefore, the present invention proposes a three-level directory positioning access method for energy and chemical products based on a binary tree data structure to improve the efficiency and accuracy of directory management. Summary of the invention
[0003] The technical problem to be solved by the present invention is to overcome the deficiencies of the prior art and provide a method for locating and accessing a three-level directory of energy and chemical products.
[0004] The technical solution adopted by the present invention is as follows: A method for locating and accessing a three-level directory of energy and chemical products comprises the following steps: S1. Construct a binary tree: According to the directory structure of energy and chemical products, a binary tree is constructed. Each node represents a directory level, including the directory name and a unique identifier ID. The root node represents the highest level directory, and each node has at most two child nodes, representing the left branch and the right branch of the next level directory respectively. S2. Search the binary tree: Locate the directory in the binary tree by entering keywords or selecting a path; start the search from the root node, and compare the ID of the current node and the directory name in turn according to the entered keywords or the selected path to determine the search direction; if a matching node is found, enter the subtree of the node to continue searching; if no matching node is found, continue to search other nodes according to the search strategy; S3. Access the third-level directory: When locating the target directory, view the product information under the directory; provide different access methods according to needs, including list display and tree display; S4. Update binary tree: As the directory structure of energy and chemical products changes, the binary tree is updated in real time to maintain its consistency with the actual directory structure; the update operation is achieved by adding new nodes, deleting old nodes, or modifying node information; S5. Optimize binary trees: Regularly optimize the binary tree, including rotation operations to balance the binary tree, to maintain the balance and stability of the tree.
[0005] This technical solution achieves accurate positioning and efficient access to the three-level directory of energy and chemical products by constructing a binary tree. First, a binary tree model is established based on the directory structure of the product, in which each node corresponds to a directory level and contains the directory name and unique identifier; the target directory is quickly located in the binary tree by keyword search or path selection; once the location is successful, a variety of access methods are provided, such as list and tree display, so that users can browse the product information under the directory; to maintain consistency with the actual directory structure, this method supports real-time updating of the binary tree, including operations such as adding, deleting and modifying nodes; by regularly optimizing the binary tree, such as rotating the balanced binary tree, the balance and stability of the tree are ensured, thereby improving the performance and reliability of the entire system. Specifically, a binary tree is chosen as the data structure because it can intuitively and efficiently represent hierarchical or tree-structured data; the target directory is located in the binary tree by keyword search or path selection; starting from the root node, the search direction (left subtree or right subtree) is determined by comparing the ID and directory name of the current node with the input keyword or path; if the current node does not match, other nodes are searched according to the search strategy (such as depth-first search, breadth-first search, etc.); if a matching node is found, the subtree of the node is entered to continue the search; when the search locates the target third-level directory, the access operation is performed; according to the needs, Provide different access methods, such as list display (displaying all product information under the directory) or tree display (displaying the hierarchical structure of the directory); as the structure of the energy and chemical product directory changes, the binary tree needs to be updated in real time to maintain consistency with the actual directory structure; update operations include adding new nodes (when a new directory is added), deleting old nodes (when a directory is deleted) or modifying node information (when directory information changes); maintaining the balance and stability of the binary tree requires regular optimization operations; optimization strategies include rotation operations on balanced binary trees (such as AVL trees, red-black trees, and other balancing strategies) to ensure that the height of the tree is not too high, thereby improving search efficiency.
[0006] In addition, the positioning access method for the three-level directory of energy and chemical products proposed above according to the present invention also has the following additional technical features: According to an embodiment of the present invention, in the binary tree construction of step S1, the path of the directory structure is unique, and each directory name corresponds to a unique ID; a stack path_stack is used to record the path from the root node to the current node, and the child nodes are accessed directly through the node reference; the nodes are added according to the order of the directory structure to ensure that the parent node has been created before the child node is added; If there are duplicate directory names in the directory structure and the IDs are different, only the IDs are used to identify the nodes, that is, as long as the IDs are different, they are considered different nodes.
[0007] This technical solution ensures the accuracy and uniqueness of the energy product directory structure by constructing a binary tree with a unique path and directory name corresponding to a unique ID. During the construction process, a stack is used to record the path from the root node to the current node, so that the child node can be directly accessed through the node reference to improve access efficiency; the nodes are added according to the order of the directory structure to ensure that the parent node has been created before the child node is added, thereby avoiding confusion in the directory structure; for nodes with the same directory name but different IDs, only the ID is used to identify the node, ensuring that even if the directory name is the same, as long as the ID is different, it is regarded as a different node, further enhancing the uniqueness and accuracy of the directory structure.
[0008] According to an embodiment of the present invention, in the binary tree search of step S2, a data structure of a binary tree node is defined, including the node ID and child nodes, and a recursive function is used to search the binary tree, starting from the root node, recursively comparing the node IDs, and determining the search direction according to the existence of the child nodes; assuming that the binary tree is constructed in lexicographic order, the left or right search is determined by comparing the IDs; If the binary tree is not strictly ordered, the search direction is determined by the name or other identifier of the node; If a matching ID is found but the node has children, assume that the search continues through recursive calls to the left and right subtrees; If your binary tree represents a directory structure, and the directory names are unique, then build and search the binary tree based on the directory names instead of relying solely on the IDs.
[0009] This technical solution defines a binary tree node data structure containing node IDs and child nodes, and uses a recursive function to search the binary tree to achieve efficient and accurate directory positioning. The search process starts from the root node, and recursively determines the search direction by comparing the node ID and the existence of child nodes; if the binary tree is constructed in dictionary order, the search direction will be determined based on the comparison result of the ID; in the case of non-strict order, the search direction will be determined based on the name of the node or other identifiers. When a matching ID is found, if the node has child nodes, the search will continue to recursively traverse the left subtree and the right subtree to ensure the comprehensiveness of the search. In particular, if the binary tree represents a directory structure and the directory name is unique, the search strategy will build and search the binary tree based on the directory name to improve the accuracy and efficiency of the search.
[0010] According to an embodiment of the present invention, accessing the third-level directory in step S3 specifically includes the following steps: S31. Search and locate the third-level directory node: S311, initialization search: start searching from the root node of the binary tree; S312, compare layer by layer: starting from the root node, compare the node ID or directory name with the ID or name of the third-level directory to be accessed layer by layer; S313, determine the search direction: If the ID or name of the current node matches the target third-level directory, and the node has no child nodes or the child nodes are empty, it means that the third-level directory has been reached, then enter S32; If the ID or name of the current node does not match the target, but there are child nodes, choose to continue searching left or right according to the search strategy; If the current node has neither child nodes nor the target third-level directory, return to the previous node and continue searching; S314, recursive search: if the current node is not the target third-level directory, but has child nodes, recursively call the search function to continue searching for child nodes; S32. Access and obtain product information in the third-level directory: S321, verify node: after reaching the target third-level directory node, verify that the node is indeed a third-level directory; S322, extract product information: extract product information from the third-level directory node, including a product list and detailed information of each product, wherein the detailed information includes name, description, and price; S323, formatting product information: formatting the extracted product information into a format suitable for subsequent processing, including a list and a dictionary structure; S33, display the third-level catalog product information: S331, select display mode: select a suitable display mode according to user needs or system settings, including list display, tree display or graphical display; S332. Rendering interface: Render product information onto the user interface using HTML, CSS, JavaScript or D3.js; S333. Providing interactive functions: providing users with functions for interacting with product information, including viewing product details, adding to shopping carts, and filtering and sorting; S34. Processing user interaction: S341, monitoring user operations: monitoring user operations on displayed product information, including click, select, and drag; S342, response operation: execute corresponding functions according to the user's operation, including jumping to the product details page, updating the shopping cart, and adjusting the product sorting; S343, update interface: according to the result of the user operation, update the user interface in real time to keep synchronization with the user operation.
[0011] This technical solution achieves accurate access to the three-level directory and effective display of product information. First, the three-level directory node is searched and located by initializing the search and comparing the node ID or directory name layer by layer. During the search process, the search direction is determined based on the match between the current node and the target three-level directory, and the child nodes are recursively searched to ensure accuracy; when the target three-level directory is located, the node is verified to be a three-level directory, and product information is extracted from it, including a product list and detailed information for each product. Subsequently, the extracted product information is formatted into a format suitable for subsequent processing, and a suitable display method is selected, such as a list, tree, or graphical display; when rendering the user interface, HTML, CSS, JavaScript, or D3.js technology is used to present product information, and interactive functions are provided to users, such as viewing product details, adding to a shopping cart, filtering and sorting, etc.; by monitoring user operations, responding to operations, and updating the interface in real time, good interaction with users is achieved to improve user experience.
[0012] According to one embodiment of the present invention, the updating of the binary tree in step S4 specifically includes the following steps: S41. Determine the update type: S411, analyzing changes: analyzing changes in the directory structure to determine whether it is necessary to add new nodes, delete old nodes, or modify information of existing nodes; S412, classification processing: according to the analysis results, the update operation is classified into adding, deleting or modifying, and the corresponding data and logic are prepared; S42. Add a new node: S421, locating the parent node: locating the parent node of the new node in the binary tree according to the parent directory information of the new node; S422, creating a new node: creating a new binary tree node using the directory name and unique identifier ID of the new node; S423, inserting a new node: according to the binary tree rule, inserting the new node into the left subtree or right subtree of its parent node; S424, updating the parent-child relationship: ensuring that the parent-child relationship between the new node and its parent node is correctly established; S43. Delete the old node: S431, locating the target node: locating the target node in the binary tree according to the ID or path information of the node to be deleted; S432, processing child nodes: if the target node has child nodes, all its child nodes need to be recursively deleted; S433, remove node: remove the target node from the child node list of the parent node to ensure the integrity of the binary tree structure; S44. Modify node information: S441, locating the target node: locating the target node in the binary tree according to the ID information of the node to be modified; S442, updating node information: using a new directory name, unique identifier ID or other information to update the target node information; S443, keep the structure unchanged: ensure that the structure of the binary tree is not changed during the process of modifying the node information; S45. Verify update result: S451, traversal check: Use the traversal algorithm to check whether the structure of the binary tree is correct, ensuring that there are no missing nodes or incorrect parent-child relationships; S452, information verification: Verify whether the updated node information is consistent with the expected changes to ensure the accuracy of the data.
[0013] This technical solution implements the update operation of the binary tree to maintain the consistency of the binary tree and the energy and chemical product directory structure. First, by analyzing the changes in the directory structure, determine the type of update operation that needs to be performed, including adding new nodes, deleting old nodes, or modifying the information of existing nodes; perform corresponding operations according to the update type: for adding new nodes, ensure that the new node is correctly added to the binary tree by locating the parent node, creating a new node, inserting the new node, and updating the parent-child relationship; for deleting old nodes, ensure that the target node and its child nodes are correctly removed from the binary tree by locating the target node, processing the child node, and removing the node; for modifying node information, ensure that the node information is accurately modified without affecting the overall structure of the binary tree by locating the target node, updating the node information, and keeping the structure unchanged; verify the update results through traversal inspection and information verification to ensure that the structure of the binary tree is correct and the node information is accurate, thereby achieving real-time response and accurate reflection of changes in the energy and chemical product directory structure.
[0014] According to one embodiment of the present invention, the optimization of the binary tree in step S5 specifically includes the following steps: S51, traverse and check the binary tree: S511, select traversal method: select a suitable traversal method to check the binary tree; S512, check balance: during the traversal process, calculate the height difference between the left and right subtrees of each node to check whether the property of a balanced binary tree is satisfied; S513, marking unbalanced nodes: when a node that does not satisfy the balance property is found, the node is marked as an unbalanced node, and its related information is recorded; S52. Perform a rotation operation on the unbalanced node: S521, determine the rotation type: determine which type of rotation operation needs to be performed according to the subtree height difference of the unbalanced node and the value of the child node; S522, performing a rotation operation: Right rotation: If the height of the left subtree is two or more times higher than that of the right subtree, select the rightmost node of the left subtree as the new root node, make the original root node the left child of the new root node, and make the right child of the original root node the right child of the new root node; Left rotation: If the height of the right subtree is two or more times higher than that of the left subtree, select the leftmost node of the right subtree as the new root node, make the original root node the right child of the new root node, and make the left child of the original root node the left child of the new root node; Right-left or left-right: if the imbalance is more complicated, first do one rotation, then the other; S523, updating node information: after the rotation operation, updating the parent-child relationship, height and other information of the relevant nodes; S53, recursively check and rotate subtrees: S531, recursive check: for the new unbalanced subtree generated after the rotation, recursively execute steps S51 and S52 until the entire binary tree is balanced again; S532, stop condition: when the entire binary tree is traversed and no unbalanced nodes are found, the optimization operation is stopped; S54. Verify optimization results: S541, traverse and check again: after the optimization operation is completed, traverse the binary tree again to check whether all nodes meet the properties of a balanced binary tree; S542. Record log: record detailed information and results of optimization operations for subsequent analysis and debugging.
[0015] This technical solution ensures the balance and stability of the binary tree, thereby improving its performance and search efficiency. First, by traversing the binary tree and checking the balance of each node, unbalanced nodes are marked; for these unbalanced nodes, according to the height difference of their subtrees and the values of the child nodes, the corresponding rotation operation is determined and performed, including right rotation, left rotation or more complex rotation combinations, to restore the balance of the binary tree; after the rotation operation, the information of the relevant nodes will be updated to maintain the accuracy of the data; the new unbalanced subtrees generated after the rotation operation are recursively checked and rotated until the entire binary tree is restored to balance; the optimization results are verified by traversing the binary tree again to ensure that all nodes meet the properties of a balanced binary tree, and the detailed information and results of the optimization operation are recorded for subsequent analysis and debugging.
[0016] Compared with the prior art, the present invention has the following beneficial effects: By constructing a binary tree data structure to organize and manage the catalog information of energy and chemical products, efficient and accurate three-level catalog location access is achieved; it is suitable for areas such as product classification display on e-commerce platforms and three-level regional display of provinces, cities and districts, providing users with a convenient search and browsing experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 It is a flow diagram of the present invention.
[0018] Figure 2 This is a diagram of interface changes before and after positioning access of the present invention.
[0019] Figure 3 This is an example diagram of the procedure for constructing a binary tree in step S1 of the present invention.
[0020] Figure 4 This is an example diagram of the procedure for searching the binary tree in step S2 of the present invention.
[0021] Figure 5 This is an example diagram of the procedure for accessing the third-level directory in step S3 of the present invention.
[0022] Figure 6 This is an example diagram of the procedure for updating the binary tree in step S4 of the present invention.
[0023] Figure 7 This is an example diagram of the procedure for optimizing the binary tree in step S5 of the present invention. DETAILED DESCRIPTION
[0024] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0025] Example 1 like Figure 1 As shown, this embodiment provides a method for locating and accessing the three-level directory of energy and chemical products, including the following steps: S1. Construct a binary tree: Figure 3 As shown in the figure, according to the directory structure of energy and chemical products, a binary tree is constructed. Each node represents a directory level, including the directory name and the unique identifier ID. The root node represents the highest level directory, and each node has at most two child nodes, representing the left branch and the right branch of the next level directory respectively. S2, search binary tree: Figure 4 As shown, by inputting keywords or selecting paths, the directory is located in the binary tree; the search starts from the root node, and the ID of the current node and the directory name are compared in turn according to the input keywords or the selected path to determine the search direction; if a matching node is found, the subtree of the node is entered to continue the search; if no matching node is found, other nodes are searched according to the search strategy; S3, access the third-level directory: Figure 5 As shown, when locating the target directory, view the product information under the directory; provide different access methods according to needs, including list display and tree display; S4, update the binary tree: Figure 6 As shown in the figure, as the directory structure of energy and chemical products changes, the binary tree is updated in real time to maintain its consistency with the actual directory structure; the update operation is achieved by adding new nodes, deleting old nodes, or modifying node information; S5. Optimize binary tree: Figure 7 As shown, optimization operations are performed on the binary tree regularly, including rotation operations to balance the binary tree, so as to maintain the balance and stability of the tree.
[0026] like Figures 1 to 7As shown, this technical solution realizes accurate positioning and efficient access to the three-level directory of energy and chemical products by constructing a binary tree. First, a binary tree model is established based on the directory structure of the product, in which each node corresponds to a directory level and contains the directory name and a unique identifier; the target directory is quickly located in the binary tree by keyword search or path selection; once the location is successful, a variety of access methods are provided, such as list and tree display, so that users can browse the product information under the directory; to maintain consistency with the actual directory structure, this method supports real-time updating of the binary tree, including operations such as adding, deleting and modifying nodes; by regularly optimizing the binary tree, such as rotating the balanced binary tree, the balance and stability of the tree are ensured, thereby improving the performance and reliability of the entire system. Specifically, a binary tree is chosen as the data structure because it can intuitively and efficiently represent hierarchical or tree-structured data; the target directory is located in the binary tree by keyword search or path selection; starting from the root node, the search direction (left subtree or right subtree) is determined by comparing the ID and directory name of the current node with the input keyword or path; if the current node does not match, other nodes are searched according to the search strategy (such as depth-first search, breadth-first search, etc.); if a matching node is found, the subtree of the node is entered to continue the search; when the search locates the target third-level directory, the access operation is performed; according to the needs, Provide different access methods, such as list display (displaying all product information under the directory) or tree display (displaying the hierarchical structure of the directory); as the structure of the energy and chemical product directory changes, the binary tree needs to be updated in real time to maintain consistency with the actual directory structure; update operations include adding new nodes (when a new directory is added), deleting old nodes (when a directory is deleted) or modifying node information (when directory information changes); maintaining the balance and stability of the binary tree requires regular optimization operations; optimization strategies include rotation operations on balanced binary trees (such as AVL trees, red-black trees, and other balancing strategies) to ensure that the height of the tree is not too high, thereby improving search efficiency.
[0027] In addition, the positioning access method for the three-level directory of energy and chemical products proposed above according to the present invention also has the following additional technical features: like Figure 3 As shown, in the binary tree constructed in step S1, the path of the directory structure is unique, and each directory name corresponds to a unique ID; a stack path_stack is used to record the path from the root node to the current node, and the child nodes are accessed directly through the node reference; the nodes are added according to the order of the directory structure to ensure that the parent node has been created before the child node is added; If there are duplicate directory names in the directory structure and the IDs are different, only the IDs are used to identify the nodes, that is, as long as the IDs are different, they are considered different nodes.
[0028] This technical solution ensures the accuracy and uniqueness of the energy product directory structure by constructing a binary tree with a unique path and directory name corresponding to a unique ID. During the construction process, a stack is used to record the path from the root node to the current node, so that the child node can be directly accessed through the node reference to improve access efficiency; the nodes are added according to the order of the directory structure to ensure that the parent node has been created before the child node is added, thereby avoiding confusion in the directory structure; for nodes with the same directory name but different IDs, only the ID is used to identify the node, ensuring that even if the directory name is the same, as long as the ID is different, it is regarded as a different node, further enhancing the uniqueness and accuracy of the directory structure.
[0029] like Figure 4 As shown, in the search binary tree of step S2, a data structure of a binary tree node is defined, including the node ID and child nodes, and a recursive function is used to search the binary tree, starting from the root node, recursively comparing the node IDs, and determining the search direction according to the existence of the child nodes; assuming that the binary tree is constructed in lexicographic order, the left or right search is determined by comparing the IDs; If the binary tree is not strictly ordered, the search direction is determined by the name or other identifier of the node; If a matching ID is found but the node has children, assume that the search continues through recursive calls to the left and right subtrees; If your binary tree represents a directory structure, and the directory names are unique, then build and search the binary tree based on the directory names instead of relying solely on the IDs.
[0030] This technical solution defines a binary tree node data structure containing node IDs and child nodes, and uses a recursive function to search the binary tree to achieve efficient and accurate directory positioning. The search process starts from the root node, and recursively determines the search direction by comparing the node ID and the existence of child nodes; if the binary tree is constructed in dictionary order, the search direction will be determined based on the comparison result of the ID; in the case of non-strict order, the search direction will be determined based on the name of the node or other identifiers. When a matching ID is found, if the node has child nodes, the search will continue to recursively traverse the left subtree and the right subtree to ensure the comprehensiveness of the search. In particular, if the binary tree represents a directory structure and the directory name is unique, the search strategy will build and search the binary tree based on the directory name to improve the accuracy and efficiency of the search.
[0031] like Figure 5 As shown, the step S3 of accessing the third-level directory specifically includes the following steps: S31. Search and locate the third-level directory node: S311, initialization search: start searching from the root node of the binary tree; S312, compare layer by layer: starting from the root node, compare the node ID or directory name with the ID or name of the third-level directory to be accessed layer by layer; S313, determine the search direction: If the ID or name of the current node matches the target third-level directory, and the node has no child nodes or the child nodes are empty, it means that the third-level directory has been reached, then enter S32; If the ID or name of the current node does not match the target, but there are child nodes, choose to continue searching left or right according to the search strategy; If the current node has neither child nodes nor the target third-level directory, return to the previous node and continue searching; S314, recursive search: if the current node is not the target third-level directory, but has child nodes, recursively call the search function to continue searching for child nodes; S32. Access and obtain product information in the third-level directory: S321, verify node: after reaching the target third-level directory node, verify that the node is indeed a third-level directory; S322, extract product information: extract product information from the third-level directory node, including a product list and detailed information of each product, wherein the detailed information includes name, description, and price; S323, formatting product information: formatting the extracted product information into a format suitable for subsequent processing, including a list and a dictionary structure; S33, display the third-level catalog product information: S331, select display mode: select a suitable display mode according to user needs or system settings, including list display, tree display or graphical display; S332. Rendering interface: Render product information onto the user interface using HTML, CSS, JavaScript or D3.js; S333. Providing interactive functions: providing users with functions for interacting with product information, including viewing product details, adding to shopping carts, and filtering and sorting; S34. Processing user interaction: S341, monitoring user operations: monitoring user operations on displayed product information, including click, select, and drag; S342, response operation: execute corresponding functions according to the user's operation, including jumping to the product details page, updating the shopping cart, and adjusting the product sorting; S343, update interface: according to the result of the user operation, update the user interface in real time to keep synchronization with the user operation.
[0032] This technical solution achieves accurate access to the three-level directory and effective display of product information. First, the three-level directory node is searched and located by initializing the search and comparing the node ID or directory name layer by layer. During the search process, the search direction is determined based on the match between the current node and the target three-level directory, and the child nodes are recursively searched to ensure accuracy; when the target three-level directory is located, the node is verified to be a three-level directory, and product information is extracted from it, including a product list and detailed information for each product. Subsequently, the extracted product information is formatted into a format suitable for subsequent processing, and a suitable display method is selected, such as a list, tree, or graphical display; when rendering the user interface, HTML, CSS, JavaScript, or D3.js technology is used to present product information, and interactive functions are provided to users, such as viewing product details, adding to a shopping cart, filtering and sorting, etc.; by monitoring user operations, responding to operations, and updating the interface in real time, good interaction with users is achieved to improve user experience.
[0033] like Figure 6 As shown, the updating of the binary tree in step S4 specifically includes the following steps: S41. Determine the update type: S411, analyzing changes: analyzing changes in the directory structure to determine whether it is necessary to add new nodes, delete old nodes, or modify information of existing nodes; S412, classification processing: according to the analysis results, the update operation is classified into adding, deleting or modifying, and the corresponding data and logic are prepared; S42. Add a new node: S421, locating the parent node: locating the parent node of the new node in the binary tree according to the parent directory information of the new node; S422, creating a new node: creating a new binary tree node using the directory name and unique identifier ID of the new node; S423, inserting a new node: according to the binary tree rule, inserting the new node into the left subtree or right subtree of its parent node; S424, updating the parent-child relationship: ensuring that the parent-child relationship between the new node and its parent node is correctly established; S43. Delete the old node: S431, locating the target node: locating the target node in the binary tree according to the ID or path information of the node to be deleted; S432, processing child nodes: if the target node has child nodes, all its child nodes need to be recursively deleted; S433, remove node: remove the target node from the child node list of the parent node to ensure the integrity of the binary tree structure; S44. Modify node information: S441, locating the target node: locating the target node in the binary tree according to the ID information of the node to be modified; S442, updating node information: using a new directory name, unique identifier ID or other information to update the target node information; S443, keep the structure unchanged: ensure that the structure of the binary tree is not changed during the process of modifying the node information; S45. Verify update result: S451, traversal check: Use the traversal algorithm to check whether the structure of the binary tree is correct, ensuring that there are no missing nodes or incorrect parent-child relationships; S452, information verification: Verify whether the updated node information is consistent with the expected changes to ensure the accuracy of the data.
[0034] This technical solution implements the update operation of the binary tree to maintain the consistency of the binary tree and the energy and chemical product directory structure. First, by analyzing the changes in the directory structure, determine the type of update operation that needs to be performed, including adding new nodes, deleting old nodes, or modifying the information of existing nodes; perform corresponding operations according to the update type: for adding new nodes, ensure that the new node is correctly added to the binary tree by locating the parent node, creating a new node, inserting the new node, and updating the parent-child relationship; for deleting old nodes, ensure that the target node and its child nodes are correctly removed from the binary tree by locating the target node, processing the child node, and removing the node; for modifying node information, ensure that the node information is accurately modified without affecting the overall structure of the binary tree by locating the target node, updating the node information, and keeping the structure unchanged; verify the update results through traversal inspection and information verification to ensure that the structure of the binary tree is correct and the node information is accurate, thereby achieving real-time response and accurate reflection of changes in the energy and chemical product directory structure.
[0035] like Figure 7 As shown, the optimization of the binary tree in step S5 specifically includes the following steps: S51, traverse and check the binary tree: S511, select traversal method: select a suitable traversal method to check the binary tree; S512, check balance: during the traversal process, calculate the height difference between the left and right subtrees of each node to check whether the property of a balanced binary tree is satisfied; S513, marking unbalanced nodes: when a node that does not satisfy the balance property is found, the node is marked as an unbalanced node, and its related information is recorded; S52. Perform a rotation operation on the unbalanced node: S521, determine the rotation type: determine which type of rotation operation needs to be performed according to the subtree height difference of the unbalanced node and the value of the child node; S522, performing a rotation operation: Right rotation: If the height of the left subtree is two or more times higher than that of the right subtree, select the rightmost node of the left subtree as the new root node, make the original root node the left child of the new root node, and make the right child of the original root node the right child of the new root node; Left rotation: If the height of the right subtree is two or more times higher than that of the left subtree, select the leftmost node of the right subtree as the new root node, make the original root node the right child of the new root node, and make the left child of the original root node the left child of the new root node; Right-left or left-right: if the imbalance is more complicated, first do one rotation, then the other; S523, updating node information: after the rotation operation, updating the parent-child relationship, height and other information of the relevant nodes; S53, recursively check and rotate subtrees: S531, recursive check: for the new unbalanced subtree generated after the rotation, recursively execute steps S51 and S52 until the entire binary tree is balanced again; S532, stop condition: when the entire binary tree is traversed and no unbalanced nodes are found, the optimization operation is stopped; S54. Verify optimization results: S541, traverse and check again: after the optimization operation is completed, traverse the binary tree again to check whether all nodes meet the properties of a balanced binary tree; S542. Record log: record detailed information and results of optimization operations for subsequent analysis and debugging.
[0036] This technical solution ensures the balance and stability of the binary tree, thereby improving its performance and search efficiency. First, by traversing the binary tree and checking the balance of each node, unbalanced nodes are marked; for these unbalanced nodes, according to the height difference of their subtrees and the values of the child nodes, the corresponding rotation operation is determined and performed, including right rotation, left rotation or more complex rotation combinations, to restore the balance of the binary tree; after the rotation operation, the information of the relevant nodes will be updated to maintain the accuracy of the data; the new unbalanced subtrees generated after the rotation operation are recursively checked and rotated until the entire binary tree is restored to balance; the optimization results are verified by traversing the binary tree again to ensure that all nodes meet the properties of a balanced binary tree, and the detailed information and results of the optimization operation are recorded for subsequent analysis and debugging.
[0037] Although the present invention is described in detail by referring to the accompanying drawings and in combination with the preferred embodiments, the present invention is not limited thereto. Without departing from the spirit and essence of the present invention, a person of ordinary skill in the art may make various equivalent modifications or substitutions to the embodiments of the present invention, and these modifications or substitutions shall be within the scope of the present invention. Any person of ordinary skill in the art may easily think of changes or substitutions within the technical scope disclosed by the present invention, and these shall be within the scope of protection of the present invention. Therefore, the scope of protection of the present invention shall be subject to the scope of protection of the claims.
Claims
1. A method for locating and accessing the three-level directory of energy and chemical products, characterized in that: The steps include: S1. Construct a binary tree: According to the directory structure of energy and chemical products, a binary tree is constructed. Each node represents a directory level, including the directory name and a unique identifier ID. The root node represents the highest level directory, and each node has at most two child nodes, representing the left branch and the right branch of the next level directory respectively. S2. Search the binary tree: Locate the directory in the binary tree by entering a keyword or selecting a path; start the search from the root node, and compare the ID of the current node and the directory name in turn according to the entered keyword or selected path to determine the search direction; if a matching node is found, enter the subtree of the node to continue searching; If no matching node is found, continue searching for other nodes according to the search strategy; S3. Access the third-level directory: When locating the target directory, view the product information under the directory; provide different access methods according to needs, including list display and tree display; S4. Update binary tree: As the directory structure of energy and chemical products changes, the binary tree is updated in real time to maintain its consistency with the actual directory structure; Update operations are implemented by adding new nodes, deleting old nodes, or modifying node information; S5. Optimize binary trees: Regularly optimize the binary tree, including rotation operations to balance the binary tree, to maintain the balance and stability of the tree.
2. The method for locating and accessing the three-level directory of energy and chemical products according to claim 1, characterized in that: In the binary tree constructed in step S1, the path of the directory structure is unique, and each directory name corresponds to a unique ID; a stack path_stack is used to record the path from the root node to the current node, and the child nodes are accessed directly through the node reference; the nodes are added according to the order of the directory structure to ensure that the parent node has been created before the child node is added; If there are duplicate directory names in the directory structure and the IDs are different, only the IDs are used to identify the nodes, that is, as long as the IDs are different, they are considered different nodes.
3. The method for locating and accessing the three-level directory of energy and chemical products according to claim 1 or 2, characterized in that: In the binary tree search of step S2, a data structure of a binary tree node is defined, including the node ID and child nodes, and a recursive function is used to search the binary tree, starting from the root node, recursively comparing the node IDs, and determining the search direction according to the existence of the child nodes; assuming that the binary tree is constructed in lexicographic order, the left or right search is determined by comparing the IDs; If the binary tree is not strictly ordered, the search direction is determined by the name or other identifier of the node; If a matching ID is found but the node has children, assume that the search continues through recursive calls to the left and right subtrees; If your binary tree represents a directory structure, and the directory names are unique, then build and search the binary tree based on the directory names instead of relying solely on the IDs.
4. The method for locating and accessing the three-level directory of energy and chemical products according to claim 3, characterized in that: The step S3 of accessing the third-level directory specifically includes the following steps: S31. Search and locate the third-level directory node: S311, initialization search: start searching from the root node of the binary tree; S312, compare layer by layer: starting from the root node, compare the node ID or directory name with the ID or name of the third-level directory to be accessed layer by layer; S313, determine the search direction: If the ID or name of the current node matches the target third-level directory, and the node has no child nodes or the child nodes are empty, it means that the third-level directory has been reached, then enter S32; If the ID or name of the current node does not match the target, but there are child nodes, choose to continue searching left or right according to the search strategy; If the current node has neither child nodes nor the target third-level directory, return to the previous node and continue searching; S314, recursive search: if the current node is not the target third-level directory, but has child nodes, recursively call the search function to continue searching for child nodes; S32. Access and obtain product information in the third-level directory: S321, verify node: after reaching the target third-level directory node, verify that the node is indeed a third-level directory; S322, extract product information: extract product information from the third-level directory node, including a product list and detailed information of each product, wherein the detailed information includes name, description, and price; S323, formatting product information: formatting the extracted product information into a format suitable for subsequent processing, including a list and a dictionary structure; S33, display the third-level catalog product information: S331, select display mode: select a suitable display mode according to user needs or system settings, including list display, tree display or graphical display; S332. Rendering interface: Render product information onto the user interface using HTML, CSS, JavaScript or D3.js; S333. Providing interactive functions: providing users with functions for interacting with product information, including viewing product details, adding to shopping carts, and filtering and sorting; S34. Processing user interaction: S341, monitoring user operations: monitoring user operations on displayed product information, including click, select, and drag; S342, response operation: execute corresponding functions according to the user's operation, including jumping to the product details page, updating the shopping cart, and adjusting the product sorting; S343, update interface: according to the result of the user operation, update the user interface in real time to keep synchronization with the user operation.
5. The method for locating and accessing the three-level directory of energy and chemical products according to claim 4, characterized in that: The updating of the binary tree in step S4 specifically includes the following steps: S41. Determine the update type: S411, analyzing changes: analyzing changes in the directory structure to determine whether it is necessary to add new nodes, delete old nodes, or modify information of existing nodes; S412, classification processing: according to the analysis results, the update operation is classified into adding, deleting or modifying, and the corresponding data and logic are prepared; S42. Add a new node: S421, locating the parent node: locating the parent node of the new node in the binary tree according to the parent directory information of the new node; S422, creating a new node: creating a new binary tree node using the directory name and unique identifier ID of the new node; S423, inserting a new node: according to the binary tree rule, inserting the new node into the left subtree or right subtree of its parent node; S424, updating the parent-child relationship: ensuring that the parent-child relationship between the new node and its parent node is correctly established; S43. Delete the old node: S431, locating the target node: locating the target node in the binary tree according to the ID or path information of the node to be deleted; S432, processing child nodes: if the target node has child nodes, all its child nodes need to be recursively deleted; S433, remove node: remove the target node from the child node list of the parent node to ensure the integrity of the binary tree structure; S44. Modify node information: S441, locating the target node: locating the target node in the binary tree according to the ID information of the node to be modified; S442, updating node information: using a new directory name, unique identifier ID or other information to update the target node information; S443, keep the structure unchanged: ensure that the structure of the binary tree is not changed during the process of modifying the node information; S45. Verify update result: S451, traversal check: Use the traversal algorithm to check whether the structure of the binary tree is correct, ensuring that there are no missing nodes or incorrect parent-child relationships; S452, information verification: Verify whether the updated node information is consistent with the expected changes to ensure the accuracy of the data.
6. The method for locating and accessing the three-level directory of energy and chemical products according to claim 5, characterized in that: The optimization of the binary tree in step S5 specifically includes the following steps: S51, traverse and check the binary tree: S511, select traversal method: select a suitable traversal method to check the binary tree; S512, check balance: during the traversal process, calculate the height difference between the left and right subtrees of each node to check whether the property of a balanced binary tree is satisfied; S513, marking unbalanced nodes: when a node that does not satisfy the balance property is found, the node is marked as an unbalanced node, and its related information is recorded; S52. Perform a rotation operation on the unbalanced node: S521, determine the rotation type: determine which type of rotation operation needs to be performed according to the subtree height difference of the unbalanced node and the value of the child node; S522, performing a rotation operation: Right rotation: If the height of the left subtree is two or more times higher than that of the right subtree, select the rightmost node of the left subtree as the new root node, make the original root node the left child of the new root node, and make the right child of the original root node the right child of the new root node; Left rotation: If the height of the right subtree is two or more times higher than that of the left subtree, select the leftmost node of the right subtree as the new root node, make the original root node the right child of the new root node, and make the left child of the original root node the left child of the new root node; Right-left or left-right: if the imbalance is more complicated, first do one rotation, then the other; S523, updating node information: after the rotation operation, updating the parent-child relationship, height and other information of the relevant nodes; S53, recursively check and rotate subtrees: S531, recursive check: for the new unbalanced subtree generated after the rotation, recursively execute steps S51 and S52 until the entire binary tree is balanced again; S532, stop condition: when the entire binary tree is traversed and no unbalanced nodes are found, the optimization operation is stopped; S54. Verify optimization results: S541, traverse and check again: after the optimization operation is completed, traverse the binary tree again to check whether all nodes meet the properties of a balanced binary tree; S542. Record log: record detailed information and results of optimization operations for subsequent analysis and debugging.
Citation Information
Patent Citations
Directory tree-based information acquisition method and device
CN110619066A