Worksheet, Data Structures and Algorithms, Week 6 -- Thurs Nov 1 2001

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

  2. Assume this boolean expression is true:
    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.  !(x < y && a > b) f.  x >= y || a <= b g.  x < y && !(a > b) h.  x < y && a <= b
    i.  c == y*z + x j.  y*y <= a && a < (y+1)*(y+1)
    k.  y*y <= b && b < (y+1)*(y+1) l.  z*z <= b && b < (z+1)*(z+1)

  3. In each code fragment, assume the boolean expression in the first comment is true when execution reaches the first statement in the fragment. Is the boolean expression in the second comment necessarily true when execution exits the fragment?
    a.
    // true
    
    x = 1
    
    // x == 1
    
    
    b.
    
    // x == 1
    
    x = x + 1
    
    // x == 2
    
    
    c.
    
    // true
    
    x = 1 
    
    x = x + 1
    
    // x == 2
    
    
    d.
    
    // true
    
    x = x + 1
    
    // x == 2
    
    
    e.
    
    // x == 1 
    
    x = x + 1
    
    // x > 2
    
    
    f.
    
    // x > 1 
    
    x = x + 1
    
    // x ==  2
    
    
    g.
    
    // true 
    
    r = n
    
    q = 0
    
    // n = q*d + r
    
    
    h.
    
    // n = q*d + r
    
    r = r - d
    
    q = q + 1
    
    // n = q*d + r