关于碰到的一次二叉树的优化
关于碰到的一次二叉树的优化……
关于碰到的一次二叉树的优化……
转载自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 initgit add <file>,git commit -m "messages"git statusgit diffgit loggit reset --hard commit_idgit reloggit check -- filegit reset HEAD filegit rmgit remote add origin git@server:path/repo.gitgit push -u origin mastergit push origin mastergit clone ssh://user@domain.com/repo.gitgit branchgit 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 taggit push origin --tagsgit 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就是哈夫曼树(也称为最优二叉树)