Skip to content

Commit 08515d5

Browse files
committed
changed poms
1 parent 3f838cb commit 08515d5

File tree

184 files changed

+217
-992
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

184 files changed

+217
-992
lines changed

arrays/src/main/java/AdvanceThroughArray.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
public class AdvanceThroughArray {
44

55
/*
6-
6.4
7-
8-
Write a program that takes an array of n integers, where A[i]
9-
denotes the maximum you can advance from index i, and returns
10-
whether it is possible to advance to the last index starting
11-
from the beginning of the array
6+
6.4
127
*/
138

149
public static boolean arrayAdvance(List<Integer> A) {

arrays/src/main/java/BuySellStockOnce.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33
public class BuySellStockOnce {
44

55
/*
6-
6.6
7-
8-
Write a program that takes an array denoting the daily stock price,
9-
and returns the maximum profit that could be made by buying and
10-
then selling one share of that stock.
11-
*/
6+
6.6
7+
*/
128

139
public static int buySellStockOnce(List<Integer> A) {
1410

arrays/src/main/java/BuySellStockTwice.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ public class BuySellStockTwice {
44

55
/*
66
6.7
7-
8-
Write a program that computes the maximum profit that can
9-
be made by buying and selling a share at most twice. The
10-
second buy must be made on another date after the first sale.
11-
*/
7+
*/
128

139
public static int buySellStockTwice(List<Integer> A) {
1410

arrays/src/main/java/ComputePascalsTriangle.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ public class ComputePascalsTriangle {
55

66
/*
77
6.19
8-
9-
Write a program which takes as input a non-negative integer n
10-
and returns the first n rows of Pascal's triangle.
11-
*/
8+
*/
129

1310
public static List<List<Integer>> generatePascalTriangle(int n) {
1411

arrays/src/main/java/ComputeRandomPermutation.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ public class ComputeRandomPermutation {
55

66
/*
77
6.13
8-
9-
Design an algorithm that creates uniformly random permutations of {0,1,...,n-1}.
10-
You are given a random number generator that returns integers in the set {0,1,...,n-1}
11-
with equal probability; use as few calls to it as possible.
12-
*/
8+
*/
139

1410
public static List<Integer> computeRandomPermutation(int n) {
1511

arrays/src/main/java/ComputeRandomSubset.java

-7
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ public class ComputeRandomSubset {
55

66
/*
77
6.14
8-
9-
Write a program that takes as input a positive integer n and a size k <= n,
10-
and returns a size-k subset of {0, 1, 2, ..., n-1}. The subset should be
11-
represented as an array. All subsets should be equally likely and, in addition,
12-
all permutations of elements of the array should be equally likely.
13-
You may assume you have a function which takes as input a non-negative
14-
integer t and returns an integer in the set {0, 1,...,t-1} with uniform probability.
158
*/
169

1710
public static List<Integer> randomSubset(int n, int k) {

arrays/src/main/java/ComputeSpiralOrdering.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ public class ComputeSpiralOrdering {
55

66
/*
77
6.17
8-
9-
Write a program which takes an nxn 2D array and
10-
returns the spiral ordering of the array.
11-
Starts at [0,0] and goes clockwise.
12-
*/
8+
*/
139

1410
public static List<Integer> matrixInSpiralOrder(List<List<Integer>> squareMatrix) {
1511

arrays/src/main/java/DeleteDuplicates.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ public class DeleteDuplicates {
44

55
/*
66
6.5
7-
8-
Write a program that takes as input an array a sorted array and updates
9-
it so that all duplicates have been removed and the remaining elements
10-
have been shifted left to fill the emptied indices. Return the
11-
number of valid elements.
12-
*/
7+
*/
138

149
public static int deleteDuplicates(List<Integer> A) {
1510
return 0;

arrays/src/main/java/DutchNationalFlag.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ public class DutchNationalFlag {
44

55
/*
66
6.1
7-
8-
Write a program that takes an array A and an index i into A, and
9-
rearranges the elements such that all elements less that A[i]
10-
(the 'pivot') appear first, followed by elements equal to the pivot,
11-
followed by elements greater than the pivot.
12-
*/
7+
*/
138

149
public static void dutchNationalFlag(int p, List<Integer> A) {
1510

arrays/src/main/java/EnumeratePrimes.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ public class EnumeratePrimes {
55

66
/*
77
6.8
8-
9-
Write a program that takes an integer argument
10-
and returns all the primes between 1 and that integer.
11-
*/
8+
*/
129

1310
public static List<Integer> enumeratePrimes(int n) {
1411
return Arrays.asList(1);

arrays/src/main/java/GenerateNonuniformRandomNumbers.java

+1-12
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,7 @@ public class GenerateNonuniformRandomNumbers {
44

55
/*
66
6.15
7-
8-
You are given n numbers as well as probabilities p0,p1,...,p(n-1),
9-
which sum up to 1. Given a random number generator that produces
10-
values in [0,1] uniformly, how would you getRandom one of the n
11-
numbers according to the specified probabilities? For example,
12-
if the numbers are 3, 5, 7, 11, and the probabilities are
13-
9/18, 6/18, 2/18, 1/18, then in 1000000 calls to your program,
14-
3 should appear roughly 500000 times,
15-
5 should appear roughly 333333 times,
16-
7 should appear roughly 111111 times,
17-
and 11 should appear roughly 55555 times.
18-
*/
7+
*/
198

209
public static int getRandom(List<Integer> values, List<Double> probabilities) {
2110

arrays/src/main/java/IncrementArbitraryPrecisionInteger.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ public class IncrementArbitraryPrecisionInteger {
44

55
/*
66
6.2
7-
8-
Write a program that takes as input an array of digits encoding a decimal number D
9-
and updates the array to represent the number D + 1. For example, if the input is
10-
(1,2,9) then you should update the array to (1,3,0). Your algorithm should work
11-
even if it is implemented in a language that has finite-precision arithmetic.
12-
*/
7+
*/
138

149
public static List<Integer> incrementInteger(List<Integer> A) {
1510
return A;

arrays/src/main/java/MultipleArbitraryPrecisionIntegers.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ public class MultipleArbitraryPrecisionIntegers {
55

66
/*
77
6.3
8-
9-
Write a program that takes two arrays representing integers,
10-
and returns an integer representing their product.
11-
*/
8+
*/
129

1310
public static List<Integer> multiply(List<Integer> a, List<Integer> b) {
1411

arrays/src/main/java/NextPermutation.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ public class NextPermutation {
55

66
/*
77
6.10
8-
9-
Write a program that takes in a permutation and returns the
10-
next permutation under dictionary ordering. If the permutation
11-
is the last permutation return an empty array.
12-
*/
8+
*/
139

1410
public static List<Integer> nextPermutation(List<Integer> permutation) {
1511

arrays/src/main/java/PermuteElements.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ public class PermuteElements {
44

55
/*
66
6.9
7-
8-
Given an array A of n elements and a permutation P, apply P to A.
9-
*/
7+
*/
108

119
public static void applyPermutation(List<Integer> perm, List<Integer> a) {
1210

arrays/src/main/java/Rotate2DArray.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ public class Rotate2DArray {
55

66
/*
77
6.18
8-
9-
Write a function that takes as input an nxn 2D array,
10-
and rotates the array by 90 degrees clockwise.
11-
*/
8+
*/
129

1310
public static List<List<Integer>> rotateMatix(List<List<Integer>> squareMatrix) {
1411

arrays/src/main/java/SampleOfflineData.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ public class SampleOfflineData {
44

55
/*
66
6.11
7-
8-
Implement an algorithm that takes an input an array of
9-
distinct elements and a size, and returns a subset of
10-
the given size of the array elements. All subsets should
11-
be equally likely. Return the result in input array itself.
12-
*/
7+
*/
138

149
public static void randomSampling(int k, List<Integer> list) {
1510

arrays/src/main/java/SampleOnlineData.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ public class SampleOnlineData {
55

66
/*
77
6.12
8-
9-
Design a program that takes as input a size k,
10-
and reads packets, continuously maintaining a
11-
uniform random subset of size k of the read packets.
12-
*/
8+
*/
139

1410
public static List<Integer> runningSample(int k, List<Integer> sequence) {
1511

arrays/src/main/java/SudokuChecker.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@ public class SudokuChecker {
44

55
/*
66
6.16
7-
8-
Check whether a 9x9 2D array representing a partially
9-
sompleted Sudoku is valid. Specifically, check that
10-
no row, column, or 3x3 2D subarray contains duplicates.
11-
A 0-value in the 2D array indicates that the entry
12-
is blank; every other entry is in [1,9].
13-
*/
7+
*/
148

159
public static boolean isValidSudoku(List<List<Integer>> partialAssignment) {
1610

binarysearchtrees/src/main/java/AreNodesOrdered.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@ public class AreNodesOrdered {
22

33
/*
44
15.11
5-
6-
Write a program which takes two nodes in a BST and a third node,
7-
the "middle" node, and determines if one of the two nodes is a
8-
proper ancestor and the other a proper descendant of the middle.
9-
(A proper ancestor of a node is an ancestor that is not equal
10-
to the node; a proper descendant is defined similarly.)
11-
*/
5+
*/
126

137
public static boolean totallyOrdered(BinaryTree<Integer> possible1,
148
BinaryTree<Integer> possible2,

binarysearchtrees/src/main/java/ClientCreditsInfo.java

+1-11
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,7 @@ public class ClientCreditsInfo {
22

33
/*
44
15.13
5-
6-
Design a data structure that implements the following methods:
7-
- Insert: add a client with specified credit,
8-
replacing any existing entry for the client
9-
- Remove: delete the specified client
10-
- Lookup: return the number of credits associated
11-
with the specified client
12-
- Add-to-all: increment the credit count for all current
13-
clients by the specified amount
14-
- Max: return a client with the highest number of credits
15-
*/
5+
*/
166

177
public void insert(String clientID, int c) {
188

binarysearchtrees/src/main/java/ClosestEntries.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ public class ClosestEntries {
44

55
/*
66
15.6
7-
8-
Design an algorithm that takes three sorted arrays,
9-
and returns one entry from each such that the minimum
10-
interval containing these three entries is as small
11-
as possible.
12-
*/
7+
*/
138

149
public static int findMin(List<List<Integer>> sortedArrays) {
1510

binarysearchtrees/src/main/java/ComputeLCA.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ public class ComputeLCA {
22

33
/*
44
15.4
5-
6-
Design an algorithm that takes as input a BST and two nodes,
7-
and returns the LCA of the two nodes.
8-
fig 15.1 with C and G returns B.
9-
*/
5+
*/
106

117
public static BinaryTree<Integer> findLCA(BinaryTree<Integer> tree,
128
BinaryTree<Integer> s,

binarysearchtrees/src/main/java/EnumerateEntries.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ public class EnumerateEntries {
55

66
/*
77
15.7
8-
9-
Design an algorithm for efficiently computing the k smallest numbers
10-
of the form a+b*sqrt(2) for non-negative integers a and b.
11-
*/
8+
*/
129

1310
public static class ABSqrt2 implements Comparable<ABSqrt2> {
1411
public int a, b;

binarysearchtrees/src/main/java/FindKLargest.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ public class FindKLargest {
55

66
/*
77
15.3
8-
9-
Write a program that takes as input a BST and an integer k,
10-
and returns teh k largest elements in the BST in decreasing
11-
order. For example, if the input is the BST in Figure 15.1
12-
on Page 158 and k = 3, your program should return [53,47,42].
13-
*/
8+
*/
149

1510
public static List<Integer> findLargest(BinaryTree<Integer> tree, int k) {
1611

binarysearchtrees/src/main/java/FirstGreaterThan.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ public class FirstGreaterThan {
22

33
/*
44
15.2
5-
6-
Write a program that takes as input a BST and a value,
7-
and returns the first key that would appear in an
8-
inorder traversal which is greater than the input value.
9-
*/
5+
*/
106

117
public static BinaryTree<Integer> find(BinaryTree<Integer> tree, Integer k) {
128

binarysearchtrees/src/main/java/InsertionAndDeletionBST.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ public class InsertionAndDeletionBST extends BinaryTree<Integer> {
22

33
/*
44
15.10
5-
6-
Design efficient functions for inserting and removing keys
7-
in a BST. Assume that all elements in the BST are unique,
8-
and that your insertion method must preserve this property.
9-
*/
5+
*/
106

117
public InsertionAndDeletionBST(Integer data) {
128
super(data);

binarysearchtrees/src/main/java/IsBST.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ public class IsBST {
22

33
/*
44
15.1
5-
6-
Write a program that takes an input a binary tree and checks
7-
if the tree satisfies the BST property.
8-
*/
5+
*/
96

107
public static boolean isBST(BinaryTree<Integer> tree) {
118

binarysearchtrees/src/main/java/MinimumHeightBST.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ public class MinimumHeightBST {
44

55
/*
66
15.9
7-
8-
How would you build a BST of minimum possible height
9-
for a sorted array?
10-
*/
7+
*/
118

129
public static BinaryTree<Integer> build(List<Integer> A) {
1310

0 commit comments

Comments
 (0)