CSC 313: Data Structures in Java

Autumn 2002

Inidividual Assignment 1

Using a class specification and Algorithm Analysis

Due Wednesday September 25 before 11:30pm

Part I

For Part I, you will read the specification of two predefined classes and use them to analyze some literary texts. This involves having your program read in a text, count word frequencies from that text, and create a report summarizing the frequencies. In particular, your program should report the following statistics:

To help you with the programming (and to practice using collections and iterators), you must make use of the following classes:

If you have not used a jar file before, it may involve some effort to set up your programming environment so that java can find the jar file and the classes contained in it. To use the SetCountables class and the CountablesIterator class, you will need to do the following:

  1. Download the jar file, which contain the two classes.
  2. Do one of the following:
  3. Insert the statement import csc313.hw1.*; at the top your program's file.

Here are some additional specifications for your program:

Part II

For each of the code segments below, answer the following questions:

  1. Which operation (e.g. comparison or statement) will typically be executed more than any operation?
  2. For input size n, how many times will this statement be executed?
  3. What is the time complexity class (Big-Oh analysis) of this code segment?

Code segment A

   for (int i = 0; i < n; i += 2)
      sum++;

Code segment B

   for (int i = 0; i < n; i++)
      for (int j = 0; j < n * n; j++)
         sum++;

Code segment C

   for (int i = 0; i < n; i++)
      for (int j = 0; j < i; j++)
         sum++;

Example analysis

Here is an example analysis of a similar code fragment:
   for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
         for (int k = 0; k < 3; k++)
            sum++;
  1. "sum++" is repeated most frequently
  2. We work the analysis starting from the innermost loop
  3. the segment has a quadratic time complexity, also written as O(n^2)
Submission

Before the due date and time, you should submit the following three files through the submission Web page: