
算法与数据结构
文章平均质量分 64
all-is-well
这个作者很懒,什么都没留下…
展开
-
随机化快速排序算法
转载出处:http://www.cppblog.com/liyuxia713/archive/2010/01/24/106332.htmlQuicksort是一个很好的排序算法,但是其最坏情况运行时间是O(n^2), 还不如Mergesort的O(nlgn),如何改进Quicksort? 引进随机化思想一种方法: 对给定的待排序序列,随机地重排列另一种方法:随机选取转载 2013-08-06 19:56:28 · 1138 阅读 · 0 评论 -
MIT算法导论6(顺序统计、中值)
在一个无序数组中,想得到Kth小的元素。首先大家想到的一定是先排序,然后再输出A[k]; 那么不使用排序,还有什么解决办法呢?下面介绍一种算法,随机选择算法 Rand-Select(int A[], int p, int q, int i ),表示在数组A中[p, q]区间上寻找第i小的元素,这种算法会用到随机分割方法(在随机化快速排序算法中有介绍)。伪代码如下:if(p=q) then原创 2013-08-10 20:44:18 · 898 阅读 · 0 评论 -
MIT算法导论5——线性时间排序
常见的排序算法,像归并排序,堆排序时间复杂度为O(nlgn);像冒泡排序,插入排序则为O(n^2)。对于排序算法而言,只要你是通过比较,O(nlgn)是一条难以逾越的界限。为了追求更快的速度,智慧的人类发明了一种新的方法——计算排序(Counting sorts),在这种算法中没有比较运算,下面简单的介绍一下。 对于这个算法,有个比较重要的约束条件——排列的数据必须在特定的范围,原创 2013-08-11 11:23:26 · 811 阅读 · 0 评论 -
Leetcode - 4. Median of Two Sorted Arrays
4. Median of Two Sorted Arrays题目简介 There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log原创 2016-05-06 19:42:20 · 581 阅读 · 0 评论 -
Leetcode - 5. Longest Palindromic Substring
题目 Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.Simple solution(超时)思路原创 2016-05-06 20:40:54 · 447 阅读 · 0 评论 -
Leetcode - 38. Count and Say
38. Count and Say题目简介 The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, … 1 is read off as “one 1” or 11. 11 is read off as “two 1s”原创 2016-05-06 22:14:18 · 1218 阅读 · 0 评论