Abstract


  • Nodes have value attached to it
  • If the left sub-tree isn’t empty, all nodes on that sub-tree is smaller than the node value
  • If the right sub-tree isn’t empty, all nodes on that sub-tree is bigger than the node value
  • Its left sub-tree and right sub-tree are also binary search tree (二叉搜索树)

Tips in solving Leetcode Question


Handling relationship between the current node & its previous node

  • Use prevNode to keep track of the previous smaller node or its parent node
  • Handy in solving some problems

Traverse nodes from smallest to biggest

Traverse node from biggest to smallest

Locate a node in log(n) time

  • Select the node.left when target value is smaller than the current node
  • Select the node.right when target value is bigger than the current node
  • This allows us to choose only one side of the Binary Search Tree (二叉搜索树) at each Level

Insert a new node in log(n) time

Leetcode Question


Properties

Modification & Structure

Common Ancestor

Terminologies


Greater Tree

  • Every value of node of the original BST is changed to the original value of node plus the sum of all value of nodes greater than the value of the original node of in BST