Is there a tree traversal algorithm with fixed memory?

I have the first tree node. Something like that:

class TreeNode {
   int uniqueValue;
   List<TreeNode> children;
}

I want to find the most memory efficient way to print all the nodes of a tree. A tree can be large or VERY BIG. It can be deep or wide. I know recursion and glass algorithms. I want to find an algorithm that uses a fixed amount of memory regardless of the size of the graph.

The tree is not binary!

+4
source share
2 answers

O (1). O (N). "", node. , , ( BFS DFS).

+2

, , , O (log (N)).

, , , O (log (N)).

(1e85, ), , - 85 3.3 = 281 = 35 . , .

0

All Articles