Quiz, Data Structures and Algorithms, Week 6 -- Tues Nov 6 2001

Name:

  1. Write the negation of each of these boolean expressions, without using the negation operator !:
    a.  a == b b.  x > y c.  a <= b d.  x > y && a <= b

  2. Assume this boolean expression is true:
    w == 0 && x == 1 && y == 2 && z == 3 && a == 4 && b == 6 && c == 7
    Write the value of each of the following boolean expressions:
    a.  x > y b.  a < b c.  x > y && a < b d.  x > y || a < b

    e.  b == y*z + w f.  c == y*z + x

    g.  y*y <= a && a < (y+1)*(y+1) h.  z*z <= b && b < (z+1)*(z+1)

  3. In each code fragment, assume the boolean expression in the first comment is true before the program executes the statement. Is the boolean expression in the second commentnecessarily true after the program executes the statement? (Answer yes or no)
    a.
    // true
    
    x = 1
    
    // x == 1
    
    
    b.
    
    // x > 0
    
    x = x + 1
    
    // x == 2
    
    
    
    
    c.
    
    // x == 1
    
    x = x + 1
    
    // x == 2
    
    
  4. In each code fragment, assume the boolean expression in the first comment is true before the program executes the statement. Write a boolean expression which is true after the program executes the statement.
    a.
    // true
    
    x = 3
    
    
    
    
    b.
    
    // x > 3
    
    x = x + 1
    
    
    
    
    
    
    c.
    
    // x > i
    
    x = x + 1
    
    
    
    
  5. In each code fragment, assume the boolean expression in the first comment is true before the program executes the missing statement. Write a statement that makes the boolean expression in the second comment true after the program executes the statement.
    a.
    // true
    
    
    
    
    
    // x == 6
    
    
    b.
    
    // x > 1
    
    
    
    
    
    // x > 3
    
    
    
    
    c.
    
    // x > 2
    
    
    
    
    
    // x > i + 2
    
    
  6. In each code fragment, assume the program executes the statement, and that makes the boolean expression in the following comment true. Write a boolean expression that must be true before the program executes the statement in order for this to be so.
    a.
    //
    
    
    
    x = 4
    
    // x == 4
    
    
    b.
    
    // 
    
    
    
    x = x + 3
    
    // x > 5
    
    
    
    
    c.
    
    // 
    
    
    
    x = x + i
    
    // x > i + 3