KNOW: Tree, Trie, Graph

本文详细介绍了二叉树与前缀树的基本概念、实现方式及应用场景,并对比了二叉树与二叉搜索树的区别。此外还概述了几种常见的树遍历方法,包括前序、中序、后序及层次遍历。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.youkuaiyun.com/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.youkuaiyun.com/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.youkuaiyun.com/b_end_an/article/details/10012155

Graph

Graph Definition: http://blog.youkuaiyun.com/b_end_an/article/details/8943169

Graph representation

1. adjacency matrix

2. adjacency list


统计下文中单词出现的个数存入字典,统计出现字数最多的三个单词和最少三个单词。删除原文中出现次数第二多的单词,其他单词保持顺序不变,先试试删除单词后的文章。 Sports help everyone to keep healthy, happy, and efficient. So 1 pay special attention to games,especially table-tennis. Table tennis is my favorite game. I play it almost every day Table-tennis is an ideal game for us because it brings the whole body into action. It strengthens our muscles, expands our lungs, promotes the circulation of the blood, and causes a healthy action of the skin. Besides, it is very amusing and does not cost us much money. Table-tennis is very moderate; it is not so rough as football. It is an indoor game and can be played even on rainy days. Thus, it is my favorite kind of exercise. One morning a fox sees a cock.He think,"This is my breakfast. He comes up to the cock and says,"I know you can sing very well.Can you sing for me? The cock is glad.He closes his eyes and begins to sing.The fox sees that and catches him in his mouth and carries him away. The people in the field see the fox.They cry,"Look, look!The fox is carrying the cock away. The cock says to the fox,"Mr Fox,do you understand?The people say you are carrying their cock away.Tell them it is yours.Not theirs. The fox opens his mouth and says,"The cock is mine, not yours.Just then the cock runs away from the fox and flies into the tree.多加注释,要流程图
最新发布
06-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值