# Tree Traversal

<figure><img src="/files/a0T9ncyJgbPgCi6TaXxh" alt=""><figcaption></figcaption></figure>

## Depth First Search

{% hint style="info" %}
&#x20;DFS will only store as much memory on the stack as is required for the longest root to leaf path in the tree. In other words, it space usage is  $$\text{O}(h)$$ where  $$h$$ is the height of the tree.&#x20;
{% endhint %}

## Breadth First Search


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://private-26.gitbook.io/notes/algorithmic-pattern/graph/tree-traversal.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
