Assignment 1, due Sep 1

Solutions

Part of the homework for CS:2820, Fall 2017
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

  1. Background: Consider these two Java declarations:

    int i = 1 + 'a';
    String j = "a" + 1;
    

    a) What operation does the + operator do on the first line? (0.3 points)

    Integer addition.

    b) What is the resulting value of i? (0.2 points)

    A value that can be printed as either 'b' or 98.

    c) What operation does the + operator do on the second line. (0.3 points)

    String concatenation.

    d) What is the resulting value of j? (0.2 points)

    The string "a1".

  2. Background: In the notes for Lecture 4, there is a table of the 16 Boolean functions of 2 variables. If you read the row labels in this table as binary numbers, then function number 1 is and, function 7 is or, and function 14 is nand.

    a) Give the truth table for the 2-input function called a or not b. (0.3 points)

    The truth table for a or not b
               
    inputsoutput
      a     b     a | ¬b
    0 0 1
    0 1 0
    1 0 1
    1 1 1
               

    b) What is the function number of the function in part a in the table of 16 functions. (0.2 points)

    1011 binary or 11 decimal.

    c) Give the truth table for the 2-input function called a and not b. (0.3 points)

    The truth table for a and not b
               
    inputsoutput
      a     b     a & ¬b
    0 0 0
    0 1 0
    1 0 1
    1 1 0
               

    d) What is the function number of the function in part c in the table of 16 functions. (0.2 points)

    0010 binary or 2 decimal.

  3. Background: In lecture 3, we propose to model a road network using one-way roads between intersections. Once a vehicle enters a road, it is required to follow that road to the next intersection. All manuvering required by our model must therefore take place at intersections, so we must introduce intersections at each point where a driveway enters or exits the road network, and if we model each lane as a separate road, then if we want to model lane changes in midblock, we must introduce an intersection at that point.

    Consider the problem of modeling the University of Iowa pentacrest, with these streets if we ignore the complexity of the bus interchange:

    These streets also play a part, some only because they add intersections to the model:

    Wherever 2 lanes go the same direction between intersections, lane changes are allowed.

    A problem: Draw a diagram, with points for every intersection and arrows connecting the points showing how this road network would be modeled. Include both real intersections and the intermediate intersections that must be added in order to model lane changes. The arrow head on each "road" indicates the direction of travel on that road.

    Legibility matters. Lay out your diagram with north on the top and try to keep the topology the same as the real road network. Exact scale does not matter, but You might start by using a blow-up of a map as a layout guide (there are plenty of on-line map services). If your drawing skills are horrible, you may have to redraw a few times to get legible results.

    Drawing of graph representation of road network

    The parts of the above table shown in light grey are outside the scope of the assignment and given only because they provide context for what was required here. The mid-block intersections that join two parallel "roads" going in the same direction represent the opportunity to change lanes in midblock between two real intersections.