Searching
- Binary Search Code
- Binary Search image ( from wikepedia)
- Binary Search
Sorting
Climb The Stairs
For all these maps:
climb-the-stairs__1.jev
climb-the-stairs__2.jev
climb-the-stairs__3.jev
climb-the-stairs__4.jev
climb-the-stairs__5.jev
climb-the-stairs__6.jev
climb-the-stairs__7.jev (GRADE BOOK)
climb-the-stairs__8.jev (GRADE BOOK)
climb-the-stairs__9.jev
**( Only if you want to get that ‘A’)
Pascal’s Triangle
Pascals Triangle presents a simple formula for expanding binomials. If you think a little bit about how Pascal’s Triangle determines each term, you should see that a recursive method is used!
The animation below demonstrates the recursive nature of Pascal’s Triangle.
Objective: to employ recursion to be able to print out an entire line of Pascal’s Triangle . Look at the animation, getting a particular term in a line is inherently recursive. This class should throw an ArithmeticException if you attempt to calculate an invalid Term. (quick example of how to throw an Exception)
Hint: You only need to use recusion to get the term of the expansion.
Part II
Now that you can print out an entire line of Pascal’s Triangle. Print out the entire triangle up to some degree ‘n’.
Description: This method prints the numbers from num down to and including on new lines
Method Call | output |
countDown(5) | 5 4 3 2 1 0 |
countDown(3) | 3 2 1 0 |
Description: This method prints each letter of String s on new lines in reverse order.
Method Call | output |
printRev(“abcdef”) | a b c d e f |
printRev(“abc”) | a b c |
int sumLessthan(int n)
Description: This method returns the sum of all positive integers less than or equal to n
Method Call | output |
sumLessThan(4) | 10 (4+3+2+1) |
sumLessThan( 5 ) | 15 ( 5 + 4 + 3 + 2 + 1) |
int sumLessthan(int n)
Description: This method returns the sum of all positive integers less than or equal to n
Method Call | output |
sumLessThan(4) | 10 (4+3+2+1) |
sumLessThan( 5 ) | 15 ( 5 + 4 + 3 + 2 + 1) |
double average( int[] nums, int index)
Description: This method returns the average of all the elements in nums. The parameter ‘idnex’ is used to keep track of how far along you have gone in the array.
Method Call | output |
average({3,2,1}, 0) | 2 |
average({3,2,2}, 0) | 2.333333 |
Recur
bunnyEars2() (try to figure out what goes where the question marks are)
1 2 3 4 5 6 |
if(bunnies == 0) return 0; if(bunnies % 2 == 0) return 3 +bunnyEars2(?????); return 2 +bunnyEars2( ????? ); |
Recursion problems (bunny ears is a good, straight forward one to start with)
Two Friends Meet
In the prior assignment (#2b), you were asked to go around the inner lake as shown below. We are going to add 1 new requirement to this
What is new this time?
recangular-lake.jev
recangular-lake-if2.jev
Scroll down for a hint about how to handle if test #1 for this map.
A closerlook at if test #1 (how to get around that first if test)
rectangular-lake-bumps1.jev
recangular-lake-bump3A.jev
recangular-lake-bump3B.jev ( NOT BEING GRADED, SKIP THIS)
walk-the-lake-jacks-map.jev
Write an infinite loop (1 while loop). You may NOT use isWater()