Non-Recursive Hierarchical Data Traversal via User-Allocated Stack
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Traditional recursive algorithms for traversing hierarchical data structures, such as file systems, incur significant computational and memory overhead, leading to potential program crashes and performance issues when dealing with deep directory structures due to excessive call stack usage.
Innovation Solution
Implementing a non-recursive traversal method that uses a user-allocated data structure, like a stack or heap, to keep track of branch points instead of relying on the call stack, thereby eliminating the need for recursive function calls and reducing memory overhead.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Ease of operation
If recursive function calls are used to traverse hierarchical data structures, then the traversal logic is simple and elegant, but computational overhead and memory usage increase significantly
Solution Approach 1:
The patent introduces an intermediary data structure (stack or heap) to replace the call stack used in recursive algorithms. This intermediary structure manages the traversal state explicitly, eliminating the need for nested function calls while maintaining the same traversal logic. The intermediary acts as a buffer between the traversal algorithm and the hierarchical data structure, resolving the contradiction by providing iterative control flow with reduced computational overhead.
2Reliability
If recursive function calls are used to traverse deep directory structures, then complete traversal is achieved, but call stack exhaustion occurs causing program crashes
Solution Approach 1:
The patent extracts the call stack dependency from the traversal algorithm by implementing an explicit stack or heap data structure. This extraction removes the harmful factor of call stack exhaustion while preserving the traversal completeness. The explicit data structure is allocated in a different memory region that does not have the same stack size limitations, thereby eliminating the risk of program crashes due to deep directory structures.
3Ease of manufacture
If recursive algorithms are used for hierarchical data traversal, then the implementation is straightforward, but application performance deteriorates
Solution Approach 1:
The patent transforms the static recursive call structure into a dynamic iterative process with explicit state management. The traversal algorithm dynamically adjusts its execution flow by pushing and popping states in the explicit stack/heap, allowing for better performance optimization while maintaining implementation simplicity. This dynamic approach enables the algorithm to avoid the overhead of repeated function call setup and teardown that plagues recursive implementations.
Data Source
AI summary
Non-recursive traversal of hierarchical data structures is disclosed. Elements inside a hierarchical data structure are processed beginning at a first level of the hierarchical data structure. In the event that a branch point associated with a second level of the hierarchical data structure is encountered, a marker data associated with a location of the branch point within the hierarchical data structure is stored inside a user allocated data structure, and the marker stored in the user allocated data structure is used to enable elements, if any, in the second level and any remaining elements in the first level, if any, to be processed without recursion.


