CMPSCI 377: Operating Systems
Discussion 1: Concept Review and Java Exercise


Links:

1. Administrative slides: slides.pdf

2. Example implementation of the TreeNode class from Part C: TreeNode.java WordCountPseudo.java


Part A: Concept Review of The 1st Lecture: glossary.html

Part B: Concept Discussion

The following quizs is for discussion in the class. In the future, you may need write the answer all by yourself and submit them to the Moodle system.

1. What is the difference between uniprogramming, multiprogramming, and time sharing?

2. Give an example of a tradeoff in designing operating systems and highlight a potential upside and downside.

3. What is Moore's law, and how has Moore's law been changing in recent years?


Part C: Java Exercise

This exercise will involve writing some Java (pseudo)code and should serve as a refresher for some concepts you will need for this course. You may work in small groups on this exercise, but you should be able to both fully understand the solution and be confident of your ability to come up with the solution independently. If you would not be comfortable completing this exercise individually, you should carefully consider whether this course is appropriate and speak to the TA and/or professor as soon as possible.

As this exercise is not really related to operating systems, it will not be averaged into your final grade.

Specification

In this assignment, you will use a binary search tree structure to analyse a textual input file determining the frequency and location of words in the file. The information of words is stored in a output file, which lists the distinct words in alphabetical order and makes reference to each line on which the word is used. We will provide a program skeleton and you will provide code filling in the missing pieces.

Input file:

Peter Piper picked a peck of pickled peppers. A peck of pickled
peppers Peter Piper picked. If Peter Piper picked a peck of pickled peppers,
where is the peck that Peter Piper picked?


Action: let a record consist of a word, its frequency count, and a list that hold the line numbers for each occurrence. In a line, extract each word of text. For the first occurrence of a word in the input file, create a record and insert it in the tree. if the word is already in the tree, update the frequency and line number list.

Output: After reading the input file, print an alphabetized list of words, the frequency count, and the ordered list of lines on which the word occurred.
The output should look something like:

a..........................3: 1 2
if..........................1: 2
is..........................1: 3
of.........................3: 1 2
peck....................4: 1 2 3
peppers...............3: 1 2
peter...................4: 1 2 3
picked.................4: 1 2 3
pickled................3: 1 2
piper...................4: 1 2 3
that.....................1: 3
the......................1: 3
where..................1: 3

Assignment

Your task is to write Java code or pseudocode that returns a string like the one above. In particular, you should design the following method:

  // construct the tree using the given input file reader and return output as specified above
  public static String buildFrequencyList(LineReader reader) {
    // TODO
  }

You may assume that the LineReader class is provided to you with the following definition:
  // read the lines of a file
  public class LineReader {

    // returns whether there's another line
    public boolean hasNextLine() { ... }

    // return the words in the next line 
    public String[] nextLineWords() { ... }

  }

To get you started, we suggest defining two additional classes in your solution - a Record class and a TreeNode class. You should not need to use any other Java classes in your solution (other than Strings and a Vector/ArrayList); the purpose of this exercise is not to test your knowledge of the Java standard library. Remember that you can compare two Strings alphabetically by calling strA.compareTo(strB), which returns -1 if strA comes before strB, 0 if strA is the same as strB, or 1 if strA comes after strB; and when you want to print out your result, you can also override the toString method of your own class such that System.out.println(YOUR_OBJECT_NAME) can finish that for you.

You do not need to compile or run your code (Java-like pseudocode is fine), and small details like exact output formatting are not important. This exercise is simplified to verify your comfort with basic data structures, program design, and programming constructs in Java.

At the end of the discussion section we will briefly discuss the design of an example solution.

Turning in Your Exercise

You can submit your code or pseudocode to Moodle before next Monday. You can form a group of at most two members. Please make sure that each group member's name and student ID are indicated on the submission.

On-Line Java Tutorials

  • On-Line Java Tutorial at SUN
  • Introduction to Programming Using Java a free online book on introductory programming.
  • The Java API,the entire Java API collection - grouped by package and class.