随笔分类 - Algorithms
摘要:本题的bonus是因此方法是queue的size 达到了K, 就停止增加元素,保证queue.size() 最大时只有k.Java code:import edu.princeton.cs.algs4.StdIn; import edu.princeton.cs.algs4.StdOut; publ...
阅读全文
摘要:RandomizedQueue 有几个关键点:1. 选择合适的数据结构,因为需要任意位置删除元素,Linked list 做不到,必须使用resizing arrays.2. resizing 的技巧。 Q. How to grow array? A. If array is full, cre...
阅读全文
摘要:本次作业考察利用array 或者linked list 实现规定时间复杂度的queue 和stack, 不能使用java 自带的stack 和queue. 目的是让我们掌握自己设计的函数的复杂度。Deque成功的关键是1. 选择合适的数据结构,本题选择doubly LinkedList.2. 自己写...
阅读全文
摘要:import edu.princeton.cs.algs4.StdOut; import edu.princeton.cs.algs4.StdRandom;import edu.princeton.cs.algs4.StdStats; /* *How do I generate a si...
阅读全文
摘要:3种版本的答案,第一种使用virtual top and bottom site, 但有backwash的问题,解决这个问题有两种方法:1. 使用2个WQUUF, 但会增加memory.One for checking if the system percolates(include virtual...
阅读全文
摘要:Question 1Suppose that you time a program as a function of N and producethe following table. N seconds------------------- 1024 0.000 ...
阅读全文
摘要:Question1Give the id[] array that results from the following sequence of 6 unionoperations on a set of 10 items using the quick-find algorithm. 6-3 2-...
阅读全文