实现一个泛型的双端队列和随机化队列,用数组和链表的方式实现基本数据结构,主要介绍了泛型和迭代器. Dequeue. 实现一个双端队列,它是栈和队列的升级版,支持首尾两端的插入和删除.Deque的API如下 public class Deque<Item> implements Iterable<Item> { public Deque() // construct an empty deque public boolean isEmpty() // is the deque emp…
RandomizedQueue 有几个关键点: 1. 选择合适的数据结构,因为需要任意位置删除元素,Linked list 做不到,必须使用resizing arrays. 2. resizing 的技巧. Q. How to grow array?    A. If array is full, create a new array of twice the size, and copy items.     Q. How to shrink array?     A: halve size…
本次作业考察利用array 或者linked list 实现规定时间复杂度的queue 和stack, 不能使用java 自带的stack 和queue. 目的是让我们掌握自己设计的函数的复杂度. Deque成功的关键是 1. 选择合适的数据结构,本题选择doubly LinkedList. 2. 自己写测试代码,测试各种情况.addLast, removeFirst 等等,尤其注意边界情况. Java code: //Deque - should be implemented using a…
本题的bonus是 因此方法是queue的size 达到了K, 就停止增加元素,保证queue.size() 最大时只有k. Java code: import edu.princeton.cs.algs4.StdIn; import edu.princeton.cs.algs4.StdOut; public class Subset { public static void main(String[] args){ int k = Integer.parseInt(args[0]); Rand…
编程作业二 作业链接: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…
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…
自我总结: 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…
Programming Assignment 3: Pattern Recognition 1.题目重述 原题目:Programming Assignment 3: Pattern Recognition 题目给定n个二维平面点,搜索能够连成线的大于等于四个点的集合.需要分别实现三个类,点的类,暴力搜索,快速搜索. 点的类需要实现根据点的坐标比较以及两个点根据某个点的斜率的比较. 暴力搜索和快速搜索均需要实现寻找点的功能. 2.分析 主要是分析如何实现暴力搜索和快速搜索. 2.1 暴力搜索 这个…
作业原文: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…
1. 题目重述 完成三个程序,分别是双向队列,随机队列,和随机队列读取文本并输出k个数. 2. 分析 2.1 双向队列 题目的性能要求是,操作时间O(1),内存占用最大48n+192byte. 当使用单向链表时,尾端删除需要从链表头遍历,才能知道新的链表头,操作时间无法满足. 当使用变长数组时,当头尾均为1/4时,内存使用为~56N,不满足情况. 选用双向链表实现. 2.2 随机队列 题目性能要求时,操作时间O(1), 内存占用最大48n+192byte. 由于是随机操作,所以链表不适用,链表只…
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给定了几何图元应该…
The Problem. 求解8数码问题.用最少的移动次数能使8数码还原. Best-first search.使用A*算法来解决,我们定义一个Seach Node,它是当前搜索局面的一种状态,记录了从初始到达当前状态的移动次数和上一个状态.初始化时候,当前状态移动次数为0,上一个状态为null,将其放入优先级队列,通过不断的从优先级队列中取出Seach Node去扩展下一级的状态,直到找到目标状态.对于优先级队列中优先级的定义我们可以采用:Hamming priority function 和…
先附上challenge要求: 博主最近在刷coursera普林斯顿大学算法课part1部分的作业,Programming Assignment2最后的这个extra challenge当初想了一段时间.最开始的想法就是创建一个RandomizedQueue对象,然后先让前k个String入队,后面的每读一个String以一定概率让它入队,不过之前需要让RandomizedQueue出队一个String.标准输入读完之后,得到一个k个String的RandomizedQueue,然后随机出队打印…
编程作业四 作业链接:Boggle & Checklist 我的代码:BoggleSolver.java 问题简介 Boggle 是一个文字游戏,有 16 个每面都有字母的骰子,开始随机将它们放在 4 * 4 的板子上,如图: 图片来自:wiki. 游戏双方就在上面找有效的单词,单词越长分数越高,有效的单词具体指: 有效单词相邻字符的骰子也相邻,上下左右,对角线也行. 有效单词不能重复使用某个骰子. 有效单词的长度至少为 3. 有效单词要能在字典中找到,专有名词不算. 举例: 左边的单词 PIN…
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…
问题描述可以详见: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…
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). 而且要注意,…
编程作业三 作业链接:Pattern Recognition & Checklist 我的代码:BruteCollinearPoints.java & FastCollinearPoints.java & Point.java 问题简介 计算机视觉涉及分析视觉图像中的模式并重建产生它们的现实世界对象.该过程通常分为两个阶段:特征检测和模式识别.特征检测涉及选择图像的重要特征:模式识别涉及发现特征中的模式.我们将研究一个涉及点和线段的特别简单的模式识别问题.这种模式识别出现在许多其他…
编程作业五 作业链接:Burrows-Wheeler Data Compression & Checklist 我的代码:MoveToFront.java & CircularSuffixArray.java & BurrowsWheeler.java 问题简介 Burrows-Wheeler 数据压缩算法包括三个部分:Burrows-Wheeler transform,Move-to-front encoding 和 Huffman compression,前面两个部分把文本转换…
编程作业三 作业链接:Baseball Elimination & Checklist 我的代码:BaseballElimination.java 问题简介 这是一个最大流模型的实际应用问题:篮球淘汰赛,设想你现在知道如下的比赛信息: w[i] l[i] r[i] g[i][j] i team wins loss left Atl Phi NY Mon ------------------------------------------------ 0 Atlanta 83 71 8 - 1 6…
编程作业二 作业链接:Seam Carving & Checklist 我的代码:SeamCarver.java 问题简介 接缝裁剪(Seam carving),是一个可以针对照片内容做正确缩放的算法(由 Shai Avidan 和 Ariel Shamir 所发表).概念上,这个算法会找出好几条 seams,而这些 seams 是在照片中最不重要的一连串像素,接着再利用这些 seams,对照片做缩放.如果是要缩小照片,则移除这些 seams,若是放大,则在这些 seams 的位置上,插入一些像…
编程作业一 作业链接:WordNet & Checklist 我的代码:WordNet.java & SAP.java & Outcast.java 这是第二部分的编程作业,因为第二部分课程开始了,第一部分博客就先放放. 问题简介 WordNet 按字面意思就是单词网,它是一个有向图,点里面是同义的单词,边则指向具有更高层次的抽象含义的点.举例来说,有个点里面含{与电路,与门}表示输入全为 1 输出才为 1 的逻辑门,指向点{门,逻辑门}这更高层的抽象概念.另外需要注意的是,它还是…
题目原文详见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 &&…
题目地址: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/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/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…
Today I complete Socket Programming Assignment 1 Web Server Here is the code: #!/usr/bin/python2.7 # Program: Web Server # Date: 2016-03-19 # Author: brant-ruan # P.S. from socket import * serverPort = 12000 # Prepare a server socket serverSocket = s…
Expected OutputTrigger Word Detection Welcome to the final programming assignment of this specialization! In this week's videos, you learned about applying deep learning to speech recognition. In this assignment, you will construct a speech dataset a…