CS 451 Willamette University Spring, 2019
 
Topics in Computer Science:
Operating Systems and Concurrency
 

Supplemental Problems

Supplemental Problems extend the range of problems considered in the course and help sharpen problem-solving skills. Through the semester, several supplemental problems will be required.

Quick Links: 1, 2, 3, 4, 5, 6

Academic Honesty Certification

The very beginning of every lab, project, and supplemental problem must contain the following lines:

    /***********************************************************************
     * Name(s)  (identify both lab partners for labs, projects)            *
     * Box(s):                                                             *
     * Assignment name (Lab, Project, Sup. Problem Number _______)         *
     *      (25% off if name/number does not match assignment)             *
     * Assignment for <due date>;                                           *
     ***********************************************************************/

    /* *********************************************************************
     * Academic honesty certification:                                     *
     *   Written/online sources used:                                      *
     *     [include textbook(s), CS 451 labs or readings;                  *
     *       complete citations for Web or other written sources           *
     *      write "none" if no sources used]                               *
     *   Help obtained                                                     *
     *     [indicate names of instructor, class mentors                    *
     *      or evening tutors, consulted according to class policy;        *
     *      write "none" if none of these sources used]                    *
     *     ["none" or the instructor's name for Supplemental Problems      *
     *   My/our signature(s) below confirms that the above list of sources *
     *   is complete AND that I/we have not talked to anyone else          *
     *   (e.g., CSC 161 students) about the solution to this problem       *
     *                                                                     *
     *   Signature:                                                        *
     ***********************************************************************/

No coursework can be accepted, if this certification is incomplete or if the statement is not signed by ALL collaborators involved.

Grading Basics


Playing Modified Scrabble

  1. The game of Scrabble is a word game, in which players place letters on a grid to form words. For this problem, after the first word is placed on the board, subsequent words must intersect one or more existing words. In the game, letters from a player are connected to letters already on the board to form words. Many descriptions of the game are available online, including a reasonably thorough discussion on Wikipedia.

    This problem considers the addition of a word to the board, where a new word will intersect with an existing word. For example, consider the following grid:

    
            P R O G R A M 
      M E M O R Y
          N E T W O R K 
      S Y S T E M                   E
            S T R I N G     A N T I Q U E
                    O       L       U
                  C O L L E G E     A
        T P       A D       E       T S
        H H       L L       B       I C
        E Y       C E       R       O H I O
        O S       U         A       N E
      G R I N N E L L                 M
        Y C       U                   E
          S       S
    

    This grid contains numerous words arranged horizontally or vertically, and each word is connected to one or more other words at various letters. When inserting a word, it is not required that every letter of the new word must form a word with every adjacent letter. For example, the words PROGRAM, MEMORY, NETWORK, SYSTEM and STRING at the top left are positioned along the vertical word POETS. Reading down in the next column from POETS, one gets the sequence RRTET; this is not a word, but that is irrelevant to the rules for this problem.

    Within this context, a first word may be placed anywhere on the grid. Thereafter adding a new word requires that the word connect with at least one existing letter already on the grid. If the new word would extend over several existing letters, then the corresponding letters must match. For example, in the illustration, the word RARE could be added vertically using the R in PROGRAM and the R in NETWORK. However, the word RAKE could not be added in this position. The first R would fit with the R of PROGRAM, but the K in RAKE does not match the grid element already on the grid (the R in NETWORK).

    This problem asks you to write a program to support the addition of new words for this type of word grid. In particular, the program should do the following.

    Programming Notes:

    Grading Form

  1. Singly-linked-list Processing

    Program namelist-2019-451.c contains a simple framework for maintaining a singly-linked list of names (with no more than 20 characters). The program has these features:

    This problem asks you to implement two additional functions within this program.

    Programming Hints:

    Problem-specific grading form for Supplemental Problem 2

