天天看點

[Algorithms] Build a Binary Tree in JavaScript and Several Traversal Algorithms

A binary tree is a tree where each node may only have up to two children. These children are stored on the <code>left</code>and <code>right</code> properties of each node.

When traversing a binary tree, we have three common traversal algorithms: in order, pre-order, and post-order. In this lesson, we write each of these algorithms and explore their differences.

Time complexity: O(n),

Space Complexity O(h) for average cases; h = logN -- this is because we need to stack all the function calls. worse cases: O(n)

繼續閱讀