Skip to content

Latest commit

 

History

History
executable file
·
12 lines (9 loc) · 683 Bytes

notes.md

File metadata and controls

executable file
·
12 lines (9 loc) · 683 Bytes

Notes

Morris Traversal (O(1) space complexity)

inorder traversal

  1. start from root node (curNode = root)
  2. if curNode->left == nullptr, then echo curNode->val and let curNode = curNode->right
  3. else if curNode->left != nullptr, find it's preNode in inorder traversal in it's left sub-tree
  • a. if preNode->right == nullptr, then let preNode->right = curNode and curNode = curNode->left
  • b. else if preNode->right == curNode, then preNode->right = nullptr(restore), echo curNode->val and let curNode = curNode->right
  1. repeat 1. and 2. until curNode == nullptr