Skip to content

Commit bcb8da8

Browse files
committed
Merge branch 'develop'
chapter 16 done
2 parents c55400f + 3aa2ffb commit bcb8da8

28 files changed

+903
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Suggested usage:
2020
Having trouble solving a problem?
2121
* The book contains hints that I intentionally omitted from this repository
2222
* The book contains thorough solutions
23-
* My (sometimes commented) solutions are available in the [solutions] branch
23+
* My (sometimes commented) [solutions] are available
2424

2525
This project is open source so please fork it and help me create a supplement to this phenomenal book. Always looking for edge cases.
2626

arrays/src/test/java/SudokuCheckerTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public void isValidSudoku2() {
4040
Arrays.asList(7,0,0,0,2,0,0,0,6),
4141
Arrays.asList(0,6,0,0,0,0,2,8,0),
4242
Arrays.asList(0,0,0,4,1,9,0,0,5),
43-
Arrays.asList(0,0,0,0,8,0,0,7,9));
43+
Arrays.asList(0,0,0,0,8,0,0,7,9)
44+
);
4445

4546
test(expected, board);
4647
}
@@ -57,7 +58,8 @@ public void isValidSudoku3() {
5758
Arrays.asList(7,0,0,0,2,0,0,0,6),
5859
Arrays.asList(0,6,0,0,0,0,2,8,0),
5960
Arrays.asList(6,0,0,4,1,9,0,0,5),
60-
Arrays.asList(0,0,0,0,8,0,0,7,9));
61+
Arrays.asList(0,0,0,0,8,0,0,7,9)
62+
);
6163

6264
test(expected, board);
6365
}
@@ -74,7 +76,8 @@ public void isValidSudoku4() {
7476
Arrays.asList(7,0,0,0,2,0,0,0,6),
7577
Arrays.asList(0,6,0,0,0,0,2,8,0),
7678
Arrays.asList(0,0,0,4,1,9,0,0,5),
77-
Arrays.asList(0,0,0,0,8,0,0,7,9));
79+
Arrays.asList(0,0,0,0,8,0,0,7,9)
80+
);
7881

7982
test(expected, board);
8083
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import java.util.ArrayList;
2+
import java.util.List;
3+
4+
public class TreeNode {
5+
public List<Edge> edges = new ArrayList<>();
6+
7+
public static class Edge {
8+
public TreeNode root;
9+
public double length;
10+
11+
public Edge(double length) {
12+
this.length = length;
13+
root = new TreeNode();
14+
}
15+
16+
public Edge(TreeNode root, double length) {
17+
this.root = root;
18+
this.length = length;
19+
}
20+
}
21+
}

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<module>hashtables</module>
2121
<module>sorting</module>
2222
<module>binarysearchtrees</module>
23+
<module>recursion</module>
2324
</modules>
2425
<packaging>pom</packaging>
2526

recursion/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Chapter 16: Recursion
2+
3+
* 16.1 TowersOfHanoi
4+
* 16.2 NQueens
5+
* 16.3 GeneratePermutations
6+
* 16.4 GeneratePowerSet
7+
* 16.5 GenerateSubsetsK
8+
* 16.6 GenerateStrings
9+
* 16.7 GeneratePalindromicDecompositions
10+
* 16.8 GenerateBinaryTrees
11+
* 16.9 SudokuSolver
12+
* 16.10 ComputeGrayCode
13+
* 16.11 ComputeDiameter

recursion/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>recursion</artifactId>
13+
<name>Chapter 16: Recursion</name>
14+
<dependencies>
15+
<dependency>
16+
<groupId>gardncl</groupId>
17+
<artifactId>datastructures</artifactId>
18+
<version>1.0</version>
19+
</dependency>
20+
<dependency>
21+
<groupId>gardncl</groupId>
22+
<artifactId>utils</artifactId>
23+
<version>1.0</version>
24+
</dependency>
25+
</dependencies>
26+
27+
28+
29+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class ComputeDiameter {
2+
3+
/*
4+
16.11
5+
6+
The diameter of a tree is defined to be the length
7+
of a longest path in the tree. Design an efficient
8+
algorithm to compute the diameter of a tree.
9+
*/
10+
11+
public static int computeDiameter(TreeNode T) {
12+
13+
return 0;
14+
}
15+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import java.util.Collections;
2+
import java.util.List;
3+
4+
public class ComputeGrayCode {
5+
6+
/*
7+
16.10
8+
9+
Write a program which takes n as input and returns an n-bit Gray code.
10+
*/
11+
12+
public static List<Integer> grayCode(int numBits) {
13+
14+
return Collections.emptyList();
15+
}
16+
}
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 GenerateBinaryTrees {
5+
6+
/*
7+
16.8
8+
9+
Write a program that returns all distinct binary
10+
trees with a specified number of nodes. All node
11+
data must be 0.
12+
*/
13+
14+
public static List<BinaryTree<Integer>> generateAllBinaryTrees(int numNodes) {
15+
16+
return Collections.emptyList();
17+
}
18+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import java.util.Collections;
2+
import java.util.List;
3+
4+
public class GeneratePalindromicDecompositions {
5+
6+
/*
7+
16.7
8+
9+
Compute all palindromic decompositions of a given string.
10+
*/
11+
12+
public static List<List<String>> palindromicPartitioning(String input) {
13+
14+
return Collections.emptyList();
15+
}
16+
}

0 commit comments

Comments
 (0)