COW Q3 N1 - Recursion and MergeSort

advertisement
COW Q3 N1
Recursion and MergeSort
Level 1
CodingBat - Complete 2 stars in Recursion-1 on codingbat.com
BabyNamer – You are working at a baby doll factory where each doll is produced with a unique
name. For this you were asked to come up with a program to come up with names for each doll. For
level 1, finish putting in code for constructor of the BabyNamer class so that it reads in the list of first
names and the list of last names from a file and stores them in the corresponding two ArrayLists. Also
have the constructor create ( = new ) the fullNames ArrayList. Then program the following methods:
 printFirstNames() - print out the ArrayList of first names
 printLastNames() - print out the ArrayList of last names
 getRandomFirstName() - returns a randomly chosen first name
 getRandomLastName() - returns a randomly chosen last name
Level 2
CodingBat - Complete 2 additional stars in Recursion-1 on codingbat.com
BabyNamer – Complete the following methods:
 generateRandomNames(int n)
generates n number of random full names and adds them
to the fullNames ArrayList.
 printList()
prints the names in fullNames
 printListInReverse() prints the names in fullNames in reverse
 findLongestName() returns the longest name in fullNames
 findShortestName() returns the shortest name in fullNames
Level 3
CodingBat - Complete 2 additional stars in Recursion-1 on codingbat.com
BabyNamer – Complete the following methods:
 sort() calles MergeSort and passes in fullNames
 MergeSort(ArrayList<String>) uses the recursive MergeSort algorithm to sort the names in
fullNames
Level 4
CodingBat - Complete 2 additional stars in Recursion-1 on codingbat.com
Recursion Practice – Create a program that produces the following output to the screen. Each item
sent to standard output should be a value stored in a variable. Each line should be produced by a
separate recursive function:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
2, 4, 6, 8, 10, 12, 14, 16, 18, 20,
1, 2, 4, 8, 16, 32, 64, 128, 256, 512,
1, 3, 7, 15, 31, 63, 127, 255, 511,
1, 4, 10, 22, 46, 94, 190, 382, 766,
1, 2, 5, 14, 41, 122, 365, 1094,
1, -10, 100, -1000, 10000, -100000,
1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
2, 4, 16, 256, 65536,
Level 5
CodingBat - Complete 2 stars in Recursion-2 on codingbat.com
BabyNamer – Complete the following methods:
 eliminateRepetitions () – eliminates all repitions of names in fullNames so
{“Mark Jones”, “Sally Doe”, “Mark Jones”, “Petter Pipper”}
becomes
{“Mark Jones”, “Sally Doe” , “Petter Pipper”}
Download