Docsity

Assertion Worksheet for COMP 401 Spring 2008 - Prof. S. F. Weiss, Assignments of Computer Science

Toggle sidebar
bg1
401-18.1
COMP 401
Spring 2008
Assertion worksheet
What is the English equivalent for each of these assertions?
Assume that a and b are arrays [0...n] of integer and key, x, and y are integer variables.
1. {Ai: 0 <= i <= n: a[i] == 0}
2. {Ai: 0 <= i < n: a[i] <= a[i+1]}
3. {Ei: 0 <= i <= n: a[i] == 0}
4. {Ei: 0 <= i < n: a[i] > a[i+1]}
5. {Ai: 0 <= i <= n: Ej: 0 <= j <= n: |a[i]-a[j]| == 1} |x| indicates the
absolute value of x
6. {Ei: 0 <= i <= n: a[i] == key && Aj: 0 <= j < i: a[j] != key}
7. {Ai: 0 <= i <= n: a[i] == b[i]}
8. {Ai: 0 <= i <= n: a[i] == a[n-i]}
Translate each of the following into a formal assertion
9. None of the elements in a[lo...hi] is equal to zero. Assume 0 <= lo <= hi <= n.
10. All of the elements of a are even.
11. Some of the elements of a are odd.
pf2

Partial preview of the text

Download Assertion Worksheet for COMP 401 Spring 2008 - Prof. S. F. Weiss and more Assignments Computer Science in PDF only on Docsity!

COMP 401

Spring 2008 Assertion worksheet What is the English equivalent for each of these assertions? Assume that a and b are arrays [0...n] of integer and key, x, and y are integer variables.

  1. {Ai: 0 <= i <= n: a[i] == 0}
  2. {Ai: 0 <= i < n: a[i] <= a[i+1]}
  3. {Ei: 0 <= i <= n: a[i] == 0}
  4. {Ei: 0 <= i < n: a[i] > a[i+1]}
  5. {Ai: 0 <= i <= n: Ej: 0 <= j <= n: |a[i]-a[j]| == 1} |x| indicates the absolute value of x
  6. {Ei: 0 <= i <= n: a[i] == key && Aj: 0 <= j < i: a[j] != key}
  7. {Ai: 0 <= i <= n: a[i] == b[i]}
  8. {Ai: 0 <= i <= n: a[i] == a[n-i]} Translate each of the following into a formal assertion
  9. None of the elements in a[lo...hi] is equal to zero. Assume 0 <= lo <= hi <= n.
  10. All of the elements of a are even.
  11. Some of the elements of a are odd.
  1. Exactly one element of a is equal to zero. Easier: use count; more difficult: use A and E.
  2. The arrays a and b are exactly the same except that in b, a[x] and a[y] have been swapped. There is often more than one way to indicate the same thing. All of the following assertions are equivalent. What do they say?
  3. {Ai: 0 <= i <= n: a[i] != 0} {!Ei: 0 <= i <= n: a[i] == 0} {(Ni: 0 <= i <= n: a[i] == 0) == 0} {(Ni: 0 <= i <= n: a[i] != 0) == n+1} Why is this one not the same? {(Sum i: 0 <= i <= n: a[i]) != 0}
  4. Specify “all elements of the array a are greater than zero” using: Universal quantifier Existential quantifier Count quantifier (two ways) Min quantifier
  5. Why is it hard to specify "Array b is the sorted version of array a"? Hint: it's easy to assert that b is sorted, but why isn't this enough? What additional assertion would make this much easier?