- Notifications
You must be signed in to change notification settings - Fork0
dev-xero/java-algorithms-exercise-practice
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
☕ Exercise solutions for chapter 1.1 written in Java
- isBetweenZeroAndOne()
- toBinaryString()
- printTwoDmBooleanArray()
- printTwoDmIntArray()
- printIntArray()
- matrixTransposition()
- lg()
- Fibonacci.Fib()
- Fibonnaci.FastFib()
- fact()
- binarySearch()
- bruteForceSearch()
We are asked in exercise (1.1.19) to improve the fib method to use some sort of cache. This one is particularly interesting because it runs in O(1) time provided that the cache contains the previous two sequences. Generating the previous sequences is done using loops.
// dynamic programming and memoizationpublicstaticlongFastFib(intN,HashMap<Integer,Long>cache) {if (N ==0) {cache.put(N,0L);return0; }if (N ==1) {cache.put(N,1L);return1; }cache.put(N,cache.get(N -2) +cache.get(N -1));returncache.get(N); }
I've implemented the same methods but in Python overhere, if you're interested.
About
☕ Exercise solutions for chapter 1.1 written in Java
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published