This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package chapter9; | |
/** | |
* | |
* @author renli | |
*/ | |
public class problem2 { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package chapter9; | |
/** | |
* | |
* @author renli | |
*/ | |
public class problem1 { | |
public static void main(String[] args) { | |
System.out.println(countStepsDP(10)); | |
System.out.println(countStepsRecursion(10)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package chapter5; | |
/** | |
* | |
* @author renli | |
*/ | |
public class problem8 { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
5.7 An array A contains all the integers from 0 through n, except for one number | |
which is missing. In this problem, we cannot access an entire integer in A with a single operation. | |
The elements of A are represented in binary, and the only operation we can use to access them is "fetch the jth bit of A[i]," | |
which takes constant time. Write code to find the missing integer. Can you do it in 0(n) time? | |
*/ | |
package chapter5; | |
/** | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package chapter5; | |
/** | |
* | |
* @author renli | |
*/ | |
public class problem6 { | |
public static void main(String[] args) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package chapter5; | |
/** | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*5.3 Given a positive integer, print the next smallest and the next largest number | |
that have the same number of 1 bits in their binary representation.*/ | |
package chapter5; | |
/** | |
* | |
* @author renli | |
*/ | |
public class problem3 { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
5.2 Given a real number between 0 and 7 (e.g., 0.72) that is passed in as a double, | |
print the binary representation. If the number cannot be represented accurately | |
in binary with at most 32 characters, print "ERROR." | |
*/ | |
package chapter5; | |
import java.util.ArrayList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
*5.1 You are given two 32-bit numbers, N andM, and two bit positions, i and j. | |
Write a method to insert M into Nsuch that M starts at bit j and ends at bit i. | |
You can assume that the bits j through i have enough space to fit all ofM. That is, | |
ifM= 10011, you can assume that there are at least 5 bits between j and i. You would not, | |
for example, have j-3 and i=2, because M could not fully fit between bit 3 and bit 2. | |
EXAMPLE: | |
Input: N = 16000000000, M = 10011, i = 2, j = 6 | |
Output: N = 10001001100 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
4.9 You are given a binary tree in which each node contains a value. | |
Design an algorithm to print all paths which sum to a given value. | |
The path does not need to start or end at the root or a leaf. | |
*/ | |
package chapter4; | |
import java.util.ArrayList; | |
import java.util.List; |
NewerOlder