Brendan Ang

Search

Search IconIcon to open search

Binary Tree

Last updated Nov 8, 2022 Edit Source

# Binary Trees

A tree structure in which each node has at most 2 children.

1
2
3
4
5
6
7
8
class TreeNode {
	constructor(val, left, right, parent){
		this.val = val
		this.left = left
		this.right = right
		// this.parent = parent
	}
}

# Properties of binary trees

Full binary trees (all nodes have 0 or 2 children)

Complete binary trees (like those use in Heaps)

# Array representation

Pasted image 20220712155952 For a node at index i: