题目:输入n个整数,找出其中最小的k个数。
《剑指offer》给出了两种实现算法:
算法1:采用Partition加递归法,该算法可以说是快速排序和二分查找的有机结合。算法的时间复杂度为O(n),缺点在于在修改Partition的过程中会修改原数组的值。
算法2:采用top-k算法。如果要找最小的K个数,我们才用一个含有K个值的大顶堆;如果要找最大的K个数,我们采用小顶堆。该算法的时间复杂度为O(nlogK),是一种比较好的算法,启发于堆排序。...
分类:
其他好文 时间:
2014-08-06 23:04:12
阅读次数:
333
冒泡排序:1 def bubble(l):2 length = len(l)3 for i in range(length):4 for j in range(i+1, length):5 if l[i] > l[j]:6 ...
分类:
编程语言 时间:
2014-08-06 22:23:07
阅读次数:
223
原文地址:http://infiniteloop.in/blog/quick-python-performance-optimization-part-i/
往往小的改变却能带来大的性能提升,
下面说下python中的几点性能优化。
1.使用timeit模块
2.减少函数的调用次数
3.使用xrange代替range
4.''.join()代替+,+=
5.while 1 代替 wh...
分类:
编程语言 时间:
2014-08-06 19:28:32
阅读次数:
247
select a.bs_sn, a.bs_bd_no, a.bs_bk_code, a.bs_kind_no, a.bs_flag, b.det_flag, c.bp_in_no, c.b...
分类:
数据库 时间:
2014-08-06 18:49:01
阅读次数:
1067
关于SQL的partition by 字段的一些用法心得先看例子:if object_id('TESTDB') is not null drop table TESTDBcreate table TESTDB(A varchar(8), B varchar(8))insert into TESTDB...
分类:
数据库 时间:
2014-08-06 14:33:11
阅读次数:
346
1:编写一个程序,确定分别由signed ,unsigned 限定的char short long int的取值范围。采用打印标准头文件中的相应值以及直接计算两种方式实现。头文件的实现方式:#include #include /*determin range of int types*/int ma...
分类:
其他好文 时间:
2014-08-06 14:14:51
阅读次数:
229
一开始我采用的方法如下: ### Stop osd
$ service ceph stop osd.0
### Flush Journal
$ ceph-osd --flush-journal -i 0
### Create symlink to partition
$ rm /var/lib/ceph/osd/ceph-0/journal
$ ln -s /de...
分类:
其他好文 时间:
2014-08-06 12:04:21
阅读次数:
424
We hold expertise in manufacturing a wide range of Industrial machines Sand Making Machine that find application in various purposes. Manufactured as ...
分类:
其他好文 时间:
2014-08-06 11:42:11
阅读次数:
271
Go编程基础
Go的内置关键字(25个)
不多
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continute for import return var
Go的注释方...
分类:
其他好文 时间:
2014-08-06 01:56:50
阅读次数:
313
1. hoare划分 1 int hoare_partition(int a[], int begin, int end) 2 { 3 int pivot = a[begin]; 4 int ini = begin; 5 int ter = end; 6 ...
分类:
其他好文 时间:
2014-08-06 01:51:00
阅读次数:
213