Gemstones

  1. This problem uses multiple processes and a stored file of information to address two questions about gemstones.

    Some Backgrond concerning Gemstones

    Gemstones are attractive forms of rock crystal, commonly used for decoration and in jewelry. Gemstones also have interesting mineral properties. Gemstones may be classified in a variety of ways, including chemical composition, crystal structure, color, specific gravity, refractive index, and hardness:

    1. Chemical Composition: While some gemstones are primarily composed of atoms of one element (e.g., diamonds are mostly carbon, with coloring coming from traces of other elements), other gemstones are made up of atoms of several atoms (e.g., mica molecules include oxygen, hydrogen, silicon, aluminum, iron, and/or many others). On-line sources of information include general references (e.g., Common Mineral Groups) and references to specific minerals (e.g., micas).

    2. Color may be classified informally (e.g., red, yellow, etc.) or more formally by viewing thin slices of mineral crystals through the microscope, using polarized light (see, for example, Minerals under the Microscope).

    3. Specific Gravity is a measure of the density of a mineral. More precisely, specific gravity is the ratio of the weight of the mineral in air to its weight in an equal volume of water. More details are available from various on-line sources (see, for example, the Mineral and Gemstone Kingdom's glossary for specific gravity.

    4. Refractive Index provides a measure of how much light bends within a crystal. The higher the refractive index, the more bending and the more brilliant a crystal is likely to appear. For more information, see various on-line sources, such as Refractive Index.

    5. Crystal Structure: Crystals typically have one of several standard shapes or structures, including cubic, tetragonal, orthorhombic, hexagonal, monoclinic, and triclinic. While the details of such structures are beyond the scope of this problem, the World Wide Web contains many useful references, including crystal forms (at the macro-level).

    6. Hardness often is measured on the (nonlinear) Mohs Scale, which associates a hardness number to each mineral, from 1 (softest) to 10 (hardest):

      1. Talc
      2. Gypsum
      3. Calcite
      4. Fluorite
      5. Apatite
      6. Orthoclase
      7. Quartz
      8. Topaz
      9. Corundum
      10. Diamond

      As a comparison, a fingernail has hardness 2.5, glass has hardness 5.5, and a steel file has hardness 6.5. Minerals of the same hardness should not scratch each other, but a mineral of one hardness will scratch minerals with a lower hardness number.

    File gems.txt contains information on several gemstones, including color, hardness, specific gravity, and refractive index. Within the file, each line contains information about a specific gemstone.

    Here are a couple of sample lines, and a character 'ruler' to show how wide the fields are:

              11111111112222222222333333333344444444445555555555666666666677777
    012345678901234567890123456789012345678901234567890123456789012345678901234
    
                    Zircon        RED           7.5         4.50         1.95
                     Topaz     YELLOW             8         3.53         1.62
    

    To clarify, the names of the gemstones come first in a line and are right-justified in a column of width 22 characters. (A gemstone name may contain multiple words, but the overall width of the name field is 22 characters.) The colors come next, followed by hardness (on a scale 1 to 10), then specific gravity, and finally refractive index (generally between 1.3 and 2.5).

    Programming Tasks

    To answer the questions posed at the start of this question, five programs are to be utilized, as described below and as illustrated in the following diagram:

    gemstone processing

    Altogether,

    Sample Output

    If the user types "GREY" as the color of gemstones, processing should return a table, such as the following:

    
                                                          Specific   Refractive
                  Gemstone       Color       Hardness      Gravity      Index
    
                 Alabaster       GREY             2         2.32         1.53
                  Bakelite       GREY           2.5         1.28         1.65
                   Calcite       GREY             3          2.7         2.71
                    Casein       GREY           2.5         1.33         1.55
                  Celluoid       GREY             2         1.35         1.50
                Chalcedony       GREY             7         2.62         1.53
                  Corundum       GREY             9         3.99         3.99
                   Diamond       GREY            10         3.52         3.52
                  Hematite       GREY             6         5.10         5.05
                     Ivory       GREY           2.5         1.80         1.54
                   Jadeite       GREY             7         3.34         3.33
               Labradorite       GREY             6          2.7         2.70
                    Marble       GREY             3         2.71         1.50
                Meerschaum       GREY             2         1.50         1.53
                  Nephrite       GREY           3.5         3.00         2.96
                      Opal       GREY             6         2.10         2.10
                    Quartz       GREY             7         2.65         1.55
                    Quartz       GREY             7         3.33         2.65
                      Talc       GREY             1         2.70         2.75
    
    Another possible format might be:
    
                                           Specific   Refractive
    Gemstone Name       Color    Hardness   Gravity      Index
    
    Alabaster            GREY       2         2.32        1.53
    Bakelite             GREY       2.5       1.28        1.65
    Calcite              GREY       3         2.70        2.71
    Casein               GREY       2.5       1.33        1.55
    Celluoid             GREY       2         1.35        1.50
    Chalcedony           GREY       7         2.62        1.53
    Corundum             GREY       9         3.99        3.99
    Diamond              GREY      10         3.52        3.52
    Hematite             GREY       6         5.10        5.05
    Ivory                GREY       2.5       1.80        1.54
    Jadeite              GREY       7         3.34        3.33
    Labradorite          GREY       6         2.70        2.70
    Marble               GREY       3         2.71        1.50
    Meerschaum           GREY       2         1.50        1.53
    Nephrite             GREY       3.5       3.00        2.96
    Opal                 GREY       6         2.10        2.10
    Quartz               GREY       7         2.65        1.55
    Quartz               GREY       7         3.33        2.65
    Talc                 GREY       1         2.70        2.75
    

    As shown in each example, the gemstone names and properties must appear in labeled columns. Gemstone names may be either left-justified or right-justified.

    A similar format could be used in printing gemstone information for the second question.

    Note that some gemstones, such as Quartz above, appear several times in the table, since variations of a gemstone may have different properties.

    Problem-specific grading form for Supplemental Problem 3


Any of the following problems may be done for extra credit. As noted in the course syllabus, however, a student's overall problems' average may not exceed 120%.

Barbershop Problem Simulation

  1. Many books state variations of the Sleeping Barber Problem, which was first proposed by Edsger W. Dijkstra in 1968. (E. W. Dijkstra, "Co-operating Sequential Processes", in F. Genuys (ed.), Programming Languages, Academic Press, 1968, pp. 43-112.) This exercise considers the following version:

    Diagram of Barbershop
    Three barbers work independently in a barber shop:

    For this problem, you are to write a C program to simulate activity for this barbershop:

    1. Simulate each barber and each customer as a separate process.
    2. Altogether, 30 customers should try to enter.
    3. Use a random number generator, so a new customer arrives every 1, 2, 3, or 4 seconds. (This might be accomplished by an appropriate statement sleep(1+(rand()%4)); .
    4. Similarly, use a random number generator, so each haircut lasts between 3 and 6 seconds.
    5. Each barber should report when he/she starts each haircut and when he/she finishes each haircut.
    6. Each customer should report when he/she enters the barbershop. The customer also should report if he/she decides to leave immediately.
    7. Similarly, if the customer must stand or sit in the waiting room, the customer should report when each activity begins.
    8. Finally, the customer should report when the haircut begins and when the customer finally exits the shop.

    Problem-specific grading form for Supplemental Problem 4

Anagrams

  1. [approximately 12 points]

    Sometimes one can simplify a problem by removing the parts that don't matter, and then looking at what's left.

    For instance if you wanted to figure out if two collections of "stuff" were the same, you might remove matching items from each collection until you see if there are items left over. If you have leftover items, the collections were different, and if both collections become empty at the same time, they are identical.

    Use this technique to write a program which will determine whether or not two strings are anagrams of each other. For this program, each string should be entered on a line of its own, with no assumptions regarding the characters entered (except that the characters can be typed on a keyboard and that each string is no longer than 40 characters.

    Test it by deciding whether or not "one plus twelve" is an anagram of "eleven plus two", among other test cases.

    Note: Two programs, one iterative and one recursive, might be eligible for bonus points.

Roller Coaster with One Car and with Several Cars

  1. [Approximately 13 points]

    This exercise is a slightly modified version of exercises 4.9 and 4.10 in Stephen Hartley, Concurrently Programming: The Java Programming Language.

    An amusement park includes a roller coaster ride. Use of the roller coaster follows these rules.

    For this problem, you are to write a C program to simulate activity for this roller-coaster problem:

    1. Values m, n, S, C, and W may be set as program constants, but you may specify them as command-line arguments if you prefer.
    2. Each passenger and each car should be simulated as a separate process.
    3. Run the simulation for R seconds (default 120). (Again, this may be a program constant or a command-line argument - your choice.)
    4. Compute the average time that a passenger must wait to be seated after deciding to take a ride.
    5. Use semaphores for synchronization. (Additional communication via pipes or shared memory is allowed, but do not use such devices unless such communication is clearly needed.)


created 20 January 2019
revised 11 February 2019
revised 25 February 2019
revised 6-10 March 2019
Valid HTML 4.01! Valid CSS!
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu.