
algorithm
文章平均质量分 71
fatshaw
这个作者很懒,什么都没留下…
展开
-
longest ordered subsequence
<br />Given a sequence with many elements and find the ordered subseqence from the original sequence.<br />dp[i] means the longest length st原创 2011-05-25 17:31:00 · 1071 阅读 · 0 评论 -
dynamic programming
dynamic programming summarization:1. dynamic programming is suitable for solving optimization problem with two important ingredients: optimal substructure and overlapping sub problems.2. optimal原创 2011-07-31 12:29:58 · 817 阅读 · 0 评论 -
贪心算法
if the problem cannot be solved by greedy algorithm then we can try to use depth-first search1. beneath every greedy algorithm there is almost always a more cumbersome dynamic programming原创 2011-11-28 20:24:17 · 873 阅读 · 0 评论 -
编程珠玑总结
column 1:bitvector operation:#define BITSPERWORD 32#define SHIFT 5#define MASK 0x1F#define N 10000000int a[1 + N/BITSPERWORD];void set(int i) { a[i>>SHIFT] |= (1<<(i & MASK)); }void原创 2011-11-28 20:23:11 · 3533 阅读 · 0 评论 -
找工作准备的面试题
master method:T(n)=t(n/2)+lgn T(n)=O(lgn*lgn). n^lg1 = 0 0. the gap between case 2 and case 3. but the factor is lgn, then result is to take an extra logn.see exercise 4.4-2工作分配问题是个O(n!原创 2011-11-28 20:20:08 · 2040 阅读 · 0 评论 -
编程之美总结
1.1, cpu占用率:如果工作10ms,sleep10ms那么cpu的usage就是50%。同样如果工作个H+ sin(A)秒然后休息个H-sin(A),这样随着A从0-2pi变化(变化量为0.01或者更小),cup的usage就是个sin的图形。1.2, 当选择数据类型时可以考虑下是否使用int,char,还是几个bit就可以了。节省空间利用率。1.5, 不变量的完美应用:一个集合中少原创 2011-11-28 20:19:13 · 2266 阅读 · 0 评论 -
微软100题面试题总结
第一题:二叉树中序遍历,每个节点的前继是没有右节点的,每个节点的后继是没有左节点的。每个节点左节点指向前继,每个节点右节点指向后继组成双向链表。第六题:模拟人工算法。第9题:二叉树问题,后续遍历产生的序列特征是最后个数是根节点,然后前面的数可以分成两部分,小于根节点的和大于根节点的,从而能够分成左子树与右子树,并递归遍历左子树和右子树。//认真复习二叉树的几个遍历。每种遍历的前继后原创 2011-11-28 20:18:40 · 1892 阅读 · 0 评论 -
归并排序
今天上算法课程上面讲到的归并排序,回来写了个试试,弄了好多时间,真是费啊void merge(int * p , int * q ,int * r, int length1,int length2){ int i = 0; int j = 0; int k = 0;原创 2010-07-14 16:23:00 · 577 阅读 · 0 评论 -
划分树,线段树的一些文章
划分树(kth数)http://www.cnblogs.com/AndreMouche/archive/2011/03/04/1971291.htmlhttp://www.notonlysuccess.com/?p=142#more-142划分树类似于经典原创 2011-08-14 15:50:05 · 1517 阅读 · 0 评论 -
在VS2008中编译纯c/c++程序并由c#调用过程
1. 建立一个C#控制台工程,主要用于调试。2. 在解决方案中添加一个新的空工程(VC++的)。3. 添加一个源文件到Source Files文件夹(xxx.c or xxx.cpp)。4. 加入这行代码#include extern "C" __declsp转载 2010-07-10 10:49:00 · 1313 阅读 · 0 评论 -
大数据量,海量数据 处理方法总结
大数据量的问题是很多面试笔试中经常出现的问题,比如baidu google 腾讯 这样的一些涉及到海量数据的公司经常会问到。 下面的方法是我对海量数据的处理方法进行了一个一般性的总结,当然这些方法可能并不能完全覆盖所有的问题,但是这样的一些方法也基本可以处理绝大多数遇到的转载 2010-11-01 20:19:00 · 726 阅读 · 0 评论 -
pku 3345 problem solving report and thinking
这两天在做pku3345,是一道关于树形dp的题目,和动态的背包问题很相似,不过是对树进行dp,关键是找到dp方程。通过这道题目复习了下动态规划(dynamic programming) 动态规划一般是通过划分问题得到原问题的一系列子问题,通过求和子问题的最优解最后得到原原创 2010-12-24 21:04:00 · 704 阅读 · 0 评论 -
主元素,中位数以及快速排序问题(分治法问题)
IBM最后有道求主元素的题目,一个数组有N个元素,其中有超过N/2的元素相同,请找出这个元素。时间复杂度为O(n)方法1:如果一个元素的个数超过N/2则这个元素必然是这N个元素的中位数。则这个题目是找中位数。方法是通过快速排序变化的来的算法。代码如下:#include #i原创 2011-04-03 23:48:00 · 9956 阅读 · 0 评论 -
shuffle算法
shuffle algorithm is very useful in many program. the algorightm can reorder the elements in a set randomly. It is used in the network, data原创 2011-04-07 12:03:00 · 1349 阅读 · 0 评论 -
关于最小的k个数的讨论(top-k问题)
<br />给定一个长度为n的序列,不妨设为L1,L2,L3,….,Ln。这个序列可以是任意一种排列,可能的排列有n!种,我们要找到最小的k个数,即找到这样的k个数{ Li(1),Li(2),Li(3)…,Li(k)},并满足Li(1)<=Li(2)<=Li(3)…<=Li(k)转载 2011-04-11 14:32:00 · 1042 阅读 · 0 评论 -
Find the elements in the set that appears only once
<br />given a set and each element in the set will appear twice. so how to find the elements that only appear once.<br /> <br />1. Use a bit原创 2011-05-16 10:42:00 · 1133 阅读 · 0 评论 -
minimum weighted difference in a set
<br />1. given a set, find a value such that the sum of the difference between all the elements in the set and the value is minimum.<br />e.原创 2011-05-20 17:44:00 · 907 阅读 · 0 评论 -
Time33哈希算法
字符串哈希函数,发现几乎所有的流行的HashMap都采用了DJB Hash Function,俗称“Times33”算法。Times33的算法很简单,就是不断的乘33,见下面算法原型。hash(i) = hash(i-1) * 33 + str[i] uint32_t time33(char const *str, int len) { un转载 2016-03-18 16:53:37 · 1518 阅读 · 0 评论