题目来源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…
题目原文:http://coursera.cs.princeton.edu/algs4/assignments/8puzzle.html 题目要求:设计一个程序解决8 puzzle问题以及该问题的推广,例如8-puzzle是3*3,程序要能解决n*n的同类问题(2 ≤ n < 128) 典型的8 puzzle如下: 算法设计参照A*搜索算法,即使不了解A*搜索算法,题目也已经将解法解释的很具体了. Best-first search:设计参照A* 搜索算法.定义一个 search node类,包…
题目地址:http://coursera.cs.princeton.edu/algs4/assignments/kdtree.html 分析: Brute-force implementation. 蛮力实现的方法比较简单,就是逐个遍历每个point进行比较,实现下述API就可以了,没有什么难度. import java.util.ArrayList; import java.util.TreeSet; import edu.princeton.cs.algs4.Point2D; import…
作业原文:http://coursera.cs.princeton.edu/algs4/assignments/queues.html 这次作业与第一周作业相比,稍微简单一些.有三个编程练习:双端队列(Deque)设计.随机队列(Randomized Queue)设计,还有一个排列组合类Permutation. 一.双端队列Deque 设计要求:A double-ended queue or deque (pronounced "deck") is a generalization o…
题目原文详见http://coursera.cs.princeton.edu/algs4/assignments/collinear.html 程序的主要目的是寻找n个points中的line segment,line segment的要求就是包含不少于4个点. 作业包含三部分程序实现: 一.Point compareTo()用来比较本节点this与其他节点that的大小:假如this节点坐标(x0, y0),that节点坐标(x1, y1),只有y0 < y1或(y0==y1 &&…
Programming Assignment 3: Pattern Recognition 1.题目重述 原题目:Programming Assignment 3: Pattern Recognition 题目给定n个二维平面点,搜索能够连成线的大于等于四个点的集合.需要分别实现三个类,点的类,暴力搜索,快速搜索. 点的类需要实现根据点的坐标比较以及两个点根据某个点的斜率的比较. 暴力搜索和快速搜索均需要实现寻找点的功能. 2.分析 主要是分析如何实现暴力搜索和快速搜索. 2.1 暴力搜索 这个…
The Problem. 求解8数码问题.用最少的移动次数能使8数码还原. Best-first search.使用A*算法来解决,我们定义一个Seach Node,它是当前搜索局面的一种状态,记录了从初始到达当前状态的移动次数和上一个状态.初始化时候,当前状态移动次数为0,上一个状态为null,将其放入优先级队列,通过不断的从优先级队列中取出Seach Node去扩展下一级的状态,直到找到目标状态.对于优先级队列中优先级的定义我们可以采用:Hamming priority function 和…
自我总结: 1.编程的思维不够,虽然分析有哪些需要的函数,但是不能比较好的汇总整合 2.写代码能力,容易挫败感,经常有bug,很烦心,耐心不够好 题目: In this programming assignment you will implement one or more of the integer multiplication algorithms described in lecture. To get the most out of this assignment, your pro…
Coursera CSE341: Programming Languages 感谢华盛顿大学 Dan Grossman 老师 以及 Coursera . 碎言碎语 这只是 Programming Languages 这门课程第一部分,在 Part A 中通过 Standard ML 这门编程语言把函数式编程的美妙娓娓道来.在 Part B 以及 Part C 中分别会学习 Racket 以及 Ruby . 这是一门什么样的课呢?首先,它很好玩,虽然我学过 Scala 学过一些 Scheme,但还…
Planar data classification with a hidden layer Welcome to the second programming exercise of the deep learning specialization. In this notebook you will generate red and blue points to form a flower. You will then fit a neural network to correctly cl…
编程作业四 作业链接:Boggle & Checklist 我的代码:BoggleSolver.java 问题简介 Boggle 是一个文字游戏,有 16 个每面都有字母的骰子,开始随机将它们放在 4 * 4 的板子上,如图: 图片来自:wiki. 游戏双方就在上面找有效的单词,单词越长分数越高,有效的单词具体指: 有效单词相邻字符的骰子也相邻,上下左右,对角线也行. 有效单词不能重复使用某个骰子. 有效单词的长度至少为 3. 有效单词要能在字典中找到,专有名词不算. 举例: 左边的单词 PIN…
先附上challenge要求: 博主最近在刷coursera普林斯顿大学算法课part1部分的作业,Programming Assignment2最后的这个extra challenge当初想了一段时间.最开始的想法就是创建一个RandomizedQueue对象,然后先让前k个String入队,后面的每读一个String以一定概率让它入队,不过之前需要让RandomizedQueue出队一个String.标准输入读完之后,得到一个k个String的RandomizedQueue,然后随机出队打印…
Please note that when you are working on the programming exercise you will find comments that say "# GRADED FUNCTION: functionName". Do not edit that comment. The function in that code block will be graded. 1) What is a Jupyter notebook? A Jupyt…
用2d-tree数据结构实现在2维矩形区域内的高效的range search 和 nearest neighbor search.2d-tree有许多的应用,在天体分类.计算机动画.神经网络加速.数据挖掘.图像检索. range search: 返回所有在query rectangle里的所有点 nearest neighbor search: 返回query point的最近点 下图显示这两种search操作 Geometric Primitives. 在assignment给定了几何图元应该…
实现一个泛型的双端队列和随机化队列,用数组和链表的方式实现基本数据结构,主要介绍了泛型和迭代器. Dequeue. 实现一个双端队列,它是栈和队列的升级版,支持首尾两端的插入和删除.Deque的API如下 public class Deque<Item> implements Iterable<Item> { public Deque() // construct an empty deque public boolean isEmpty() // is the deque emp…
问题描述可以详见:http://coursera.cs.princeton.edu/algs4/assignments/percolation.html 关于QuickFindUF的javadoc:http://algs4.cs.princeton.edu/15uf/QuickFindUF.java.html 关于WeightedQuickUnionUF的javadoc:http://algs4.cs.princeton.edu/15uf/WeightedQuickUnionUF.java.ht…
课程 Programming Languages, Part A Programming Languages, Part B Programming Languages, Part C CSE341: Programming Languages 笔记 Programming Languages, Part A 总结 Programming Languages, Part B 总结 Programming Languages, Part C 总结 总结 从 2017年12月1日 到 2018年1月…
Programming Languages, Part A Programming Languages, Part B Part A 笔记 碎言碎语 很多没有写过 Lisp 程序的人都会对 Lisp 中的括号产生偏见(包括曾经第一次看到 Lisp 程序的我),事实上,括号赋予 Lisp 的是严谨的程序结构,Lisp 中的括号是极其严格的,往往既缺一不可,也不能画蛇添足.括号往往意味着表达式的计算,例如 (e)表示 e 表达式的计算,那么一旦 e 是一个确定的值,则会出现问题,(3),在 Rack…
编程作业二 作业链接:Deques and Randomized Queues & Checklist 我的代码:Deque.java & RandomizedQueue.java & Permutation.java 问题简介 Write a generic data type for a deque and a randomized queue. The goal of this assignment is to implement elementary data struct…
编程作业一 作业链接:WordNet & Checklist 我的代码:WordNet.java & SAP.java & Outcast.java 这是第二部分的编程作业,因为第二部分课程开始了,第一部分博客就先放放. 问题简介 WordNet 按字面意思就是单词网,它是一个有向图,点里面是同义的单词,边则指向具有更高层次的抽象含义的点.举例来说,有个点里面含{与电路,与门}表示输入全为 1 输出才为 1 的逻辑门,指向点{门,逻辑门}这更高层的抽象概念.另外需要注意的是,它还是…
题目原文 Selection in two sorted arrays. Given two sorted arrays a[] and b[], of sizes n1 and n2, respectively, design an algorithm to find the kth largest key. The order  of growth of the worst case running time of your algorithm should be logn, where n…
题目原文: 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] to a[2*n-1] is sorted using an auxiliary array of length n (instead of 2n) 分析: 对两个大小分别为n的有序子数组进行归并,…
第二周课程的Elementray Sorts部分练习测验Interview Questions的第3题荷兰国旗问题很有意思.题目的原文描述如下: Dutch national flag. Given an array of n buckets, each containing a red, white, or blue pebble, sort them by color. The allowed operations are: swap(i,j): swap the pebble in buc…
题目原文: 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传参数时传递的是值,这很多人都知道,只不过特别要注意的是对于引用类型,传递的是"引用的值",也就是说传递的是指针的副本,因此虽然似乎把一个数组传递进去了,但只要其他地方改动了这个数组,函数内部也会被影响.同理,返回值也是指针,如果不拷贝一份再返回,很有可能你在修改返回值的时候改动到了类的内部变量. 自己还不太明白的地方:…
The problem. Given a set of N distinct points in the plane, draw every (maximal) line segment that connects a subset of 4 or more of the points. Point data type. Create an immutable data type Point that represents a point in the plane by implementing…
import edu.princeton.cs.algs4.StdOut; import edu.princeton.cs.algs4.StdRandom; import edu.princeton.cs.algs4.StdStats; /* *How do I generate a site uniformly at random among all blocked sites for use in PercolationStats? * Pick a site at random (by u…
3种版本的答案,第一种使用virtual top and bottom site, 但有backwash的问题,解决这个问题有两种方法: 1. 使用2个WQUUF, 但会增加memory. One for checking if the system percolates(include virtual top and bottom), and the other to check if a given cell is full(only include virtual top). 而且要注意,…
碎言碎语 和前面的 ML 和 Racket 感觉明显不一样了,一边学着一边觉得这真是一门奇怪的语言,有着各种奇怪的语法,不过真的算是一个奇妙的体验(相比前面的两门语言,Ruby 的学习资源多了不少). week 1 的作业直接就是给出一份 Ruby 源码的俄罗斯方块游戏,而任务就是给这个游戏添加功能,趣味性不用多说,也能很好的考察到阅读代码.应用已有代码的能力.不得不再次感叹作业真的用心. week 2 首先就是比较,OOP vs FP,大量的代码示例以及详细的讲解,但绝不是为了告诉我们用什么而…