CS 151 -- Lab 7, Oct 27

Write the following recursive programs:
  1. Use recursion to write a Java method for determining if a string s has more vowels than consonants. The words to be checked should come from the command line. This is a really silly use of recursion. Do it anyway.
  2. Write a recursive function that will allow you to answer the questions:
    1. What is the largest number of recursive function calls that Java allows?
    2. Does java stop recursion at the same place every time?
    3. Does Java stop recursion in the same place on every machine? For instance, try on you laptop and on a lab computer.
  3. Recursive functions are, more often than not, a single function which calls itself. Write a "recursive loop" of 3 methods such that the first calls the second, the second calls the third and the third calls the first. You program should go around this recursive loop a number of times determined by a command line parameter. Further, the number of times you go around this loop should be controlled by a parameter that is passed around the loop; not by an instance variable of the class containing your recursive loop. The methods in the loop can be quite short (several could be as short as one line of code). None should be more than 5 lines.
  4. Write a short recursive Java method that determines if a string s is a palindrome, that is, it is equal to its reverse. Examples of palindromes include 'racecar' and 'gohangasalamiimalasagnahog'. The string to be checked should come from the command line. Do not use loops or stacks to do this, only recursion. One approach: compare first and last letters; if they are the same, recur on a string from which you removed the first and last letters. To check whether the first and last letters are the same, use the charAt method of the String class. For instance
                String abc = "abcdef";
                System.out.println("This should be true " + (abc.charAt(abc.length()-1)=='f'));
            
    Keep going until you get a non-matching letter (not a palindrome) or can confirm that the string is, indeed, a palindrome. For instance the code below drops the first and last letters from a string:
                String aa = "asdfdsa";
                System.out.println(aa.substring(1, aa.length()-1));        
            
  5. Given an unsorted array, A, of integers and an integer k, write a recursive algorithm for rearranging the elements in A so that all elements less than or equal to k come before any elements larger than k. What is the running time of your algorithm on an array of n values? The integer array to be re-arranged can be hardcoded into the main function

What to hand in

Stop after 80 minutes (I do not expect you to complete all of these, I simply could not pick the ones I wanted to skip.) Send email containing the functions you completed to gtowell@brynmawr.edu.