nkcoder007.wordpress.com
Steve Jobs Says | Coding->Expressing->Improving
https://nkcoder007.wordpress.com/2011/10/07/steve-jobs-says
October 7, 2011. Come from: Steve Jobs says. 1 Steve Jobs said: Innovation distinguishes between a leader and a follower. 2 Steve Jobs said: Be a yardstick of quality. Some people aren’t used to an environment where excellence is expected. 3 Steve Jobs said: The only way to do great work is to love what you do. If you haven’t found it yet, keep looking. Don’t settle. As with all matters of the heart, you’ll know when you find it. If the answer is ‘no’ keep looking, you’ll know when you find it. 6 Steve J...
nkcoder007.wordpress.com
nkcoder | Coding->Expressing->Improving
https://nkcoder007.wordpress.com/author/nkcoder007
October 7, 2011. Come from: Steve Jobs says. 1 Steve Jobs said: Innovation distinguishes between a leader and a follower. 2 Steve Jobs said: Be a yardstick of quality. Some people aren’t used to an environment where excellence is expected. 3 Steve Jobs said: The only way to do great work is to love what you do. If you haven’t found it yet, keep looking. Don’t settle. As with all matters of the heart, you’ll know when you find it. If the answer is ‘no’ keep looking, you’ll know when you find it. 6 Steve J...
nkcoder007.wordpress.com
Elementary Data Structures | Coding->Expressing->Improving
https://nkcoder007.wordpress.com/2011/09/13/elementary-data-structures
September 13, 2011. 栈 后进先出 数组s[1…n],操作top[s]返回最近插入的元素的索引,栈包含的元素为 s[1…top[s] . tops[s] 为0表示栈空。 入栈叫push(s, x); 出栈叫pop(). 队列 先进先出 入队叫enqueue(q, x); 出队叫dequeue(). 操作head[q]指向头元素,操作tail[q]指向尾元素的下一个元素。 循环队列 当队列为空时 head[q]= tail[q]; 当队列满时 head[q]= tail[q] 1;. List-Search(L, k) x - next[nil[L] while x! K do x - next[x] return x List-Delete(L, x) next[prev[x] - next[x] prev[next[x] - prev[x] List-Insert(L, x) next[x] - next[nil[L] prev[next[nil[L] ] - x next[nil[L] - x prev[x] - nil[L]. Leave a Reply Cancel reply.
nkcoder007.wordpress.com
C语言的两个隐蔽的bug | Coding->Expressing->Improving
https://nkcoder007.wordpress.com/2011/09/03/c语言的两个隐蔽的问题
September 3, 2011. 分析1 、2 两段代码,编译后都没有问题,但…. Ifdef WIN32 # define tmpfile w32 tmpfile #endif FILE * w32 tmpfile ( void ) { code for Windows; } else if (code = 200) { / Downloading whole file /* Write new file (plus allow reading once we finish) */ / FIXME Win32 native version fails here because / Microsoft's version of tmpfile() creates the file in C: / g = fname? Fopen(fname, w ) : tmpfile(); if(NULL! Fname) { g = fopen(fname, w ); } else { g = tmpfile(); } }. Fopen(fname, w ) : tmpfile();.
nkcoder007.wordpress.com
Medians and Order Statistics | Coding->Expressing->Improving
https://nkcoder007.wordpress.com/2011/09/13/medians-and-order-statistics
Medians and Order Statistics. Medians and Order Statistics. September 13, 2011. 1 ith order statistic (顺序统计 即n个元素中第i小的元素。 Median 中值 当n是奇数时,中值为(n 1)/2; 当n为偶数是,中值有两个,即(n 1)/2分别向上取整和向下取整的结果。 2 如果同时找出数组的最大值及最小值呢 分别遍历一遍,比较次数为2(n-1),这是最优的吗 不是. 算法分析 当n是奇数时,将数组的第一个元素设置为当前的最大值和最小值,此时的比较次数为3n/2(向下取整 ;当n是偶数时,先将数组的前两个数作比较,较大者为当前最大值,较小者为当前最小值,此时比较的次数为(1 3(n-2)/2=3n/2)次。 分析 选择哨兵值q后,小于等于q的元素个数为k,如果k等于i,则A[q]即为第i小的元素 如果k大于i,则说明第i小的元素在左边,递归操作左边 如果k小于i,则第i小的元素在右边,递归操作右半部分,此时,因为已经有k个值小于i,所以要求的只是第(i-k)小的元素。 Goolge : Ling Guo.
nkcoder007.wordpress.com
Bucket Sort | Coding->Expressing->Improving
https://nkcoder007.wordpress.com/2011/09/05/bucket-sort
September 5, 2011. BucketSort: 桶排序的基本思想是 将[0,1)区间分成n个大小相同的子区间,也叫桶。 输入 A[0, … ,n-1]. 辅助数组: B[0, … ,n-1],即表示桶,用链表实现。 BUCKET-SORT n - length[A] for i - 0 to n-1 do insert A[i] into bucket B[n*A[i] for i - 0 to n-1 do sort bucket B[i] with insertion sort concatenate the lists B[0], B[1], ., B[n-1] together in order. 一年的全国高考考生人数为500 万,分数使用标准分,最低100 ,最高900 ,没有小数,你把这500万元素的数组排个序。 分析 对500W数据排序,如果基于比较的先进排序,平均比较次数为O(5000000*log5000000) 1.112亿。 但是我们发现,这些数据都有特殊的条件 100= score =900。 题目 在一个文件中有 10G 个整数,乱序排列,要求找出中位数。
nkcoder007.wordpress.com
面试题:火车运煤问题 | Coding->Expressing->Improving
https://nkcoder007.wordpress.com/2011/09/14/面试题:火车运煤问题
September 14, 2011. 且B距A 250公里 即全程的1/4处 ,C距A 500公里处 即全程的中点。 运煤步骤如下 1. 装1000吨煤,运到B,放下500吨,还剩250吨,刚好可以返回A。 这么考虑,当煤的数量在(2000, 3000]内时,火车满载,至少需要也仅仅需要两个来回 最后一次不用返回的 将这些煤运到一个中间点 当煤的数量在(1000, 2000]范围内时,只需一个来回,可以将这些煤运到下一个中间点 最后,当煤的数量在1000以内时,直接运到目的地即可。 还是如思路1里的中间点B,C 从A到B,需要两个来回,即AB段经过了5次 最后一次只从A到B ,消耗了1000吨煤,则AB间的距离为 1000/5=200 公里。 Leave a Reply Cancel reply. Enter your comment here. Fill in your details below or click an icon to log in:. Address never made public). Notify me of new comments via email.
nkcoder007.wordpress.com
Radix Sort | Coding->Expressing->Improving
https://nkcoder007.wordpress.com/2011/09/04/radix-sort
September 4, 2011. 基数排序(radix sort): 输入数组有n个元素,每个元素由d位组成,即n-element d-digit;每一趟对元素的最后一位排序,然后对倒数第二位排序,依此类推…这样进行d趟,排序结束。 RADIX-SORT(A, d) for i - 1 to d do use a stable sort to sort array A on digit i. 1 如果元素的每一位的值不大于K,而K值不是很大,显然可以选择countingSort,此时的复杂度为O(d(n K) ,当d是常数且K=O(n),则复杂度为O(n),即线性时间。 2 如果有n元素,每个元素b位,有整数r, d=b/r,即将b位重分为d组,每d组有r位。 R位的最大值为2er-1.同样采用countingSort,此时的复杂度为O( b/r)(n 2er). 如果b=O(lgn),取r=lgn,此时复杂度为O(n). Leave a Reply Cancel reply. Enter your comment here. Address never made public).