0. Traversal

public class Node {
	
	int data;
	Node left;
	Node right;
	
	public Node (int data) {
		this.data = data;
	}
}

What is Auxilary Space ?

The extra memory used by an algorithm excluding the input and the required output.

Example: The Traversal in Binary Trees cost O(h) Auxilary space, where h is the tree height.
Note: For BFS it is O(w), where w is the width of the tree.

Question:

Why isn't the answer vector counted as auxiliary space?

Good answer:

Because the problem requires us to return it. Every correct solution must allocate space for the output, so it isn't considered extra working memory. Auxiliary space measures only the additional memory the algorithm uses beyond the input and the required output.

Powered by Forestry.md