二叉树相关题目总结

1. 简要介绍 
   关于二叉树问题,由于其本身固有的递归属性,通常我们可以用递归算法来解决。(《编程之美》,P253)
  总结的题目主要以leetcode题目、《剑指offer》以及《编程之美》的题目。

2. 测试用例

  普通二叉树(完全二叉树,不完全二叉树)

  特殊二叉树(所有节点都没有右子节点的二叉树,所有节点都没有左子节点的二叉树,只有一个节点的二叉树)

  特殊输入测试(二叉树的根节点指针为NULL)

3. 编写程序前要思考的问题

  二叉树相关的代码有大量的指针操作,每一次使用指针的时候,我们都要问自己这个指针有没有可能是NULL,如果是NULL该怎么处理。(《剑指offer》P120)

4. 二叉树的遍历

  前序遍历:[LeetCode] Binary Tree Preorder Traversal

  中序遍历:[LeetCode] Binary Tree Inorder Traversal

  后序遍历:[LeetCode] Binary Tree Postorder Traversal

  层次遍历:从上往下打印二叉树

  分层遍历简介:二叉树分层遍历

  分层遍历题目(《剑指offer》,面试题60):1. [LeetCode] Binary Tree Level Order Traversal I

                        2. [LeetCode] Binary Tree Level Order Traversal II

  之子形遍历(《剑指offer》,面试题61):[LeetCode] Binary Tree Zigzag Level Order Traversal

5.二叉树重建

  可以重建唯一一棵二叉树的组合:前序遍历+中序遍历,中序遍历+后序遍历,层次遍历+中序遍历。

  如果只知道二叉树的先序序列和后序序列,是无法唯一确定一棵二叉树的。

  前序序列和中序序列重建二叉树(《剑指offer》,面试题6):[LeetCode] Construct Binary Tree from Preorder and Inorder Traversal

  中序遍历和后序遍历重建二叉树:[LeetCode] Construct Binary Tree from Inorder and Postorder Traversal

6.二叉树的路径
  二叉树从根到叶的所有路径:[LeetCode] Binary Tree Paths
  二叉树的最大路径和:[LeetCode] Binary Tree Maximum Path Sum

  路径和(一): [LeetCode]  PathSum

  路径和(二)(《剑指offer》面试题25): [LeetCode]  PathSum II

7.二叉树的深度

  二叉树的最小深度:[LeetCode] Minimum Depth of Binary Tree

  二叉树的最大深度:[LeetCode] Maximum Depth of Binary Tree

  

8. 二叉搜索树

  二叉搜索树: 二叉搜索树       平衡树以及AVL: 平衡树以及AVL树

  判断一棵树是不是二叉搜索树(《王道程序员求职宝典》,P226): [LeetCode] Validate Binary Search Tree

  有序数组转换到二叉搜索树:[LeetCode] Convert Sorted Array to Binary Search Tree

  有序链表转换到二叉搜索树:[LeetCode] Convert Sorted List to Binary Search Tree

  二叉搜索树转换成双向链表:二叉树搜索树转换成双向链表

     二叉搜索树的第k个节点:[LeetCode] Kth Smallest Element in a BST

  二叉搜索树中两个节点的最低公共祖先:[LeetCode] Lowest Common Ancestor of a Binary Search Tree

  恢复错误的二叉搜索树:[LeetCode] Recover Binary Search Tree

  

9. 相似二叉树的问题

  判断两棵二叉树是否相同(《wd》,P220):[LeetCode] Same Tree

  对称的二叉树(《剑指offer》,面试题59):[LeetCode] Symmetric Tree

  二叉树的镜像(《剑指offer》,面试题19):[LeetCode] Invert Binary Tree

  二叉树的子结构:二叉树的子结构

  

10.其他

  求二叉树中节点的最大距离: 二叉树中节点的最大距离

  判断是不是平衡二叉树:[LeetCode] Balanced Binary Tree

  二叉树中两个节点的最低公共祖先:[LeetCode] Lowest Common Ancestor of a Binary Tree

  二叉树的下一个节点:二叉树的下一个节点

  

  

  

原文地址:https://www.cnblogs.com/vincently/p/4240255.html