CS 381 Final Exam



May 8, 2002



1. State the following formula in English, where the universe is the set of objects and the meaning of the predicate symbols are as follows:



$B(x)$: $x$ is a book.
$D(x,y)$: $x$ is difficult for $y$.
$E(x,y)$: $x$ is expensive for $y$.
$P(x)$: $x$ is a person.



(a) $\forall x \forall y [[B(x) \wedge P(y)] \rightarrow [D(x,y)
\wedge E(x,y)]]$



Every book is difficult and expensive for everyone.



(b) $\forall x [B(x) \rightarrow [\exists y [ P(y) \wedge D(x,y) ] \vee
\exists y [ P(y) \wedge E(x,y) ] ] ]$



Every book is either difficult for someone or expensive for someone.



(c) $\forall x [B(x) \wedge \exists y [P(y) \wedge E(x,y)]]$



Everything is a book and expensive for someone.




2. Express the assertions given below as propositions of predicate logic using the following predicates. The universe is the set of objects.



$C(x)$: $x$ is a composite number.
$D(x,y)$: $x$ is divisible by $y$.
$N(x)$: $x$ is a natural number.
$P(x)$: $x$ is a prime number.



a) Every natural number is prime.



$\forall x [N(x) \rightarrow P(x)]$



b) 3 is prime.

$P(3)$



c) For an integer to be composite, it is necessary that the integer is divisible by some prime number.



$\forall x [ [I(x) \wedge C(x) ] \rightarrow \exists y D(x,y)]$

3. Recursively define the set of powers of 2 including negative powers, that is, the set $ \{ ... 1/4, 1/2, 1, 2, 4, 8, ... \}$.



Let S denote the set of powers of 2.
Basis Clause: 1 is in S.
Inductive Clause: For any number x, if x is in S then x/2 and 2x are in S.
Extremal Clause: Nothing is in S unless it is obtained from the above two clauses.

4 (a) Express the argument given below as propositions of propositional logic using the symbol suggested for each proposition.
(b) Check whether or not the reasoning is correct. Give your reasons.



If my program is not correct ($\neg M$), then the seat must have been double booked that day($D$).
Either the seat was not double booked or the agent saw the double booking ($A$).
If the flight was not overbooked on October 10 ($\neg P$), the agent did not see the double booking.
Furthermore if the flight was overbooked on October 10, then the seat was double booked and also no more seats were available ($\neg S$).
But we all know that there were some seats available.
Therefore my program is correct.



(a) $\neg M \rightarrow D $
$\neg D \vee A$
$\neg P \rightarrow \neg A$
$P \rightarrow [D \wedge \neg S]$
$S$
---------
$M$
(b) Since $S$ holds, $D \wedge \neg S$ is false.
Hence from $P \rightarrow [D \wedge \neg S]$ by modus tollens $\neg P$.
Hence from $\neg P \rightarrow \neg A$
by modus ponens $\neg A$.
Hence from $\neg D \vee A$ by disjunctive syllogism $\neg D$.
Hence from $M \rightarrow D $ by modus tollens $\neg M$.



5. Which of the following statements are true and which are false ?



(a) "For Mary to be happy it is necessary that John is with her" is logically equivalent to "If Mary is happy, then John is with her". True
(b) $\emptyset \in \emptyset$ False
(c) $\{ x \} \subseteq \{ x \}$ True
(d) $A - (B - C) = (A - B) \cup C$, where $A,B,C$ are sets. False
(e) The relation < (less than) over the set of natural numbers is a partial order. False
(f) The relation Big-Oh on the set of functions is a total order. True
(g) If a relation is irreflexive and transitive, then it is antisymmetric. True
(h) For a poset, if all the maximal elements are maximum and also if all the minimal elements are minimum, then the order is a total order. False
(i) If a function is one-to-one, then it has an inverse function. False
(j) The function $x^{2}$ over the set of nonnegative real numbers is a bijection. True



