Princeton Algorithms week3 Assignment

这周编程作业是实现检测点共线的算法。和排序算法有关系的地方在于,对斜率排序后可以很快的检测出来哪些点是共线的,另外这个算法的瓶颈也在于排序的性能。

一点收获:

java传参数时传递的是值,这很多人都知道,只不过特别要注意的是对于引用类型,传递的是“引用的值”,也就是说传递的是指针的副本,因此虽然似乎把一个数组传递进去了,但只要其他地方改动了这个数组,函数内部也会被影响。同理,返回值也是指针,如果不拷贝一份再返回,很有可能你在修改返回值的时候改动到了类的内部变量。

自己还不太明白的地方:

循环内部除了排序还有很多很多操作,这些相对于排序的时间复杂度不重要是因为当N很大很大时,排序需要的时间O(NlogN)要远远大于你内部循环一遍O(N)和其他操作(常数级复杂度),所以说看时间复杂度还是要看循环内的操作。

总结一下:

编程时还是应该自己动手解决问题,太依赖论坛里的解答或者轻易问同学就等于自己放弃了学习的机会。刘未鹏老师在“为什么遇到问题要自己动手解决”里面已经讲的很清晰了,有时你心里清楚这个问题请做完作业的同学给你简单说两句,就马上可以解决(真的很诱惑呀,谁不想最快的速度写完作业呢?)可是如果你问了,下次遇到类似的问题你还是不会,因为你没有经历那个一点点琢磨明白这个知识点的过程,你就做到不到对这个知识点了然于心,下次用起来就不顺手。心理学上有一个“记忆的存储提取速度成反比”的现象,一个东西你理解它的时候越费劲,到用的时候越容易想起来。

另外,面对困难,坚持想办法,不断搜索,尝试,琢磨...这整个过程是很磨练人的耐性的。尤其是物理专业转计算机的学生,很多比较“怵”需要动手的东西,写程序这个过程就是一个训练自己心态的过程,只有不断积累写程序调程序的经验,才能让自己在面对困难的时候,坚持的时间更长一些。

时间: 2024-10-14 06:19:49

Princeton Algorithms week3 Assignment的相关文章

Coursera Algorithms week3 快速排序 练习测验: Nuts and bolts

题目原文: 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. Each nut fits exactly one bolt and each bolt fits exactly one nut. By fitting a nut and a bolt toget

Coursera Algorithms week3 快速排序 练习测验: Selection in two sorted arrays(从两个有序数组中寻找第K大元素)

题目原文 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

Coursera Algorithms Programming Assignment 4: 8 Puzzle (100分)

题目原文: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类,包

Coursera Algorithms week3 归并排序 练习测验1: Merging with smaller auxiliary array

题目原文: 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的有序子数组进行归并,

Coursera Algorithms Programming Assignment 1: Percolation

题目来源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

Coursera Algorithms Programming Assignment 2: Deque and Randomized Queue

这次作业与第一周作业相比,稍微简单一些.有三个编程练习:双端队列(Deque)设计.随机队列(Randomized Queue)设计,还有一个排列组合类Permutation. 一.双端队列Deque 设计要求:A double-ended queue or deque (pronounced "deck") is a generalization of a stack and a queue that supports adding and removing items from e

CN5102 Module title Data Structures and Algorithms

SCHOOL OF ARCHITECTURE, COMPUTING &ENGINEERINGSubmission instructions Cover sheet to be attached to the front of the assignment when submitted Question paper to be attached to assignment when submitted All pages to be numbered sequentially All work h

COMP0037 Coursework Investigating Path Planning Algorithms

COMP0037 Coursework 1Term 2, 2019"Path Planning in a Known World"Investigating Path Planning AlgorithmsCOMP0037 Assignment 1Simon Julier ([email protected]), Dan Butters ([email protected]), Julius Sustarevas([email protected])Version: 21st Janu

Princeton-Algorithms-Part1-Week1-AnalysisOfAlgorithms

Slides from Princeton Algorithms. If you do it as a lg, lg plot very often you'll get a straight line. And the slope of the straight line is the key to what's going on. In this case, the slope of the straight line is three and so you can run what's c