heap
-------------------------------------------------------------------------
binary heap 是一种完全二叉树。
隐式表示法:以 array 表述 tree。
小技巧:将 array 的 #0 元素保留,则第 i 个元素的左右子节点分别是 2i 和 2i + 1,
父节点是i/2 --> STL 里没有采用这种小技巧
将 array 无法动态改变大小,所以用 vector 替代 array
这个文件里提供了各种堆操作的...
分类:
其他好文 时间:
2014-07-22 00:32:34
阅读次数:
256
复制解决的问题是保持多个服务器之间的数据的一致性,就如同通过复制保持两个文件的一致性一样,只不过MySQL的复制要相对要复杂一些,其基本过程如下: 1)在主库上将数据更改记录到二进制日志(Binary Log)中(这些记录被成为二进制日志事件,即binlog) 2)本分将主库上的日志复制到自...
分类:
数据库 时间:
2014-07-21 11:23:00
阅读次数:
300
Another recursion problem.class Solution {public: int getHeight(TreeNode *p) { if (!p) return 0; int hL = 1; if (p->left) h...
分类:
其他好文 时间:
2014-07-21 11:10:03
阅读次数:
180
using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Runtime.Serialization.Formatters.Binary;using System.Text...
分类:
其他好文 时间:
2014-07-21 08:03:51
阅读次数:
197
用grep来搜代码和方便,最原生态了,常用的: ??~?grep?‘NuPlayer‘?-iInr?--color?./aosp 其中`i`表示大小写忽略;`I`表示忽略binary文件;`n`显示搜索结果的行号;`r`表示递归搜索子目录 不过grep搜索有点...
分类:
其他好文 时间:
2014-07-20 23:30:42
阅读次数:
446
关于二叉树的遍历有很多的方法, 下面介绍两个经典的遍历算法: BFS和DFS。一个是深度优先遍历, 一个是广度有优先遍历。 这两种遍历算法均属于盲目的遍历算法, 一般而言, 启发式的遍历搜索算法比较好一些。 。 关于各种遍历算法的对比, 将会在后面逐一提及。 这里不在赘述。
由于树是一个非线性的数据结构, 显然不能像linked list , 或者Array那样通过从头像最末尾移动去实现遍历每一...
分类:
编程语言 时间:
2014-07-20 23:14:21
阅读次数:
387
这里讲讲对binary Tree 进行level order Traversal.。 即BF traversal(广度优先遍历)。即首先, 访问根节点F, 打印出数据。 接着访问level 1的所有节点, 即D, J。 访问完level1之后, 访问level2, 即B, E, G , K 等等一次访问下去, 直至遍历完所有的节点。
BFS遍历的思路很简单, 但是当我们编程实现的时候,...
分类:
编程语言 时间:
2014-07-20 23:11:21
阅读次数:
344
如下图:
这里我们实现DFS中的三种遍历方法。
相关的如下:
相关算法的介绍不再赘述。
首先对于preorder traversal 的步骤为:
其他两种算法略。
具体递归调用分析, 注意学会画stack frame的图分析。 这里不再赘述。
代码如下:
/* Binary Tree Traversal - Preorder, Inorder, Postor...
分类:
编程语言 时间:
2014-07-20 23:05:10
阅读次数:
365
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).
For example:
Given binary...
分类:
其他好文 时间:
2014-07-20 22:41:23
阅读次数:
303
Given two binary trees, write a function to check if they are equal or not.
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
比较两个...
分类:
编程语言 时间:
2014-07-20 22:12:03
阅读次数:
273