CS 105 Midterm Examination Solutions
Thursday, March 16, 2000

NAME:

Question Points Score
1 16  
2 20  
3 20  
4 12  
5 12  
6 12  
7 8  
TOTAL 100  
There are 7 questions on this examination. The point values associated with the questions are shown in the table above. You have 75 minutes to complete the examination. You should not consult any references while completing this examination. Show all answers in the spaces provided in the examination booklet. Paper for scrap work will be made available.

  1. Both on-off keying and Manchester encoding involve sudden transitions from amplitude zero to full amplitude. As a result, the graphs used to represent the actual signals transmitted using these schemes are described as "square waves" and look something like:

    For this problem, I would like you to consider the frequency with which the abrupt transitions occur using on-off keying and Manchester encoding. For each of the following questions, assume that data is being transmitted at a rate of 1000 bits per second.

  2. Indicate whether each of the following statements is true or false:

    1. The binary code used in modern computer networks is like Morse code in that Morse code uses two symbols, dot and dash, to encode all information.
      False. Morse code actually uses five symbols: dot, dash, short pause, medium pause, and long pause.

    2. In HTML, only text-level items can be made into links.
      True. The "A" tag is a text-level tag. Luckily "IMG" tags are considered "text-level items" by HTML, so images can be used as links.

    3. Increasing the amplitude of a wave decreases its period.
      False. The period of a wave is related to its frequency, but not to its amplitude. Amplitude measures the "height" of a wave rather than its "width".

    4. The number of colors stored in the palette of an image represented using 8-bit color can never be greater than 256.
      True. The 8-bit entries used for pixels are only capable of identifying 256 distinct palette entries.

    5. Frequency division multiplexing is only possible on optical fiber.
      False. Frequency division multiplexing can be used in many other transmission media. For example, frequency division multiplexing is used in radio and TV transmission (i.e. through the air). Otherwise, there could only be one TV station or one radio station.

    6. When using the token ring protocol, increasing a network's speed tends to actually decrease its efficiency.
      True. As transmission speed increases the time "wasted" waiting for the token becomes relatively more significant so the efficiency with which data is transmitted decreases. Even though the efficiency is lower, the actual transmission rate does increase.

    7. The "lossy" compression technique used in JPEG files is more likely to distort a simple diagram created with a line drawing program than a digital photograph of a complex natural scene.
      True. Since the color values needed to describe an image are encoded in a JPEG file using an approximating function based on component funtions that vary smoothly (cosine functions), images with sharp divisions between regions of different colors tend to be distorted more than images in which color transitions are gradual.

    8. The phone systems was converted from circuit switching to message switching once the original long-distance lines were replaced with fiber optic cables.
      False. Circuit switching is still used for telephone calls.

    9. Two pairs of computers can communicate simultaneously on a switched network as long as the sections of cable that connect the members of each pair do not overlap with the sections connecting the other pair.
      True.

    10. Every Ethernet card ever manufactured is given a distinct address at the factory.
      True (at least it is supposed to be true!).

  3. Each of the following samples of HTML are a) derived from pages created by CS 105 students (all from this year!), and b) examples of either incorrect or inappropriate use of HTML. I have modified the code to simplify it and to make it difficult to identify the authors. Here and there I have also replaced bits of HTML that were irrelevant to the point of the example with three dots.

    For each example, please briefly explain the problems with the HTML shown and indicate how to modify the HTML to make it correct while producing what the author appeared to have in mind. It is more important that your revised code be correct than that it perfectly capture the intent of the original. In fact, in some cases, the problems with the HTML given may be severe enough that several different interpretations of "what the author appeared to have in mind" may be possible.

    You can either clearly mark up the code shown or write a complete revision in the space provided.

    1. <FONT COLOR="#990099">
             <H3>
                YOUR LINKS TO THE WORLD!! 
             </H3>
       </FONT>
      
      Problems: It is illegal to enclose a block level tag (like <H3>) within a text level tag (like FONT).
      Correction:
      
      <H3>
          <FONT COLOR="#990099">
                YOUR LINKS TO THE WORLD!! 
          </FONT>
      </H3>
      

    2. <H2>
        <P ALIGN="Center">
            <FONT COLOR="#FF0000">
                <FONT COLOR="#00CC66">
                     People
                </FONT>
            </FONT>
        </P>
      </H2>
      
      Problems: It is illegal to nest anything but text tags within either a header tag or a paragraph tag. So, placing a P tag within an H2 tag is illegal. It is also pointless to nest two font tags specifying different colors around a single piece of text. Only the inner color setting will be effective. In correcting this code, it seems reasonable to assume that the text is intended to function as a header and that the P tag was only added to control alignment. So, it is appropriate to move the alignment attribute to the H2 tag.
      Correction:
      
      <H2 ALIGN="Center">
                <FONT COLOR="#00CC66">
                     People
                </FONT>
      </H2>
      

    3. <OL >
         <FONT COLOR= "#FF0066">
            <H4> Top Ten List</H4>
                              
                 <LI>Miami</LI>
                 <LI>Boston</LI>
      
                   ... imagine eight more items ...
      </OL>
      
      Problems: Within OL tags, only items preceded by <LI> tags are allowed. So, the FONT tag and H4 tag shown would be illegal. Also, the FONT tag needs to be closed. It is unclear whether the author's intend was to just change the color of the heading or to change the color of all the list items. Below, I have assumed the color of all the text was supposed to be changed (since this is the harder thing to do). The alternative (leaving out the FONT tags in all the LI's) would be just as reasonable a correction.
      Correction:
      
      <H4>
         <FONT COLOR= "#FF0066">Top Ten List </FONT>
      </H4>
      <OL >
            <LI><FONT COLOR= "#FF0066">Miami </FONT></LI>
            <LI><FONT COLOR= "#FF0066">Boston</FONT></LI>
      
                ... imagine eight more items ...
      </OL>
      

    4. <HTML>
      <HEAD>
      <TITLE>Image Gallery</TITLE>
      </HEAD>
      <HEAD>
      <B>
          <FONT SIZE="4">
              <FONT SIZE="6">
                   Lab #2: Image Gallery
              </FONT>
          </FONT>
      </B>
      </HEAD>
      <BODY>
      <P>
      This is a page showing the images created in lab #2 using Adobe Photoshop.
      .
      .
      .
      </BODY>
      </HTML>
      
      Problems: First, this sample has an extra set of <HEAD>...</HEAD> tags surrounding HTML that really belongs within the BODY tag pairs. Next, it has redundant FONT size specifications applied to the text "Lab ...". Finally, the combination of code to increase the font size and use boldface suggests that the text should really be treated as a header. (While appropriate, this last suggested change is not required to make the HTML correct.)
      Correction:
      
      <HTML>
      <HEAD>
      <TITLE>Image Gallery</TITLE>
      </HEAD>
      <BODY>
      <H2>
                   Lab #2: Image Gallery
      </H2>
      <P>
      This is a page showing the images created in lab #2 using Adobe Photoshop.
      .
      .
      .
      </BODY>
      </HTML>
      

    5. (Hint: This example is more subtle than the others.)
      <TABLE BORDER=0 CELLSPACING="2" CELLPADDING="1">
      
      <TR WIDTH=100% HEIGHT=25>
             <TD ALIGN=CENTER COLSPAN=3>
                  <IMG SRC=BANNER1.GIF>
            </TD>
      </TR>
      
      <TR>
           <TD ALIGN=CENTER VALIGN=MIDDLE COLSPAN=3>
                <H1>
                   YOU WANT MORE??
              </H1>
          </TD>
      </TR>
      
      <TR>
         <TD ALIGN=CENTER>
            This is me and my younger brother.
        </TD>
        <TD ALIGN=CENTER>
            <IMG SRC="siblings2.jpg">
        </TD>
      </TR>
      
      </TABLE>
      
      Problems: There were several issues with this HTML. First, the table is unbalanced. The first two rows each have three columns (due to the COLSPANS), but the last row only has two. Next, WIDTH and HEIGHT attributes are not allowed in TR tags (they must be put in TH and TD tags). While the use of an H1 tag within a TD tag is allowed, it seems less appropriate than using a TH tag rather than a TD tag. Finally, some of the values specified for attributes include special characters (periods and percent signs) so they should be quoted.
      Correction:
      
      <TABLE WIDTH="100%" BORDER=0 CELLSPACING="2" CELLPADDING="1">
      
      <TR >
             <TD HEIGHT=25 ALIGN=CENTER COLSPAN=2>
                  <IMG SRC="BANNER1.GIF">
            </TD>
      </TR>
      
      <TR>
           <TH ALIGN=CENTER VALIGN=MIDDLE COLSPAN=2>
                    YOU WANT MORE??
           </TH>
      </TR>
      
      <TR>
         <TD ALIGN=CENTER>
            This is me and my younger brother.
        </TD>
        <TD ALIGN=CENTER>
            <IMG SRC="siblings2.jpg">
        </TD>
      </TR>
      
      </TABLE>
      

  4. The diagrams below are intended to represents possible layouts for the wiring of a local area network. The lines represent the cables between machines and the little lettered circles the machines themselves.

    For each layout, indicate whether it would be a possible topology for a token ring based network, an Ethernet, neither or both.

  5. In discussing the importance of "being digital", I explained that certain non-digital forms of information, like sound and images, could not be represented perfectly in digital form but could be approximated very accurately by digital representations. For either sound or images, explain two forms of approximation present in the approaches to the digital representation of such information we discussed. For each approximation, explain how one can reduce or increase the accuracy with which the original information is preserved.
    The two issues that lead to approximation in digital images and digital sound recording are the sampling rate and the sample accuracy. In the case of images, the sampling rate is just the number of pixels per inch. The more pixels per inch, the more accurate the representation can be. In each pixel, however, there is also another form of approximation related to how many digits (bits) of accuracy are used to represent the color of the pixel. The fewer digits used to represent colors, the more approximate each pixels color will be. Thus, 24-bit color is more accurate than 8 bit color.

    In the world of digital sound, the sampling rate is simply how many times per second the amplitude of the sound wave is measured. The sample accuracy is determined by the number of digits used to represent the amplitude at a given time. When discussing the phone system, I mentioned that 8 binary digits are used to represent the amplitude of each sample of the sounds sent through a phone call. Thus, only 256 different sound amplitudes can be represented exactly. Amplitudes that fall between these 256 values must be rounded (approximated) up or down.

  6. Imagine a token ring connecting N computers. Assume that the computers are evenly spaced around the perimeter of the ring. Assume that each machine has a message containing B bits that it is waiting to send, that the distance between any two stations is D, that each machine transmits R bits per second and that the signal travels a the speed c = 3 x 108 meters per second.

  7. The Java code for a simple applet very similar to the one you constructed in lab is shown below. To make it a bit easier to describe the applet's behavior I have replaced the images used in lab with two images that are not quite so similar. Namely, the image file "clickBut.gif" contains an image that looks like:
    and the file "homeBut.gif" contains the familiar image:

    Examine the code shown and answer each of the questions following the code.

    public class ActiveButton extends Controller
    {
       VisibleImage pic1;
       VisibleImage pic2;
       
          /* Specifies what to do when the applet first comes to life */      
       public void begin(){
          pic1 = new VisibleImage(getImage("clickBut.gif"),0,0);
          pic2 = new VisibleImage(getImage("homeBut.gif"),0,0);
       }
                 
          /* Specifies how to react when the mouse button is depressed */      
       public void mouseDown() {
          loadPage("http://www.cs.williams.edu/~cs105s00");
       }
          
          /* Specifies how to react when the mouse is moved into the applet's
             screen window */      
       public void mouseEnter() {
          pic2.hide();
       }
          
          /* Specifies how to react when the mouse is moved out of the applet's
             screen window */      
       public void mouseExit() {
          pic2.show();
       }      
    
    }
    

    1. Like the applet you produced in lab, this applet switches between displaying "clickBut" and "homeBut" as you move the mouse in and out of the image area. Which button will be displayed when the mouse is positioned within the image?
      The "clickBut" image will be visible when the mouse is within the image.

    2. How (if at all) would the behavior of the program change if the two commands in the body of the begin method were interchanged so that the method looked like:
            /* Specifies what to do when the applet first comes to life */      
         public void begin(){
            pic2 = new VisibleImage(getImage("homeBut.gif"),0,0);
            pic1 = new VisibleImage(getImage("clickBut.gif"),0,0);
         }
      
      With this change, the image that was on the bottom of the stack would be hidden when the mouse entered the image area rather than the image on top so no visible change would occur.