Discussion 2

advertisement
Discussions 10 and 11
Fall 2011
October 25 and 26
November 1 and 2
1. Relations
a. Find the properties of the following relation: R = {(a, b)N  N | a + b is even}
Also give counterexamples when the property does not hold.
Reflexive: Let a  N. Since a + a = 2a for all natural numbers a, and 2a is even, R is
reflexive. Stress that they must show (a, a)  R for every a  N
Symmetric: If (a, b)  R, then a + b = 2k for some integer k.
Then, b + a = 2k also, so (b, a)  R. Thus, R is symmetric.
Clearly, R is not irreflexive, antisymmetric or asymmetric (explain why), so the only thing
we have left to consider is the transitive property. Suppose (a, b)  R and (b, c)  R.
Then, there are integers j and k such that
a + b = 2k and b + c = 2j Thus,
a + c + 2b = 2k + 2j
a + c = 2k + 2j -2b
a + c = 2(k + j - b)
Since a + c is even, (a, c)  R and R is transitive.
b. Prove that if R is a nonempty reflexive and transitive relation on S then, then R  R-1 is
an equivalence relation.
Let (a, b)  R  R-1.
Then (a, b)  R and (a, b)  R-1.
Then, (b, a)  R and (b, a)  R-1
Thus, (b, a)  R  R-1
Therefore R  R-1 is symmetric
Defn. of intersection
Defn of inverse
Defn of intersection
Defn. of symmetric (a, b)  R  (b, a)  R
c. If n(A) = 30 and the equivalence relation R on A partitions A into equivalence classes A 1,
A2, and A3, where n(A1) = n(A2) = n(A3), how many ordered pairs are in R?
d Start with A = {1, 2, 3, 4}. Find nonempty relations on A with the following characteristics:
1) irreflexive and antisymmetric
2) symmetric and transitive but not reflexive
3) any others you you’d like to do
e. Prove the complement of a symmetric relation is symmetric.
Proof: Let R be a symmetric relation on a set A.
Let (a, b) be an element of R′.
(a, b)  R
Definition of complement
(b, a)  R
Definition of symmetric and R is symmetric
(b, a)  R′
Definition of complement
Therefore R′ is symmetric
Definition of symmetric
f. Let A = {1, 2, 3, 4, 6, 8, 12, 18, 24}. Construct a Hasse diagram for R = {(a, b) | a | b}
g. Using the Hasse diagram below, list all ordered pairs that contain c, and explain how to
determine the total number of ordered pairs in this partial order.
2.
The reflexive (symmetric, transitive) closure of a relation R is the smallest reflexive
(symmetric, transitive) relation that contains R. That is, only enough ordered pairs are
added to the relation in order to get a new relation with the desired property.
a. Let R be the relation on {1, 2, 3, 4} defined by R = {(1, 2), (1, 4), (2, 3), (3, 1), (4, 2)}.
Then, find the following:
1) reflexive closure of R Ans. {(1, 1), (1, 2), (1, 4), (2, 2), (2, 3), (3, 1), (3, 3), (4, 2), (4, 4)}
2) symmetric closure of R Ans. {(1, 2), (1, 3), (1, 4), (2, 1) (2, 3), (2, 4), (3, 1), (3, 2),
(4, 1), (4, 2)}
3) transitive closure of R Ans. A x A
b. Find the smallest equivalence relation on {a, b, c, d, e} that contains the relation
{(a, b), (a, c), (b, d), (d, e)}.
c. Find the smallest partial order on {a, b, c, d, e} that contains the relation
{(a, b), (a, c), (b, d), (d, e)}.
d. Draw the Hasse diagram for the divides relation on set A = {2, 3, 4, 6, 8, 9, 12, 18}.
e. If n(A) = 30 and the equivalence relation R on A partitions A into equivalence classes A1,
A2, and A3, where n(A1) = n(A2) = n(A3), how many ordered pairs are in R?
f. Prove that if R is a partial order on set A then R-1 is also a partial order on A. Be sure to
prove all three properties.
These will be done November 2 and 3.
3. Big-O proofs. Unless a sum or product rule is used, all big-O, big- proofs are to be done
by using the appropriate definition.
a. big-O proofs
1) Prove that if f(x) = 3x3 + 4x +6 then f(x)  O(x3).
2) First state the definition of big- and then use it to prove that f(x)  (x3)
3) Negate the definition of big-O and then prove that f(x) O(x2).
b. Additional examples of big-O and big- proofs and disproofs:
1) n lg n  O(n2) but n2  O(n lg n)
2) 2n2 + n – 7  (n2) Do both the big-O and big- proofs
3) If f(n)  O(g(n)) and g(n)  O(h(n)) then f(n)  O(h(n))
4) any additional examples you’d like to do.
c. Prove that (x2 + 1)/(x + 1) = O(x).
d. Use the sum and product rules to find the best big-O complexity for these:
1) (x! + 2x)(x3 + log(x2 + 1))
2) x•lg(x2 + 1) + x2•lg x
e. Using complexity measures to estimate run time. Algorithms A and B each take one
second on 20 data items. If A uses c•n2 time for n items and B uses d•2n for n items,
how long does each algorithm take on 40 data items? on 100 data items?
4. Algorithm analysis
Consider the following program segments.
a. Set up and solve summations to determine how many times the print statement is executed.
for i  1 to 20 do
for j  1 to i do
for k  1 to j do
print(i*j + k)
b. Set up and solve a summation to determine the value of sum when the code terminates.
sum  0
for i  1 to n
for j  1 to n2
for k  1 to j
sum  sum + 1
Download