Tuesday, June 9, 2015

Binary tree algorithms

May 28, 2015
To expand my knowledge, challenge my understand of binary tree, read through over 1000 lines Java code, and then, memorize all the algorithms. 非常幸运, 可以阅读这上千行的代码, 理解, 并记忆这些二插树的算法. 花几个小时, 读一读; 思考思考, 对不常写算法的我, 是一个崭新的开始.
最喜欢, 也是第一次阅读, 理解的算法:
  1. 递归转换BST为双向链表(DLL)
  2. 分层遍历二叉树(递归)
  3.  后序遍历迭代解法
  4. 求二叉树的深度(高度) 迭代解法: O(n)  ( 基本思想同LevelOrderTraversal,还是用一个Queue )
  5. 将二叉查找树变为有序的双向链表 迭代解法 ( 类似inorder traversal的做法  )

No comments:

Post a Comment