CSci 3501 Algorithms and Computability - Lab 6.

September 30. Due Wednesday, October 6 at 11:59pm

What to submit and when:

Lab assignment

Work in pairs

Lab overview and goals

The lab has two separate parts

The goal of part I of the lab is to practice with JFLAP (a tool for experimenting with finite automata and other computability topics) and to design and test DFAs.

The second part fo the lab revisits sorting methods and focuses on picking the best approach for a particular sorting criteria.

Using JFLAP and naming your files

Lab tasks

Part 1 (10 points; 3 per each automaton and 1 for general set-up)

Unless specified otherwise, the alphabet is the set of 0 and 1. Recall that zero is an even number.

Design and test the following finite automata:

  1. DFA to recognize the language of all strings that have at most three zeros.
  2. DFA to recognize the language of all strings that have an even number of zeros and an odd number of ones.
  3. DFA to recognize the language of all strings that end at an even number of zeros (i.e. the longest substring of 0s at the end of the string is of even length).

Part 2 (to be graded later...)

Develop a sorting algorithm to sort words in a long text file (a few thousand words) by the following criteria: by word length as a primary criteria and alphabetically as a secondary one. This means that all shorter words come before all longer words and within each group of words of the same length the words are sorted alphabetically (more precisely, according to compareTo method of String class).

Your goal is to develop an algorithm that sorts as fast as possible. "Fast" here means direct timing of the program, not just the Big-Theta approximation. You will get a text file to practice, but the final test will be done on a different file.

The assignment will run for two lab periods: one to get preliminary competition results and the second one for the final competition.

Make sure to make your Eclipse workspace read-protected to keep your "trade secrets". For the first competition, please send me a jar file or a class file, not the source code.

Three groups that get the best time in the final run will get extra credit.

Rules and requirements:

  1. You must use Java. While this may not be the best language choice for efficiency purposes, this assignment is not about languages, it's about algorithms. Thinking about implementation details is important, however.
  2. The file may contain data that is not just letters, but most of it is English words. Alphabetical comparison must be done based on compareTo of String class. Note that punctuation marks attached to words are considered a part of the word (e.g. when? has the length of 5)
  3. Your program must read data from a file, store it internally as an array, sort it, and then output it into a file. This link may be helpful for file reading/writing: http://www.javapractices.com/topic/TopicAction.do?Id=42
  4. The program must take three command-line arguments: the name of the input file, output file, and the number of loops. The last argument will allow repeating the sorting multiple times to get more accurate times if needed.
  5. The timing in the program is done similarly to lab 1 (using System.currentTimeMillis()). The timer starts after you read the file and stops before you start writing out the result. You might want to stop the current thead for a few milliseconds after reading the file before you start the timer to allow time to close the buffer reader.
  6. Your sorting starts by copying the given array into a new array (in a loop) and then sorting that array in place. This is so that you can repeat the sorting multiple times. Since the copying time is the same for everyone, it will not affect the competition.
  7. Only the last copy of the sorted array should be copied to the resulting file.

Use the file text1.txt for testing.


CSci 3501 course web site.