Problems
Computational number theory. Write a program CubeSum.java that prints out all integers of the form where and𝑏 are integers between 0 and in sorted order, without using excessive space. That is, instead of computing an array of the sums and sorting them, build a minimum-oriented priority queue, initially containing . Then, while the priority queue is nonempty, remove the smallest item , print it, and then, if , insert the item . Use this program to find all distinct integers , and between 0 and such that 𝑎3+𝑏3=, such as .
Index priority-queue implementation. Implement IndexMaxPQ.java by modifying MaxPQ.java as follows: Change pq[] to hold indices, add an array keys [ ] to hold the key values, and add an array qp[] that is the inverse of pq [] — qp[i] gives the position of i in pq[] (the index j such that pq[j] is i). Then modify the code to maintain these data structures. Use the convention that qp[i] is -1 if i is not on the queue, and include a method contains() that tests this condition. You need to modify the helper methods exch() and less() but not sink() or swim().
Last updated
Was this helpful?