CS 1713 Week 9:
Review and Catch Up

Objectives:

No reading this week


Here are some of the things we will go over:


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.

If time permits, you can also add the following methods to this class: