# CS 1713 Week 9: Review and Catch Up

#### Objectives:

• Review concepts covered during the last week.
• Go over material skipped from previous lectures.

Here are some of the things we will go over:

• Searching an sorting
• String manipulation
• The ArrayList
• Working with strings: Case Study 8: Word Utility

Searching and Sorting
Practice tracing selection and insertion sorts: Look at the sorttrace project here

The following were in the Week 8 notes:

The meaning of O(n), O(log n), and O(n2):
Problems:

1. It takes 10 seconds to do an operation on an array of size n. How long does it take to do it on an array of size 2n, if the operation is
1. A linear search
2. A binary search on a sorted array
3. A seletion or insertion sort
2. It takes 1 minute to sort an array of size 1,000,000 using a seletion sort. How long would it take to sort a similar array of size 5,000,000?
3. It takes 5 seconds to search an array of size 1,000,000 using a binary search. How long would it take to sort a similar array of size 8,000,000?

String manipulation
1. Suppose s is a string that contains only digits.
Set the integer variable x to the value of the integer it represents.
2. Suppose s is a string that contains two integers separated by a single blank. Set the integer variable x to the first integer and the integer variable y to the second.
3. How would you write a method that takes a String like the one in b) as a parameter and returns the two integers?
4. How would you modify the above if the integers were separated by several blanks?
5. A String contains several integers separated by blanks. Return the integer values.

The ArraysList
Look here.

Also, get a copy of gcs04a and load it into eclipse.
Convert it to use an ArrayList instead of an array.

### Case Study 8: Developing a utility class with static methods - the WordUtility class

You can find activity instructions here.

You can find a skeleton of this case study here.

Create a project called cs08. All classes in this project will be in the strings package.

This case study uses the String class to write more complicated utility methods to manipulate words. Develop a WordUtility class that contains static methods to perform the following useful functions.

• public static boolean isVowel(char c) - returns true if the character c is a vowel and false otherwise
• public static int firstVowelPosition(String s) - returns the position of the first vowel in s or -1 if s doesn't contain any vowels.
• public static int firstBlank(String s) - returns the position of the first blank character in s or -1 if s does not contain blanks.
• public static int firstOccurrence(String s, char c) - returns the first occurrence of c in s or -1.
• public static int firstNonBlank(String s) - returns the position of the first nonblank character in s or -1 if s only contains blanks.
• public static int firstNonVowel(String s) - returns the position of the first character in s that is not a vowel or -1 if s contains all vowels.
• public static int numberVowels(String s) - returns the number of vowels in s.
• public static int numberNonVowels(String s) - returns the number of non vowel characters in s.
If time permits, you can also add the following methods to this class:
• public static String reverse(String s); - returns a new string that is the reverse of the parmeter
• public static int countTokens(String s); - returns the number of tokens in the string, where tokens are separated by one or more blanks.
• public boolean isPalindrome(String s); - returns true if the string reads the same forwards and backwards.