KNOW: Tree, Trie, Graph

Binary Tree

A binary tree is a tree in which no node can have more than two children.

The depth of an average binary tree is considerably smaller than N.

For binary search tree, the average depth is O(logN)

Difference between BT and BST:http://stackoverflow.com/questions/6380231/difference-between-binary-tree-and-binary-search-tree

Binary Tree Implementation

http://blog.csdn.net/b_end_an/article/details/9975943

Binary Search Tree

For BST questions, we need to clarify if we allow duplicate!

http://stackoverflow.com/questions/300935/definition-of-a-binary-search-tree

Tree Traversal

http://en.wikipedia.org/wiki/Tree_traversal#Depth-first

Different way to implement tree traversal:  http://blog.csdn.net/kofsky/article/details/2886453

Iterative post-order traverse tree: http://leetcode.com/2010/10/binary-tree-post-order-traversal.html

Pre-order:

  1. Visit the root.
  2. Traverse the left subtree.
  3. Traverse the right subtree.

In-order (symmetric):

  1. Traverse the left subtree.
  2. Visit the root.
  3. Traverse the right subtree.

Post-order:

  1. Traverse the left subtree.
  2. Traverse the right subtree.
  3. Visit the root.

Level-order:

  1. Traverse each node on a level
  2. Go to the next level

Trie

http://en.wikipedia.org/wiki/Trie

In computer science, a trie, also called digital tree or sometimes radix tree or prefix tree (because we can search by prefixes), is anordered tree data structure that is used to store a dynamic set or associative array where the keys are usually strings. Unlike a binary search tree, no node in the tree stores the key associated with that node; instead, its position in the tree defines the key with which it is associated. All the descendants of a node have a common prefix of the string associated with that node, and the root is associated with the empty string. Values are normally not associated with every node, only with leaves and some inner nodes that correspond to keys of interest.

Each node can have 0 ~ 26 children.

Trie Implementation

http://blog.csdn.net/b_end_an/article/details/10012155

Graph

Graph Definition: http://blog.csdn.net/b_end_an/article/details/8943169

Graph representation

1. adjacency matrix

2. adjacency list


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值