One Pager Cheat Sheet
- A
binary treeis a recursive structure composed of oneNodewith akeyvalue and up to two childNodesthat can be traversed with arootpointer. - A
BSTis a special type of binary tree where the key values are placed according to a defined rule; nodes in the left subtree have keys less than the parent, and keys in the right subtree have keys greater than the parent. - Every node in a binary search tree
at most has two childrenand duplicatescanbe added, but must be placed in the same subtree. - A balanced BST is a
Binary Search Treein which the left and right subtrees differ in height by no more than1. - A
binary treecan berebalancedto become a balanced BST, thereby ensuring that all subtrees of a given node will differ in height by no more than one (1). - Create a balanced BST tree from a
sorted arraybased on thein-order traversalof the unbalanced tree for efficient balancing. - We are creating an array from BST in-order traversal using a
vectorand also recursively creating a balanced BST usingbuildmethod with the middle array element being the root node. - We are building a balanced binary tree from
arraysof different lengths to view the pseudo code in action. - We can start balancing our
BSTbycodingthebuildfunction, with0andn-1as its starting and ending parameters, respectively. - Before trying out the code, it is best to conduct a dry run to get an idea of the time and memory complexities (which are
O(N)) of theinorder traversalalgorithm. - It is
possibleto convert an array into a balanced Binary Search Tree (BST) usinginorder traversalto divide the array and create a root node and subtrees that differ in height by one. - It is not possible to convert a BST to a balanced BST without using
recursion, as there is no algorithm known to have a better time complexity than O(n log n).

