Skip to content

Commit ce1c486

Browse files
committed
release v1.7
2 parents 42d7b83 + 49a1e7d commit ce1c486

20 files changed

+530
-5
lines changed

datastructures/pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111

1212
<artifactId>datastructures</artifactId>
1313
<name>Data Structures</name>
14-
14+
<dependencies>
15+
<dependency>
16+
<groupId>gardncl</groupId>
17+
<artifactId>datastructures</artifactId>
18+
<version>1.4</version>
19+
</dependency>
20+
</dependencies>
1521

1622

1723
</project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
public class Star implements Comparable<Star> {
2+
3+
private double x, y, z;
4+
5+
public Star(double x, double y, double z) {
6+
this.x = x;
7+
this.y = y;
8+
this.z = z;
9+
}
10+
11+
public double distance() {
12+
return Math.sqrt(x * x + y * y + z * z);
13+
}
14+
15+
@Override
16+
public int compareTo(Star rhs) {
17+
return Double.compare(this.distance(), rhs.distance());
18+
}
19+
20+
@Override
21+
public String toString() {
22+
return "Star{" +
23+
"x=" + x +
24+
", y=" + y +
25+
", z=" + z +
26+
'}';
27+
}
28+
}

heaps/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Chapter 11: Heaps
2+
3+
* 11.1 MergeSortedFiles
4+
* 11.2 SortIncDec
5+
* 11.3 SortAlmostSorted
6+
* 11.4 ComputeKClosest
7+
* 11.5 ComputeMedianOnline
8+
* 11.6 ComputeKLargest
9+
* 11.7 HeapStack

heaps/pom.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>elements-of-programming-interviews</artifactId>
7+
<groupId>gardncl</groupId>
8+
<version>1.5</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>heaps</artifactId>
13+
<name>Chapter 11: Heaps</name>
14+
<dependencies>
15+
<dependency>
16+
<groupId>gardncl</groupId>
17+
<artifactId>datastructures</artifactId>
18+
<version>1.4</version>
19+
</dependency>
20+
<dependency>
21+
<groupId>gardncl</groupId>
22+
<artifactId>utils</artifactId>
23+
<version>1.4</version>
24+
</dependency>
25+
</dependencies>
26+
27+
28+
</project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import java.util.Collections;
2+
import java.util.Iterator;
3+
import java.util.List;
4+
5+
public class ComputeKClosest {
6+
7+
/*
8+
11.4
9+
10+
How would you compute the k stars which
11+
are closest to Earth?
12+
*/
13+
14+
private static final Star EARTH_COORDINATES = new Star(0,0,0);
15+
16+
public static List<Star> getKClosest(int k, Iterator<Star> stars) {
17+
18+
return Collections.emptyList();
19+
}
20+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import java.util.Collections;
2+
import java.util.List;
3+
4+
public class ComputeKLargest {
5+
6+
/*
7+
11.6
8+
9+
Given a max-heap, represented as an array A, design an
10+
algorithm that computes the k largest elements stored
11+
in the max-heap. You cannot modify the heap.
12+
*/
13+
14+
public static List<Integer> kLargestInBinaryHeap(final List<Integer> list, int k) {
15+
16+
return Collections.emptyList();
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import java.util.Collections;
2+
import java.util.Iterator;
3+
import java.util.List;
4+
5+
public class ComputeMedianOnline {
6+
7+
/*
8+
11.5
9+
10+
Design an algorithm for computing the
11+
running median of a sequence.
12+
*/
13+
14+
public static List<Double> onlineMedian(Iterator<Integer> sequence) {
15+
16+
return Collections.emptyList();
17+
}
18+
}

heaps/src/main/java/HeapStack.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
public class HeapStack {
2+
3+
/*
4+
11.7
5+
6+
How would you implement a stack API using a heap?
7+
*/
8+
9+
public void push(Integer x) {
10+
11+
}
12+
13+
public Integer pop() {
14+
15+
return 0;
16+
}
17+
18+
public Integer peek() {
19+
20+
return 0;
21+
}
22+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import java.util.Collections;
2+
import java.util.List;
3+
4+
public class MergeSortedFiles {
5+
6+
/*
7+
11.1
8+
9+
Write a program that takes as input a set of sorted sequences
10+
and computes the union of these sequences as a sorted sequence.
11+
*/
12+
13+
public static List<Integer> mergeSorted(List<List<Integer>> sortedArrays) {
14+
15+
return Collections.emptyList();
16+
}
17+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import java.util.Iterator;
2+
3+
public class SortAlmostSorted {
4+
5+
/*
6+
11.3
7+
8+
Write a program which takes as input a very long sequence
9+
of numbers and prints the numbers in sorted order. Each
10+
number is at most k away from its correctly sorted position.
11+
(Such an array is sometimes referred to as being k-sorted.)
12+
For example, no number in the sequence [3,-1,2,6,4,5,8]
13+
is more than two away from its final sorted position.
14+
*/
15+
16+
public static void sort(Iterator<Integer> sequence, int k) {
17+
18+
}
19+
20+
}

0 commit comments

Comments
 (0)