07 2017 档案
摘要:题目原文详见http://coursera.cs.princeton.edu/algs4/assignments/collinear.html 程序的主要目的是寻找n个points中的line segment,line segment的要求就是包含不少于4个点。 作业包含三部分程序实现: 一、Poi
阅读全文
摘要:题目原文: Nuts and bolts. A disorganized carpenter has a mixed pile of n nuts and n bolts. The goal is to find the corresponding pairs of nuts and bolts.
阅读全文
摘要:快速排序也是一种分治算法。主要思想是选取一个切分点,将大于切分点的元素都放置到数组右侧,小于切分点的元素都放置到数组左侧;然后递归,再对切分点左侧和右侧分别排序。 归并排序时递归在前,归并在后,快速排序是切分在前,排序在后。 快速排序的运行时间在1.39nlogn的某个常数因子范围之内,归并排序也能
阅读全文
摘要:归并排序有两种实现方式,自顶向下和自底向上。前者的思想是分治法,现将数组逐级二分再二分,分到最小的两个元素后,逐级往上归并,故其核心在于归并。后者的思想相反,采用循环的方式将小问题不断的壮大,最后变成整个大问题。 归并需要有一个同等大小的辅助数组aux,现将需要归并的元素copy至辅助数组aux中,
阅读全文
摘要:希尔排序是对插入排序的优化,将插入排序的交换步长由1增加到h。 希尔排序的思想是使数组中任意间隔为h的元素有序。步长调幅为h = 3*h + 1, 也就是1,4,13,40,121,364, 1003....这种步长算法是经过论文证明为比较高效的步长。 最开始由最大步长开始排序,最大步长为 whil
阅读全文
摘要:插入排序的基本思想就是遍历一边列表,将a[i]依次通过a[i-1]、a[i-2]、a[i-3]...依次比较并交换位置的方式插入合适的位置。 for: i from 0~n-1{ for: j from i~0 if(a[j] <= a[j-1]) 交换a[j]和a[j-1] break; }
阅读全文
摘要:选择排序核心思想是通过每一次遍历选择最小元素: for: i from 0~n-1 { for j from i+1~n-1 选出最小元素a[min] 将选出的最小元素a[min]与a[i]交换位置 }
阅读全文
摘要:题目原文: Shuffling a linked list. Given a singly-linked list containing n items, rearrange the items uniformly at random. Your algorithm should consume a
阅读全文
摘要:在做Coursera上的Algorithms第三周测验练习的时候有一道链表随机排序问题,刚开始没有什么思路,就想着先把单向链表归并排序实现了,再此基础上进行随机排序的改造。于是就结合归并排序算法,实现了单向链表的归并排序。
阅读全文
摘要:题目原文: An inversion in an array a[] is a pair of entries a[i] and a[j] such that i<j but a[i]>a[j]. Given an array, design a linearithmic algorithm to
阅读全文
摘要:题目原文: Stack with max. Create a data structure that efficiently supports the stack operations (push and pop) and also a return-the-maximum operation. A
阅读全文
摘要:题目原文: Suppose that the subarray a[0] to a[n-1] is sorted and the subarray a[n] to a[2*n-1] is sorted. How can you merge the two subarrays so that a[0]
阅读全文
摘要:题目原文: Implement a queue with two stacks so that each queue operations takes a constant amortized number of stack operations. 题目要求用栈实现队列的所有操作。
阅读全文
摘要:题目原文: Given two integer arrays of size n , design a subquadratic algorithm to determine whether one is a permutation of the other. That is, do they co
阅读全文
摘要:题目原文: Given two arrays a[] and b[], each containing n distinct 2D points in the plane, design a subquadratic algorithm to count the number of points t
阅读全文
摘要:第二周课程的Elementray Sorts部分练习测验Interview Questions的第3题荷兰国旗问题很有意思。题目的原文描述如下: Dutch national flag. Given an array of n buckets, each containing a red, whit
阅读全文
摘要:题目原文: Suppose that you have an n-story building (with floors 1 through n) and plenty of eggs. An egg breaks if it is dropped from floor T or higher an
阅读全文
摘要:题目要求: Design an algorithm for the 3-SUM problem that takes time proportional to n2 in the worst case. You may assume that you can sort the n integers
阅读全文
摘要:作业原文:http://coursera.cs.princeton.edu/algs4/assignments/queues.html 这次作业与第一周作业相比,稍微简单一些。有三个编程练习:双端队列(Deque)设计、随机队列(Randomized Queue)设计,还有一个排列组合类Permut
阅读全文
摘要:题目原文: Given a set of n integers S = {0,1,…,N-1}and a sequence of requests of the following form: Remove x from S Find the successor of x: the smallest
阅读全文
摘要:题目原文: Add a method find() to the union-find data type so that find(i) returns the largest element in the connected component containing i. The operati
阅读全文
摘要:题目原文描述: Given a social network containing. n members and a log file containing m timestamps at which times pairs of members formed friendships, design
阅读全文
摘要:题目来源http://coursera.cs.princeton.edu/algs4/assignments/percolation.html 作业分为两部分:建立模型和仿真实验。 最关键的部分就是建立模型对象。模型对象要求如下: The model. We model a percolation
阅读全文

浙公网安备 33010602011771号