关于碰到的一次二叉树的优化
关于碰到的一次二叉树的优化……
关于碰到的一次二叉树的优化……
转载自ICS161,学英语,自娱自乐
To traverse(遍历) means to visit the vertices in some systematic order. You should be familiar with various traversal methods for trees:
preorder: visit each node before its children.
postorder: visit each node after its children.
inorder (for binary trees only): visit left subtree, node, right subtree.
We also saw another kind of traversal, topological ordering(拓扑排序), when I talked about shortest paths.
Today, we'll see two other traversals: breadth first search (BFS) and depth first search (DFS). Both of these construct spanning trees with certain properties useful in other graph algorithms. We'll start by describing them in undirected graphs, but they are both also very useful for directed graphs.
这两天看了廖雪峰老师的 Git 教程,受益匪浅。
以下为常用基本命令总结:
git init
git add <file>
,git commit -m "messages"
git status
git diff
git log
git reset --hard commit_id
git relog
git check -- file
git reset HEAD file
git rm
git remote add origin git@server:path/repo.git
git push -u origin master
git push origin master
git clone ssh://user@domain.com/repo.git
git branch
git branch <name>
git checkout <name>
git checkout -b <name>
git merge <name>
git branch -d <name>
git tag <name>
默认为HEADgit tag -a <tagname> -m "balabala……"
git tag
git push origin --tags
git tag -d <tagname>
git push origin :refs/tags/<tagname>
哈夫曼树是带权路径长度 WPL(Weighted Path Length)最小的二叉树,也称为最优二叉树。
如下图:
它们的带权路径长度分别为:
图a: WPL = 5*2 + 7*2 + 2*2 + 13*2 = 54
图b: WPL = 5*3 + 2*3 + 7*2 + 13*1 = 48
可见,图b的带权路径长度较小,我们可以证明图b就是哈夫曼树(也称为最优二叉树)