Skip to content

Commit c55400f

Browse files
committed
Merge branch 'develop'
Release v1.11 done. chapter 15 BST all code complete
2 parents 2e1fe6d + d6e82e4 commit c55400f

Some content is hidden

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

42 files changed

+1009
-37
lines changed

arrays/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>elements-of-programming-interviews</artifactId>
77
<groupId>gardncl</groupId>
8-
<version>1.4</version>
8+
<version>1.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

@@ -16,7 +16,7 @@
1616
<dependency>
1717
<groupId>gardncl</groupId>
1818
<artifactId>utils</artifactId>
19-
<version>1.4</version>
19+
<version>1.0</version>
2020
</dependency>
2121
</dependencies>
2222

binarysearchtrees/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Chapter 15: Binary Search Trees
2+
3+
* 15.1 IsBST
4+
* 15.2 FirstGreaterThan
5+
* 15.3 FindKLargest
6+
* 15.4 ComputeLCA
7+
* 15.5 ReconstructBST
8+
* 15.6 ClosestEntries
9+
* 15.7 EnumerateEntries
10+
* 15.8 MostVisitedPages
11+
* 15.9 MinimumHeightBST
12+
* 15.10 InsertionAndDeletionBST
13+
* 15.11 AreNodesOrdered
14+
* 15.12 RangeLookup
15+
* 15.13 ClientCreditsInfo

binarysearchtrees/pom.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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.0</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>binarysearchtrees</artifactId>
13+
<name>Chapter 15: Binary Search Trees</name>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>gardncl</groupId>
18+
<artifactId>utils</artifactId>
19+
<version>1.0</version>
20+
</dependency>
21+
<dependency>
22+
<groupId>gardncl</groupId>
23+
<artifactId>datastructures</artifactId>
24+
<version>1.0</version>
25+
</dependency>
26+
</dependencies>
27+
28+
29+
</project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
public class AreNodesOrdered {
2+
3+
/*
4+
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+
*/
12+
13+
public static boolean totallyOrdered(BinaryTree<Integer> possible1,
14+
BinaryTree<Integer> possible2,
15+
BinaryTree<Integer> middle) {
16+
17+
return false;
18+
}
19+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
public class ClientCreditsInfo {
2+
3+
/*
4+
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+
*/
16+
17+
public void insert(String clientID, int c) {
18+
19+
}
20+
21+
public boolean remove(String clientID) {
22+
23+
return false;
24+
}
25+
26+
public int lookup(String clientID) {
27+
28+
return -1;
29+
}
30+
31+
public void addAll(int c) {
32+
33+
}
34+
35+
public String max() {
36+
37+
return "";
38+
}
39+
40+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import java.util.List;
2+
3+
public class ClosestEntries {
4+
5+
/*
6+
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+
*/
13+
14+
public static int findMin(List<List<Integer>> sortedArrays) {
15+
16+
return 0;
17+
}
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class ComputeLCA {
2+
3+
/*
4+
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+
*/
10+
11+
public static BinaryTree<Integer> findLCA(BinaryTree<Integer> tree,
12+
BinaryTree<Integer> s,
13+
BinaryTree<Integer> b) {
14+
15+
return new BinaryTree<>(0);
16+
}
17+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import java.util.Collections;
2+
import java.util.List;
3+
4+
public class EnumerateEntries {
5+
6+
/*
7+
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+
*/
12+
13+
public static class ABSqrt2 implements Comparable<ABSqrt2> {
14+
public int a, b;
15+
public double val;
16+
17+
public ABSqrt2(int a, int b) {
18+
this.a = a;
19+
this.b = b;
20+
this.val = a + b * Math.sqrt(2);
21+
}
22+
23+
@Override
24+
public int compareTo(ABSqrt2 o) {
25+
return Double.compare(val, o.val);
26+
}
27+
}
28+
29+
public static List<ABSqrt2> generateFirst(int k) {
30+
31+
return Collections.emptyList();
32+
}
33+
34+
35+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import java.util.Collections;
2+
import java.util.List;
3+
4+
public class FindKLargest {
5+
6+
/*
7+
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+
*/
14+
15+
public static List<Integer> findLargest(BinaryTree<Integer> tree, int k) {
16+
17+
return Collections.emptyList();
18+
}
19+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class FirstGreaterThan {
2+
3+
/*
4+
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+
*/
10+
11+
public static BinaryTree<Integer> find(BinaryTree<Integer> tree, Integer k) {
12+
13+
return new BinaryTree<>(0);
14+
}
15+
}

0 commit comments

Comments
 (0)