Loading Web-Font TeX/Math/Italic
JMU JMU - Department of Computer Science
Help Tools
Sample Questions for Exam 2


  1. Choose the best answer to each of the following:
    (1) _____ The degree (or valency) of a vertex is:
    1. Its connected forest
    2. Its geographic extent
    3. The number of links incident to it
    4. Its walk
    (2) _____ A graph which contains no circuits is said to be:
    1. A walk
    2. Directed
    3. A giraffe
    4. A forest
    (3) _____ A label correcting algorithm for finding shortest paths:
    1. Visits each node at most once
    2. Only works for distances, not for times
    3. Can select candidates using the Euclidean distance
    4. All of the above
    (4) _____ A "great circle" is:
    1. A vertex
    2. A norm
    3. A map projection
    4. A section of a sphere that contains a diameter of the sphere
    (5) _____ Which of the following is a type of automatic vehicle location system?
    1. Dead Reckoning System
    2. Contiguous Encapsulation System
    3. Discrete J-Bus System
    4. None of the above
    (6) _____ In an even parity checksum scheme:
    1. The parity bit is set to make the number even
    2. The parity bit is set to make the data word flat
    3. The parity bit is set to make the number of bits containing ones even
    4. None of the above
    (7) _____ The RS232-C protocol:
    1. Uses timing to reduce errors
    2. Only works with DB-9 connectors
    3. Is only used to connect terminals to modems
    4. None of the above
    (8) _____ GPS satellites transmit:
    1. The location of each GPS receiver
    2. The location of beacons at intersections
    3. The date and time
    4. None of the above
  2. Assuming all streets are one way, show how a street network can be represented as a graph in which the vertices/nodes correspond to streets and the links/arcs correspond to turning movements.
  3. Given the following illustration of a directed graph (where the numbers next to an edge/link represent its "length"):
    network.gif

    calculate the "shortest" path from vertex/node 0 to vertex/node 8 using Dijkstra's label setting algorithm. Show your work in the tables next to each vertex/node (i.e., each time you change the label associated with a vertex/node you must add a row to the associated table that contains the new label and the new predecessor).

  4. Given the following illustration of a 4-heap:
    heap.gif
    1. Change the 62 to a 49 and perform a "sift up".
    2. Change the 46 to a 17 and perform a "sift up".
    3. Remove the smallest element by swapping the "front" and "back" elements, removing the new "back" element, and performing a sift down.
    4. Add a new element (with a value of 27) by making it the "back" element and performing a sift up.
  5. Given the following (poorly designed) Node class:
    public class Node
    {
        public int              label;
        public String           id;    
    }
        

    complete the following GroupedCollection class:

    import java.util.*;
    
    /**
     * A GroupedCollection is a collection of Node objects.
     * Each node is kept in a "bucket" that corresponds to 
     * an intervale of labels.
     *
     * For example, if the maximum label is 100 and the 
     * number of buckets is 2, then the Node objects are
     * kept in two buckets, one containing Node objects with
     * labels in the interval [0, 50] and one containing Node 
     * objects with labels in the interval [51, 100].
     * corresponding to its label.
     */
    public class GroupedCollection
    {
    
    
    
        
    
        /**
         * Explicit Value Constructor
         *
         * @param maxLabel    The value of the largest possible label
         * @param numBuckets  The number of buckets
         */
        public GroupedCollection(int maxLabel, int numBuckets)
        {
    
    
    
    
        }
        
    
    
        /**
         * Add a Node to this GroupedCollection (i.e., put
         * it in the appropriate bucket)
         *
         * Note: This method assumes that the Node is not
         *       already in this GroupedCollection
         */
        public void addNode(Node node)
        {
    
    
    
    
    
    
    
    
    
    
    
    
        }
        
    
    
        /**
         * Get the Node with the smallest label (and remove it
         * from this GroupedCollection)
         *
         * @retun  The appropriate Node
         */
        public Node getNodeWithSmallestLabel()
        {
    
    
    
    
    
    
    
    
    
    
    
    
    
    
        }
        
    
    
        /**
         * Modify the label of a Node that is already
         * in this GroupedCollection (and move the Node
         * to the correct bucket)
         *
         * @param node      The Node to modify
         * @param newLabel  The new label for this Node
         */
        public void modifyNode(Node node, int newLabel)
        {
    
    
    
    
    
    
    
    
    
    
    
    
    
    
        }
    }
        
  6. Find the "distance" between the following points (1,0) and (4,4) using each of the following metrics:
    The metric generated by the Euclidean norm


    The metric generated by the rectilinear norm


    The metric generated by the supremum norm


    The "Post Office" metric


  7. Recall that the minimum distance between a point, c, and the line A through the points a and b is given by: d(c, A) = \frac{ | (a_{2}-b_{2})c_{1} + (b_{1}-a_{1})c_{2} + (a_{1}b_{2} - b_{1}a_{2}) | }{||a-b||}

    Using this, find the minimum distance between each of the following points and the line segment connecting the points (1,1) and (4,4).

    (3,1)


    (2,2)


    (5,4)


    (4,1)


  8. Evaluate each of the following expressions related to checksums (where is the bitwise exclusive or operator, and is the modulo operator). Your answer must be in decimal (i.e., base 10).
    16 ^ 16


    (7 + 4) % 8


    (211 + 32) % 256


    1 ^ 2 ^ 3 ^ 4


  9. I've developed a messaging system for cars and trucks called JMUmble. In this system, arriving messages are handled by a PostOffice object. Depending on how the system is configured at runtime, one or more objects might need to know when a message arrives. I have currently implemented several such classes: Flasher (which makes a light near the speedometer flash), PopularityTimer (which starts a clock on your radio that show the amount of time since the most recent message arrived), and Mumbler (which uses speech generation to read the name of the person that sent the message -- this is where the system got its name). Use the observer pattern to develop a class model of this system (in UML). You do not need to include the attributes of each class, only the operations/methods. Include comments that describe each operation/method.
  10. Subdivide the following "map" using a point quadtree. Your solution must contain at most one point in any quadrant.
    quadtree-data.gif
  11. Given the Point class discussed in lecture, trace the execution of the following application (that was developed as part of a system for partitioning spatial data):
    public class Subdivide
    {
        public static Point      i, j, one, startMax, startMin;
        
    
        public static void main(String[] args)
        {
           double[]        v;
    
    
           // Create the unit vector i = (0,1)
           v = new double[2];
           v[0] = 1.0;
           v[1] = 0.0;
           i = new Point(v);
           
    
           // Create the unit vector j = (1,0)
           v[0] = 0.0;
           v[1] = 1.0;
           j = new Point(v);
           
           // Create the vector one = (1,1);
           one = i.plus(j);       
    
           // Create the vector lowerLeft = (0,0)
           v[0] = 0.0;
           v[1] = 0.0;
           startMin = new Point(v);
    
           // Create the vector upperRight = (4,4)
           v[0] = 4.0;
           v[1] = 4.0;
           startMax = new Point(v);
           
           // Quarter the rectangle formed by (0,0) and (4,4)
           quarter(startMin, startMax);
        }
        
    
    
    
        public static void quarter(Point min, Point max)
        {
           Point               delta, rho, tmin, tmax;
           
    
           System.out.println("Min: "+min+"     Max: "+max);
           
    
           rho   = max.minus(min);       
           delta = rho.times(0.5);
           
           if (delta.gt(one))
           {
              // NW
              tmin = min.plus(j.ctimes(delta));
              tmax = tmin.plus(delta);
              quarter(tmin, tmax);
              
              // NE
              tmin = min.plus(delta);
              tmax = tmin.plus(delta);
              quarter(tmin, tmax);
              
              // SE
              tmin = min.plus(i.ctimes(delta));
              tmax = tmin.plus(delta);
              quarter(tmin, tmax);
              
              // SW
              tmin = min;
              tmax = tmin.plus(delta);
              quarter(tmin, tmax);
           }
        }
        
    }
        
  12. Assume the universe is flat (i.e., a plane). Further, assume that you know that you are 3 units from a satellite located at (2,3) and you are 1 unit from a satellite located at (4,1). Determine your possible location(s) graphically.
  13. Consider the following system of nonlinear equations:

    y = 10 + x^{2}

    y = 2 + x^{4}

    You must find non-negative values of x and y that solve this system. Specifically, you must use the Golden Section algorithm to find the value of x that minimizes:

    [(10 + x^{2}) - (2 + x^{4})]^{2}

    Show three iterations of the Golden Section algorithm starting with a lower bound of L = 0 and an upper bound of R = 3.

Copyright 2025