码迷,mamicode.com
首页 > 其他好文 > 详细

Tree总结

时间:2018-12-01 18:40:43      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:时间复杂度   mini   imu   nim   因此   总结   树结构   插入   面试题   

树结构问题因为容易写出解法,因此经常出现在面试题中

1. 树的种类

  1) Tree

  2) Binary Trees 

  3) Binary Search Trees(BST) : used to sorted or ordered data.  //解决方案:recursion

   查找操作(fast and simple):O(logn)

   插入和删除:O(logn)

      打印:O(n)

  4) Heap: find the maximum value / minimum value(min-heap) in constant time.

     插入和删除:O(logn)

     查找:O(n) ,因为除了顶点,左右子书是无序的

2. 通常的查询方法

注意:如果查找的树结构是无序的,时间复杂度是O(n),所以复杂的树要避免使用普通的树结构

  1)BFS :空间开销大

  2)  DFS

3. Traversals

当需要遍历树中的每个点时使用的方法,遍历方法有很多。     // recursive

最寻常的Depth-first-traversals for binary tree的种类

  1) Pre-order : a node is always visited before any its children, then left first

  2) In-order : The left subtree is visited first, then the node itself, and then the nodes‘s right subtree.

  3) Post-order: left, right, node. A node is always visited after all its children.

 

Tree总结

标签:时间复杂度   mini   imu   nim   因此   总结   树结构   插入   面试题   

原文地址:https://www.cnblogs.com/GW977/p/10049995.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!