[Algorithms(Princeton)] Week1 - Percolation】的更多相关文章

public class Percolation { private boolean[] openSites; private int gridN; private WeightedQuickUnionUF UF; private WeightedQuickUnionUF UFfull; public Percolation(int N) { if (N <= 0) { throw new java.lang.IllegalArgumentException( "N must be gre…
public class PercolationStats { private int N; private int T; private double[] results; public PercolationStats(int N, int T) { if (N <= 0 || T <= 0) { throw new java.lang.IllegalArgumentException( "N or T must be greater than 0"); } this.…
题目来源http://coursera.cs.princeton.edu/algs4/assignments/percolation.html 作业分为两部分:建立模型和仿真实验. 最关键的部分就是建立模型对象.模型对象要求如下: The model.  We model a percolation system using an n-by-n grid of sites. Each site is either open or blocked. A full site is an open s…
题目原文: 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 y in S such thaty>=x design a data type so that all operations(except construction) take logarithmi…
题目原文: 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 operations, union(), connected(), and find() should all take logarithmic time or better. import edu.princet…
题目原文描述: Given a social network containing. n members and a log file containing m timestamps at which times pairs of members formed friendships, design an algorithm to determine the earliest time at which all members are connected (i.e., every member…
这周编程作业是实现检测点共线的算法.和排序算法有关系的地方在于,对斜率排序后可以很快的检测出来哪些点是共线的,另外这个算法的瓶颈也在于排序的性能. 一点收获: java传参数时传递的是值,这很多人都知道,只不过特别要注意的是对于引用类型,传递的是"引用的值",也就是说传递的是指针的副本,因此虽然似乎把一个数组传递进去了,但只要其他地方改动了这个数组,函数内部也会被影响.同理,返回值也是指针,如果不拷贝一份再返回,很有可能你在修改返回值的时候改动到了类的内部变量. 自己还不太明白的地方:…
题目原文: 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 and does not break otherwise. Your goal is to devise a strategy to determine the value of T given the…
题目要求: 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 in time proportional to n2 or better. 分析: <算法4>这本书提供的TwoSumFast解法为NlogN,ThreeSumFast解法为N2logN,根据课后练…
Welcome to Algorithms, Part I 前言 昨天在突然看到了Coursera上Robert Sedgewick讲的Algorithms,Part II看了一些,甚是爽快,所以又去注册了Algorithms,Part I,想从I开始系统的学习,关于网站,课程,人物的介绍我就不费笔了,不知道的大家可以谷歌一下.我认为这么好的东西,不去好好学习一下,实在是人生的一大缺憾,但是自己一个看看视频学习一下,貌似又没设什么意思,所以,就想分享和大家一起学习,我的想法是,起初,将本课程翻译…