Trees

Types of Binary Trees

https://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees

A full binary tree is a tree in which every node has either 0 or 2 children.

In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible.

A balanced binary tree is a binary tree structure in which the left and right subtrees of every node differ in height by no more than 1.

A perfect binary tree is a tree with all leaves are at the same level, and every parent has two children.

Binary Tree Node

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */

Binary Tree Traversal

Iterative, Non-recursive Implementation with Stack

Pre-Order Traversal

*Another Iterative Pre-Order Traversal

In-Order Traversal

*Another Iterative In-Order Traversal

Post-Order Traversal

*Another Iterative Post-Order Traversal

Recursive Implementation

Pre-Order Traversal

In-Order Traversal

Post-Order Traversal

Level Order Traversal

BFS

DFS

Maximum Depth of Binary Tree

Recursive

Symmetric Tree

https://leetcode.com/articles/symmetric-tree/

Recursive

Iterative

Binary Search Tree (BST)

Last updated

Was this helpful?