Skip to content

Files

Latest commit

19ee2eb · Jul 30, 2022

History

History

8_tree_depth_first_search

Introduction

This pattern is based on the Depth First Search (DFS) technique to traverse a tree.

We will be using recursion (or we can also use a stack for the iterative approach) to keep track of all the previous (parent) nodes while traversing. This also means that the space complexity of the algorithm will be O(H), where ‘H’ is the maximum height of the tree.