6 (a) Prove that $\Theta (f)$ is an equivalence relation over the set of functions.



(1) $\Theta$ is reflexive. For since $\lim_{n \rightarrow \infty} f(n)/f(n) = 1$ $f(n) = \Theta (f(n))$.



(2) $\Theta$ is symmetric. For $f(n) = \Theta (g(n))$ if and only if $f(n) = O(g(n))$ and $g(n) = O(f(n))$, which also means $g(n) = \Theta (f(n))$.



(3) $\Theta$ is transitive. To prove this, let us first prove that big-oh is transitive.
$f(n) = O(g(n))$ if and only if there exist constants $c_{1}$ and $n_{1}$ such that $\mid f(n) \mid \leq c_{1} \mid g(n) \mid$ for all $n \geq n_{1}$.
Also $g(n) = O(h(n)$ if and only if there exist constants $c_{2}$ and $n_{2}$ such that $\mid g(n) \mid \leq c_{2} \mid h(n) \mid$ for all $n \geq n_{2}$.
Let $n_{0}$ be the larger of $n_{1}$ and $n_{2}$.
Then $\mid f(n) \mid \leq c_{1} \mid g(n) \mid$ and $\mid g(n) \mid \leq c_{2} \mid h(n) \mid$ for all $n \geq n_{0}$.
Hence $\mid f(n) \mid \leq c_{1} c_{2} \mid h(n) \mid$ for all $n \geq n_{0}$.
Hence $f(n) = O(h(n))$. Thus big-oh is transitive.



If $f(n) = \Theta (g(n))$ and $f(n) = \Theta (g(n))$, then $f(n) = O(g(n))$ and $g(n) = O(h(n))$. Hence by the transitivity of big-oh, $f(n) = O(h(n))$.
Similarly since $h(n) = O(g(n))$ and $g(n) = O(f(n))$, $h(n) = O(f(n))$.
Hence we can conclude that $f(n) = \Theta (h(n))$.
Thus $\Theta$ is transitive.



Since $\Theta$ is reflexive, symmetric and transitive, it is an equivalence relation.



(b) Give two elements of the equivalence class $[ x^{2} ]$ for the relation $\Theta (f)$.



Any quadratic functions will do. For example, $3x^{2} + x + 1$, $x^{2} -10x + 2$ etc.



7. Prove by mathematical induction the following:



(a) $\Sigma_{i=1}^{n} i^{3} = n^{2} (n+1)^{2}/4$

(b) The Bubble Sort sorts keys by comparing pairs of keys in adjacent locations and interchanging them if they are out of order. For example to sort the array of numbers 10, 8, 6, 4, 2 in increasing order, it first compares 10 and 8. Since 10 is larger, it is interchanged with 8 to get 8, 10, 6, 4, 2. Next 10 is compared with 6. Since 10 is larger, it is interchanged with 6 to get 8, 6, 10, 4, 2. Two more iterations produces 8, 6, 4, 2, 10. That is the largest number in the array has been brought to the rightmost location.
Then the process starts all over from the first location to bring the next largest number to the next rightmost (next to 10) location, that is, 6, 4, 2, 8, 10 is obtained.
Similarly 6 is percolated up next to get 4, 2, 6, 8, 10, and finally 4 and 2 are interchanged to arrive at the sorted array 2, 4, 6, 8, 10.



In the above example the number of comparisons used is 4 + 3 + 2+ 1 = 10. If there are six numbers in the array and they are ordered from the largest to the smallest, then we need 5 + 4 + 3 + 2 + 1 = 15 comparisons to sort them.
In general it seems to take (n-1) + (n-2) + ... + 2 + 1 = n(n-1)/2 comparisons to sort n numbers if they are arranged from largest to the smallest in the array.
Now the question: Prove by mathematical induction that it does take n(n-1)/2 comparisons to sort numbers into increasing order that are stored in an array in decreasing order.





S. Toida
2003-12-05