We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents c55400f + 3aa2ffb commit bcb8da8Copy full SHA for bcb8da8
README.md
@@ -20,7 +20,7 @@ Suggested usage:
20
Having trouble solving a problem?
21
* The book contains hints that I intentionally omitted from this repository
22
* The book contains thorough solutions
23
-* My (sometimes commented) solutions are available in the [solutions] branch
+* My (sometimes commented) [solutions] are available
24
25
This project is open source so please fork it and help me create a supplement to this phenomenal book. Always looking for edge cases.
26
arrays/src/test/java/SudokuCheckerTest.java
@@ -40,7 +40,8 @@ public void isValidSudoku2() {
40
Arrays.asList(7,0,0,0,2,0,0,0,6),
41
Arrays.asList(0,6,0,0,0,0,2,8,0),
42
Arrays.asList(0,0,0,4,1,9,0,0,5),
43
- Arrays.asList(0,0,0,0,8,0,0,7,9));
+ Arrays.asList(0,0,0,0,8,0,0,7,9)
44
+ );
45
46
test(expected, board);
47
}
@@ -57,7 +58,8 @@ public void isValidSudoku3() {
57
58
59
60
Arrays.asList(6,0,0,4,1,9,0,0,5),
61
62
63
64
65
@@ -74,7 +76,8 @@ public void isValidSudoku4() {
74
76
75
77
78
79
80
81
82
83
datastructures/src/main/java/TreeNode.java
@@ -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
19
+}
pom.xml
@@ -20,6 +20,7 @@
<module>hashtables</module>
<module>sorting</module>
<module>binarysearchtrees</module>
+ <module>recursion</module>
</modules>
<packaging>pom</packaging>
recursion/README.md
@@ -0,0 +1,13 @@
+# Chapter 16: Recursion
+* 16.1 TowersOfHanoi
+* 16.2 NQueens
+* 16.3 GeneratePermutations
+* 16.4 GeneratePowerSet
+* 16.5 GenerateSubsetsK
+* 16.6 GenerateStrings
+* 16.7 GeneratePalindromicDecompositions
+* 16.8 GenerateBinaryTrees
+* 16.9 SudokuSolver
+* 16.10 ComputeGrayCode
+* 16.11 ComputeDiameter
recursion/pom.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>elements-of-programming-interviews</artifactId>
+ <groupId>gardncl</groupId>
+ <version>1.0</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>recursion</artifactId>
+ <name>Chapter 16: Recursion</name>
+ <dependencies>
+ <dependency>
+ <artifactId>datastructures</artifactId>
+ </dependency>
+ <artifactId>utils</artifactId>
+ </dependencies>
27
28
29
+</project>
recursion/src/main/java/ComputeDiameter.java
@@ -0,0 +1,15 @@
+public class ComputeDiameter {
+ /*
+ 16.11
+ The diameter of a tree is defined to be the length
+ of a longest path in the tree. Design an efficient
+ algorithm to compute the diameter of a tree.
+ */
+ public static int computeDiameter(TreeNode T) {
+ return 0;
recursion/src/main/java/ComputeGrayCode.java
@@ -0,0 +1,16 @@
+import java.util.Collections;
+public class ComputeGrayCode {
+ 16.10
+ Write a program which takes n as input and returns an n-bit Gray code.
+ public static List<Integer> grayCode(int numBits) {
+ return Collections.emptyList();
recursion/src/main/java/GenerateBinaryTrees.java
@@ -0,0 +1,18 @@
+public class GenerateBinaryTrees {
+ 16.8
+ Write a program that returns all distinct binary
+ trees with a specified number of nodes. All node
+ data must be 0.
+ public static List<BinaryTree<Integer>> generateAllBinaryTrees(int numNodes) {
recursion/src/main/java/GeneratePalindromicDecompositions.java
+public class GeneratePalindromicDecompositions {
+ 16.7
+ Compute all palindromic decompositions of a given string.
+ public static List<List<String>> palindromicPartitioning(String input) {
0 commit comments