Sample Solutions in Lectures |
Symbolic Logic |
only (a) and (b) are propositions. If we denote by p and q respectively the propositions (a) and (b), then
In general, when p and q are propositions, p q (i.e. ''p and q'') for example is true (T) if and only if both p and q are true. The precise effect or truth values for the above connectives can be summerized in the following truth tables
In fact we can take these tables as the precise definitions for the corresponding connectives. Likewise one way of describing completely a compound proposition is to give explicitly its truth table. Conversely, we note that a truth table can also be used to define a compound proposition.
Solution We first construct below the truth table for the two compound propositions
Since the last two columns are the same, we conclude ( p) ( q) and (p q) are equivalent.
Solution This is manifested in the following truth table
because the corresponding truth values differ (at 2 places).
Solution From the following truth table
We see (p q) ( p) is always true and is thus a tautology and (p q) ( p) is always false and is thus a contradiction.
Row 1: | ''I buy shares'' (p true) and ''I'll be rich'' (q true) is certainly consistent with (p q) being true. |
Row 2: | ''I buy shares'' and ''I won't be rich'' means ''If I buy shares then I'll be rich'' (i.e. p q) is false. |
Row 3 and 4: | ''I don't buy shares'' won't contradict our statement p q, regardless of whether I'll be rich, as obviously there are other ways to get rich. |
Switching Circuits and Boolean Algebra |
Solution This is because for any switching systems x and y, we have that x+y, x y and x' are all still switching systems with the same state space S.
Note Binary operator or operation has nothing to do with binary numbers.
Solution We need to show B1 -- B5, by letting ''+'', '''' and '''' specifically denote switches in parallel, in series and in complementation respectively. The identities in B1 are valid because
The proof of B2 -- B5 is elementary. Hence we'll simply show only the first half of B3, i.e. a + (b c) = (a + b) (a+c). We'll show the identity by the use of the evaluation table below
Solution No. Because neither the 1st half of B3 nor the 2nd half of B5 is satisfied. For example,
1 + (2 3) (1 + 2) (1 + 3).
Solution Since this question is marked by a pair of solid arrows on the margin, it is entirely optional and is not examinable. I'll thus save it for one of those bored evenings or sleepless nights.
Solution Since p q is equivalent to ( p) q, we see that (p q) r is equivalent to ( (p q)) r which is thus converted to (p + q)' + r.
(x+y)' = x' y', (x y)' = x' + y'.
Solution Proof obvious from the theorem in the previous lecture.
Boolean Functions |
Solution From the following truth table
We see that only two rows will actually contribute to the final Boolean expression
f(x,y,z) = xy'z' + xyz
where the binary operator '''' is omitted for simplicity.
Solution First we observe
Since f is not identical to 0 or 1, and its equivalent expression x has only 1 product term and 1 literal in total, this equivalent Boolean expression must be a minimal representation of f.
Solution Since f is already in canonical form, once we convert (a)--(d) into canonical forms we should see that the newly obtained canonical forms are in exactly the same form as f itself. For (a), for instance, we have
which is same as f. We can also derive (a)--(d) from f directly. For (c), for instance, we have
It is easy to see that expressions (a)--(d) all have 3 product terms. However (a) and (d) both have 7 literals while (b) and (c) both have only 6 literals. Hence neither (a) nor (d) is a minimal representation. We finally note that (b) and (c) in example 4 are minimal representations.
Solution
Solution Since every Boolean expression can be represented by some AND-gates, OR-gates and NOT-gates, if we can construct these 3 types of gates with NAND-gates alone, then we have shown that any Boolean expression can be presented by just the NAND-gates. Since we can construct NOT-gates via
AND-gates via
and OR-gates via
because (p'q')'=p+q, we conclude that NAND-gates alone are enough to represent any Boolean expressions.
Karnaugh Maps |
are both valid grids, and there are other possible valid grids as well.
where , , and are the 4 neighbours of the shaded box.
is a typical grid and shaded box has 5 neighbours , , ..., .
is a 2 2 block representing
In other words, the block of 4 is simplified to a single product term y (with 1=N-M=3-2 literals)
is a 2 4 block representing z.
Notice that in a typical term w'x'y'z in the block, the variable names w, x and ymay change inside the circled block, and are thus not present in the final product term which becomes z.
Solution
the the simplification procedure is as follows.
wy + yz + w'y' + x'y'z'
then
which gives 5 product terms (corresponding to 5 circles). However, if we drop the block of 4 circle, we still have all the 1's circled. But the new and equivalent expression will only have 4 product terms.
With our normal procedure, nevertheless, we'll arrive at the correct answer represented by
Propositional Logic |
Solution From the table
we see all critical rows (in this case, those with the shaded positions all containing a T) correspond to (the circled) T(true) for r. Hence the argument is valid.
Solution
We see that on the 3rd row, a critical row, the premise p q is true while the conclusion p q is false. Hence the argument (p q, p q ) is invalid.
p q, q r, p s t, r, q u s, t | (*) |
Solution We'll treat all the rules of inference introduced earlier in this subsection as the known elementary argument forms. The logical inference for the argument form in the question is as follows.
(1) | q r | premise | r | premise | q | by modus tollens |
(2) | p q | premise | q | by (1) | p | by disjunctive syllogism |
(3) | q u s | premise | q | by (1) | u s | by modus ponens |
(4) | u s | by (3) | s | by conjunctive simplification |
(5) | p | by (2) | s | by (4) | p s | by conjunctive addition |
(6) | p s t | premise | p s | by (5) | t | by modus ponens |
Solution In the following we shall give the ''reverse route'' for the proof of the above argument form. Basically we shall start with the conclusion t (marked by below), then go downwards towards other ''required'' intermediate propositions by making use of the known premises. The final proof of the argument form will be essentially in the reverse order of the ''reverse route''. The main idea is to try to lead from the conclusion to eventually reach only the premises.
From the above diagram we see that we could derive the conclusion tin the order of
With the help of the above order of derivation, we have
(a) | r, q r, q | (modus tollens) |
(b) | q, p q, p | (disjunctive syllogism) |
(c) | q, q u s, u s | (modus ponens) |
(d) | u s, s | (conjunctive simplification) |
(e) | p, s, p s | (conjunctive addition) |
(f) | p s, p s t, t | (modus ponens) |
Solution The ''dumbest'' way is to try to determine for each proposition (symbol) if it is true or not. This way one could be wasting a lot of time unnecessarily; but this often ensures one gets closer and closer to the solution of the problem.
In the argument form in examples 5-6, we have 6 basic propositions p, q, r, s , t and u. We will now proceed to determine (in the order dictated by the actual circumstances) whether each of these 6 propositions is true or not.
We have by now established the truth value of all the concerned basic propositions p,q,r,s,t,u. We can now proceed to determine if the conclusion t of the original argument form is true or not. In this case, it is obvious because we have already shown t is true. So the argument form (*) in example 5 is valid. Notice that step (v) is completely unnecessary. But we probably wouldn't know it at that time.
Note This ''dumb'' method can be very useful if you want to determine whether or not the conclusion of a lengthy argument form is true or not. I'll leave you to think about why.
Solution Let (1)--(4) to be given later on be 4 statements. The 1st two, (1) and (2) below, are true due to the detective's work.
From the (content of the) statements SA and SC we know
and from (1)
Let us examine the following sequence of statements.
(a) | SA SD | SA true implies SDtrue, i.e. (SA, SD) (from (3)) | (b) | SA SB SC SD | SA true implies SB, SC and SDall false (from (4)) | (c) | SB SC SD SD | conjunctive simplification (direct) | (d) | SA SD | hypothetical syllogism (from (b), (c)) | (e) | SD SA | modus tollens (from (a)) | (f) | SA SA | hypothetical syllogism (from (d), (e)) |
We note all the statements on the sequence apart from the first two (a) and (b) are obtained from their previous statements or form the valid argument forms. However the first 2 statements (a) and (b) are both true hence the conclusion in (f) is also true. A statement sequence of this type is sometimes called a proof sequence with the last entry called a theorem. The whole sequence is called the proof of the theorem.
Alternatively sequence (a)--(f) can also be regarded as a valid argument form in which a special feature is that the truth of the first 2 statements will ensure that all the premises there are true.
From (3) and (4) and (a)--(f) we conclude SA SA is true. Hence SA must be false from the rule of contradiction (if SA were true then SA would be true, implying SA is false: contradiction).
From the definition of SC we see SA SC. From the modus ponens
SA SC, SA, SC
we conclude SC is true. Since (1) gives
SC SA SB SD ,
we obtain from the (conjunctive simplification) argument
SC SA SB SD, SA SB SD SD, SC SD
that SC SD. Finally from modus ponens (SC SD, SC, SD) , we conclude SD is true, that is, C killed E. We note that in the above example, we have deliberately disintegreted our argument into smaller pieces with mathematical symbolisation. It turns out that verbal arguments in this case are much more concise. For a good comparison, we give below an alternative solution.
Solution (alternative for example 6) Suppose A wasn't lying, then A's statement B killed E is true. Since A spoke the truth means B,C and D would be lying, hence the statement C didn't kill E said by D would be false, implying C did kill E. But this is a contradiction to the assumption A spoke the truth. Hence A was lying, which means B didn't kill E, which in turn implies C spoke the truth. Since only one person was not lying, D must have lied. Hence Cdidn't kill E is false. Hence C killed E.
Predicate Calculus |
Hence we see that the domain of a predicate could also be absorbed in the predicate itself.
Solution We'll explain in more details in the first 2 cases.
m, n
,
((m+n) )
((m-n)
),
m ,
n ,
((m+n) )
((m-n)
) ,
m ,
( n
,
((m+n) )
((m-n)
) ) .
This is because essentially (m+n) says the sum of 2 integers is again an integer, and (m-n) says likewise for the subtraction of 2 integers. We note that while the 1st form is perhaps the neatest, the 1st and the 2nd forms can both be interpreted as an equivalent ''shorthand'' notation of the 3rd form. Moreover, the 3rd form can be regarded as an embedded predicate statement because the 3rd form can considered as
m , P(m) ,
where P(m) for each given m is again a predicate statement:
n , ((m+n) ) ((m-n) )) .
m, n , m/n .
Obviously the above form can also be written in other equivalent variant forms similar to the case (a).
Solution We note that more than 1 quantifier are used in both (a) and (b).
{ x , x > 0 }, N , n { x , n N }, |an - a| < .
Solution Let D denote the set of all people, and predicate L(x,y) denote that person x loves person y. Then the statement ''Everyone loves someone'' can be written as
x D, y D, L(x,y)
or equivalently ( x D, ( y D, L(x,y) ). Hence the negation is
x D, y D, L(x,y)
which means ''There is someone who loves no one''. We note here the order in which the quantifiers appear is important. If for instance we change the order of quantifiers for the original statement and consider instead
y D, x D, L(x,y) ,
we see that this new statement is true means that ''There's someone everyone loves'' which is quite different from the original statement.
Solution We begin with writing out certain related simpler but uesful components. We first observe that student x does all assignments can be written as
y A, D(x,y).
Hence the statement ''If student x does all the assignments, then he or she will pass this unit'' can be written as
( y A, D(x,y)) P(x) .
It is now straightforward to see that the original statement ''If a student does all the assignments, then he or she will pass this unit'' can thus be simply denoted by
x S, ( y A, D(x,y)) P(x) .
Solution The statements can be written as
original: | x , (x > 3) (x2 > 4) | (a) |
contrapositive: | x , (x2 4) (x 3) | (b) |
converse: | x , (x2 > 4) (x > 3) | (c) |
inverse: | x , (x 3) (x2 4) | (d) |
person x, (x drinks water) (x survives).
It is obviously not a sufficient condition because drinking water alone is not enough to guarantee the survival of a person, i.e. the statement
person x, (x drinks water) (x survives)
is not true.
Set and Its Connection with Boolean Algebra |
(a) | 2 A | 2 is an element of A |
(b) | 4 A | 4 is not an element of A |
(c) | {4} A | {4 } is an element of A |
(d) | {4} A | {4} is not a subset of A because the element 4 in {4} is not an element in A |
(e) | {1,2} A | 1,2 are both elements of A |
(f) | {1,2} A | {1,2} is an element of A |
(g) | B A | 5 B but 5 A |
(h) | A B = { 1,2,3, {4}, 5, {1,2,}} | union of A and B |
(i) | A B = { 1,2, { 4}} | intersection of A and B |
(j) | A - B = { 3,{1,2}} | set A minus set B |
(k) | B-A = {5} | set B minus set A |
{(A)} = { , {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}} .
Efficiency, Big |
Solution Observe
By taking C = 3 and M =3 (and D = ), we see f(n) is (n). We note that there are many different yet all valid choices of Cand M. For example,
implies we can choose C=5 and M =1 in the definition of f(n) = (n).
Solution The inequality
i.e. |f(x)| 21 for x 1, gives immediately f(x) = () (by choosing C = 21 and M=1 in the definition).
Solution We need to find constant M and positive constant Csuch that |f(n)| Cn2 for all n M. There are different ways to achieve this, and we give below 2 most obvious ones.
We take in this case M=1 and C=3.
We take in this case M=5 and C=2.
Solution DIY.
Mathematical Induction |
Solution Just about everyone will say ''not possible'' immediately. Why? This is because the P.M.I. is already in our natural mind without being noticed. However, let us see how the underlying logic works mathematically.
Let Sn denote the statement that Jim's offsprings of the n-th generation are all foxes. Then
(*) |
Solution Let Sn denote the statement (*). Since th initial index for n 1 is n = 1, we first verify
Hence equality (*) holds for n=1, meaning S1 is true.
(**) |
We now prove Sk+1 is also true. For n = k+1,
i.e. Sk+1 is true.
We thus conclude from the P.M.I. that Sn is true for all n 1. This means (*) will hold for all integers n 1.
Solution Let us consider how to prove by induction the following statement
(1) |
(2) |
(3) |
(4) |
(5) |
We are now ready to proceed. The l.h.s. of (3) is
, |
Solution If we are ''unlucky'', no worries, at most just a bit extra work. Let us assume that we looked the other way and saw the r.h.s. of (3) first and we still want to prove it by making use of the induction assumption (2). The first step is to ''break'' that expression into containing forms that are identifiable with some of those in (2). But for expression like
(6) |
(7) |
(k+1) | (8) |
(a) | only 1 empty set | |
(b) | the only subset with all elements in it is the set itself | |
(c) | if r 1, n>1} |
Recall the convention 0! =1. Let us prove
(***) |
Solution Let Sn denote the following statement
As for r=0 and r = n +1, we see from (a) and (b)
Hence Sn+1 is true..
Sn:
Solution
i.e. Sk+1 is true.
Solution I'm quite exhausted by now; if you're not then supply the proof yourself.
Analysis of Algorithms |
Binary search. 3 comparisons are needed as can be seen from the diagram below
Sequential search. 6 comparisons are needed in this case, see
Notation |
Solution
i.e. 2n |f(n)| 3n for n 1, we easily conclude f(n) = (n).
Solution
i.e. |f(n)| (1/2) (1) for any n 1. Hence f(n) = (1) (with C = 1/2 and M = 1).
i.e. 1 8|f(n)| for n 2. Hence, together with the upper bound found in (a), we have
or |g(n)|/8 |f(n)| |g(n)|/2 for g(n) 1, with M=2, C=1/2 and D=1/8. According to the definition, we thus have f(n)= (g(n)), i.e. f(n) = (1).
Solution Big is essentially a measurement for the magnitude of functions at ''infinity'', and tells roughly who is ''bigger''. We say function f(n) is of order of big of function g(n), i.e. f(n)= (g), if the magnitude of f(n) will be eventually bounded from above by a constant multiple of the magnitude of g(n). Magnitude |f(n)| bounded by a constant multiple of that of g means
|f(n)| C |g(n)| | (*) |
Solution From the definition of notation, we have to establish an upper bound and lower bound, corresponding to the 2nd and the 1st inequality relation in the formula below
D |n2| |f(n)| C |n2| .
To establish an upper bound is to find some positive constants C and M such that
(1) |
We will now try to ''move'' from the expression
(2) |
C n2 | (3) |
(4) |
(5) |
(6) |
n2+2n | (7) |
2n 2n2 |
n2+2n n2 +2n2 = 3n2 . |
(8) |
(9) |
Now we proceed to establish a lower bound for f(n). We need to find positive constant D and constant L such that
(10) |
(11) |
To derive (10), we proceed similarly. First let us throw away some non-significant terms legitimately, by keeping the dominant ones and assuming n 1 (thus (2) is non-negative). Our first ''move'' is to throw away the term 2n2 in the numerator of (2). Notice that our new ''moves'' are for the '' '' sign, not the '' '' as in the previous case. Thus we can't throw way the ''-1'' in the numerator and ''1'' in the denominator as they would break the sought '' '' sign. Hence after the first ''move'', we obtain
(12) |
(13) |
-1 constant n3 . | (14) |
(15) |
(16) |
(17) |
(18) |
Solution To find an upper bound we first observe
The inequality above was due to the (legitimate!) increase of the numerator and the decrease of the denominator, it could be done so because we were looking for an upper bound. Obviously we won't allow in this case a decrease of the numerator or an increase of the denominator. To find a lower bound, incidentally, the oppsite is true. We have thus so far shown
|f(n)| 2n2 , whenever n 2 .
For a lower bound, we observe
which means
|f(n)| n2/2 , whenever n 1 .
Hence, by putting together the upper bound and the lower bound, we have
n2/2 |f(n)| 2n2 , whenever n 2 .
This in the definition of notation corresponds to C=2, D=1/2 and M=max(1, 2)=2 where, for any values a and b, max(a, b) denotes their maximum value. Hence we finally conclude f(n)= (n2).
Solution We first prove by induction the statement
Sn: log2 n < n
for n 1. Obviously S1 is true because l.h.s.= log2 1=0 < 1=r.h.s. Assume Sk is true for an integer k 1, i.e. log2 k< k, then
log2 (k+1) log2( k + k) = log2(2k) = log2 2 + log2 k =1 + log2 k < 1 + k ,
i.e. log2 (k+1)< k+1. Hence Sk+1 is also true. From the P.M.I. we have thus shown that Sn is true for all integers n 1. Since log2 n 0 for n 1 implies | log2 n|= log2 n |n| for n 1, we finally conclude log2 n=(n).
Number Bases |
(1011.1)2 = 1 23+0 22+1 2 + 1+1 (1/2) =(11.5)10 ,
i.e. 1011.12 is equal to 11.5 in decimal.
13.78=1 81+3 80+7 8-1=11.875 ,
i.e. 13.78 represents the decimal number 11.875.
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F ,
representing 0 to 15 respectively. For example,
A 7F16 | = | A 162+7 161 +F 160 |
= | 10 162+7 16 + 15 1 = 2687 . |
That is, we first divide 45 by 4. The quotient 11 is then divided by 4, with the new quotient 2 being again divided by 4. This repeating process is then stopped because the latest quotient has reached 0. The remainders obtained at these division steps, when listed in the reverse order, finally give the desired representation of 45 in base 4.
Solution We illustrate here an alternative approach to number conversions. It uses exactly the same algorithm as before, and the only difference lies in the organisation or presentation of the derivation. Obviously you don't have to bother with this approach if you don't like it: the approach adopted in the previous example is already neat enough.
Hence 123=11110112.
Solution Since 16=24, 1 digit in hexademical will correspond to exactly 4 digits in binary. Since
we have
(7A 1)16=(01111010.0001)2 .
Solution Since 8=23 implies every 3 consecutive digits, going left or right starting from the fractional point, in binary will correspond to a single digit in base 8. By grouping consecutive digits into blocks of 3, appending proper 0's if necessary, we have
(1111010.0001)2= (001 111 010.000 100)2 =(172.04)8
because 0012=18, 1112=78, 0102=28 and 1002=48.
i.e. 3435+1145=10125 . We note that the addition is performed digitwise from the rightmost digit towards the left. On the rightmost digit, 35+45=710=(12)5 gives the resulting digit 2 and the carry 1 to the next digit on the left. On the 2nd rightmost digit, we have thus 45+15+ (carry) 15=610=(11)5, resulting to digit 1 plus a new carry 1. As the last step, we then have 35+15+15=510=(10)5. This completes our addition.
Hence 100112-1012=11102 . The subtraction is also performed digitwise from the rightmost digit towards the left. On the rightmost digit, 12-12=02 gives the resulting digit 0. On the 2nd rightmost digit, 12-02=12 gives the result 1. On the 3rd rightmost digit, we borrow 1 from the digit on the left; actually we have to borrow 1 further on the left because the digit on the immediate left is 0 and therefore can't be borrowed. The subtraction on the 3rd rightmost digit thus becomes (10)2-12=210 -110=110=12. Finally, the 4th rightmost digit, after borrowed 1 from the left and being borrowed 1 from the right, is left with the remaining 1. This completes the subtraction.
Graphs and Their Basic Types |
the vertex set V={v1, v2, v3,
v4,v5}, the edge set E={e1,
e2, e3, e4} and the edge-endpoint
function is given by
edge e | endpoints (e) | |
e1 | {v1} | |
e2 | {v1, v2} | |
e3 | {v2, v3} | |
e4 | {v2, v3} | |
e5 | {v2, v3} |
the vertex set V={v1, v2, v3},
the edge set E={e1, e2, e3,
e4}, and the edge-endpoint function is given by
edge e | endpoints pair (e) | |
e1 | (v1, v1) | |
e2 | (v1, v2) | |
e3 | (v3, v2) | |
e4 | (v2, v3) |
A graph H is a subgraph of graph G iff
If we choose 2(e) = {v2, v3} then graph G2 = (V,E, 2) represents
Although it is obvious that
V(G2) V(G1) , E(G2) E(G1) = {e} ,
the endpoints of e in G2 are different from those of e in G1. Hence G2 is not a subgraph of G1.
Note Intuitively we see from the diagram that e={v2, v3} in G2 is not an ''edge'' of G1 breaks the condition (ii) in this definition of a subgraph. This argument is however based on the implicit edge association with the corresponding end points. In other words, condition (iii) may be dropped, as in some texts, if the condition (ii) is extended in this sense. See the note at the end of this lecture for further explanations.
graph H
and graph F
are both subgraphs of G.
we have (v1)=5, (v2)=4, (v3) =1 and (v4)=0.
is disconnected, because we can't walk from vertex
v4 to for instance vertex v1,
i.e. there is no walk from v4 to
v1. Obviously G can be decomposed into three
connected components G1, G2 and
G3.
V(G1) | = | {v1, v2, v3} , | E(G1) | = | {e1, e2} ; |
V(G2) | = | { v4} , | E(G2) | = | (the empty set) ; |
V(G3) | = | { v4, v5, v6} , | E(G3) | = | {e3, e4, e4} . |
is planar because it can be drawn as
is nonplanar because, after removing edges e and f, and vertex v, the graph becomes K3,3. Hence Kuratowski's Theorem implies the original graph is nonplanar. We note that removal of vertex like v (and then connecting the end points v1 and v2) is called series reduction. If a graph is planar, then obviously any of its subgraphs is also planar, even if series reductions are further performed. Hence Kuratowski's Theorem can be rephrased as saying a graph is nonplanar iff it contains a subgraph which, after series reduction, is K5 or K3,3.
Eulerian and Hamiltonian Circuits |
has an Eulerian path but is not Eulerian.
route | total distance | |
A B C D A | 30 + 30 + 25 + 40 = 125 | |
A B D C A | 140 | |
A C B D A | 155 | |
A C D B A | 140 | |
A D B C A | 155 | |
A D C B A | 125 |
We start at v5 because (v5) = 5 is odd. We can't choose edge e5 to travel next because the removal of e5 breaks G into 2 connected parts. However we can choose e6 or e7 or e9. We choose e6. One Eulerian path is thus
Graph Isomorphism and Matrix Representations |
Solution How to find isomorphism function g and h in general will be clearer when we introduce the concept of isomorphism invariants later on. But at this stage it is mostly guesswork. Let g and h be given by
g(v1) = w2, g(v2) = w1, g(v3) = w4, g(v4) = w3 ,
h(e1) = f2, h(e2) = f1, h(e3) = f4, h(e4) = f3, h(e5) = f5
which can be alternatively represented in the diagrams below
We now verify the preservation of endpoints under g
and h
e1 {v1,v2} | f2 {w1,w2} = {g(v1), g(v2)} | |
e2 {v2, v4} | f1 {w1,w3} = {g(v2), g(v4)} | |
e3 {v2,v3} | f4 {w1,w4} = {g(v2), g(v3)} | |
e4 {v1,v4} | f3 {w2,w3} = {g(v1), g(v4)} | |
e5 {v3,v4} | f5 {w3,w4}= {g(v3), g(v4)} , |
are not isomorphic to each other because vertex v of G1 has degree 5 while no vertices of G2 have degree 5.
First, since v2, v4 in G1 and w1 and w3 in G2 are the only vertices of degree 3, g must map v2, v4 to w1, w3 or w3, w1 respectively. We thus choose g(v2) = w1 and g(v4) = w3. Since {v2, v4} are the endpoints of e2, we must have h(e2) = f1 so that the endpoints {v2, v4} of edge e2 are preserved because f1 has endpoints {w1, w3} = {g(v2), g(v4)}.
Next we need to map v1, v3 to w2, w4 or w4, w2 respectively. If we choose w2 = g(v1) we must have w4 = g(v3). Thus the edge e1 joining v1 and v2 should be mapped to the edge f2 joining g(v1) = w2 and g(v2) = w1, i.e. f2 = h(e1). The rest of g and h can be determined similarly.
is
is
which has the adjacency matrix A below
Since
we see there are exactly \shade{2} walks of length 2 that start at v3 and end at v1. Since
has only 0's in the third column, we conclude that no vertex can reach v3 via a walk of nonzero length.
Trees |
are both trees.
is not a tree.
Solution
the traversals are as follows.
Preorder: | a, b, d, c, e, f, g |
Inorder: | d, b, a, f, e, g, c |
Postorder: | d, b, f, g, e, c, a |
But how is the calculation actually done? It may be processed via a postorder traversal
a, b, c, , +, d, / | ( ) |
a , b , c , , + , d , / |
a , b c , + , d , / |
a+b c , d , / |
(a + b c)/d . |
15, 7, 24, 11, 27, 13, 18, 19, 9 .
We note that when a binary tree is used to sort a list, the inorder traversal will be automatically assumed in this unit.
Solution To sort a list, just create a binary tree by adding to the tree one item after another, because the insertion is essentially a sorting process. The binary tree constructed during the course of sorting the above list then reads
The sorted list is thus
7, 9, 11, 13, 15, 18, 19, 24, 27 .
We note that a better tree sorting algorithm will involve balancing the trees. However such additional features fall beyond the current unit scope.
Spanning Trees |
becomes
after removing edge {v2,v3} from G to break the cycle v5 v2 v3 v5, and becomes a spanning tree
after removing edge { v4,v3} to break the last remaining cycle v5 v3 v4 v5. Of course, there can be different spanning trees for the same connected graph G.
Suppose each communication link (edge) costs 1000 to install. Since communications may be relayed via intermediate centres, we may choose a spanning tree to lay the communication links so as to minimise the total cost. We now list below all possible spanning trees
each will thus only cost 3000 to build, in comparison with the 5000 (5 edges) required for the original graph G.
Recall that a spanning tree was obtained there by breaking all the cycles in the graph. However, we can also construct a spanning tree in the opposite way, that is, by gradually collecting edges from G, and making sure that the resulting subgraph is always connected and contains no cycles. For instance, a spanning tree T4, different from that obtained in example 1, can derived from the following 4 steps
Notice that neither e5 nor e6 can be added because that would create cycles. We stop the procedure when consideration for all edges are exhausted.
Solution Since the graph is already provided with a vertex list and an edge list, we might just as well use these lists as the outcome of steps (i) and (ii) though we could use lists of different orders. Steps (iii)-(vi) can be summarised in the following table
Notice that at step 1, since e1 has vertices v2 and v3 and L(2)=2 L(3)=3, we thus change L(2),L(3) both to 2 and add e1 to the spanning tree. At step 5, since e5 has vertices v2 and v4 and L(2)=L(4)=2 (at the end of step 4), we know from (v) that we can't add e5 to the tree (because the addition of e5 would create a cycle). At step 7, since e7 has vertices v1 and v2 whose labels are 1 and 2 respectively, we change in this step all the labels with value either 1 or 2 to the min(1,2)=1. At step 10, nothing needs to be considered because all labels are now equal at the end of step 9, implying the spanning tree is already obtained. The spanning tree, collecting the edges in the last column, has edges { e1,e2,e3,e4,e7,e9 }, or
in which the number on the edges indicates the corresponding weight.
Solution Since this is a simple graph, we may use a pair of
vertices to represent an edge. One possible list of edges ordered in
increasing weight is
e1={v2,v3} , w(e1)=1 ; | e6={v5,v7} , w(e6)=4 ; |
e2={v5,v6} , w(e2)=2 ; | e7={v1,v2} , w(e7)=4 ; |
e3={v6,v7} , w(e3)=3 ; | e8={v1,v4} , w(e8)=5 ; |
e4={v3,v4} , w(e4)=3 ; | e9={v3,v5} , w(e9)=5 ; |
e5={v2,v4} , w(e5)=4 ; | e10={v3,v7} , w(e10)=7 . |
in which the numbers conveniently represented by the bar ''---'' are the same as the numbers in the previous step. You may of course use the actual numbers instead if you so prefer. Hence a minimal spanning tree can be formed by the edges {e1,e2,e3,e4,e7,e9}. The corresponding total weight is 18 (=1+2+3+3+4+5).
Relations |
1 2, 1 5, 3 2, 3 5 .
In other words, 3 pairs (1, 2), (1, 5) and (3, 5) observe the '' '' relationship. Hence by collecting them in R, i.e.
R= { (1, 2), (1, 5), (3 ,5) } ,
we know relation R describes precisely the relationship between
elements of A and elements of B under '' ''. For example,
3 R 5 | (3, 5) R | 3 is related to 5 by R | 3 5 , | ||
3 2 | (3, 2) R | 3 is not related to 2 by R | 3 2 . |
for any (x,y) A B: (x,y) R iff x-y is even
Solution
(x,y) | property of x-y | conclusion |
(1,1) | 1-1 even | (1,1) R |
(1,2) | 1-2 odd | (1,2) R |
(1,3) | 1-3 even | (1,3) R |
(2,1) | 2-1 odd | (2,1) R |
(2,2) | 2-2 oven | (2,2) R |
(2,3) | 2-3 odd | (2,3) R |
F={(1,1), (2,3), (3,6)}
in which, for instance, (2,3) corresponds to 3=f(2).
S={ (x,y) | (x-10)2+y2 16, or (x-5)2+y2 4 } .
Graph S in the Cartesian plane.
Solution Recall from analytic geometry that a Cartesian plane is a plane with the normal x and y axis, and a circle of radius r centred at the coordinates (a,b) is given precisely by the equation
(x-a)2 +(y-b)2= r2 .
Hence equation (x-10)2+y2=16 (=42) represents a circle of radius 4 centred at the coordinates (10,0), and (x-5)2+y2=4 is a circle of radius 2 centred at the coordinates (5,0). Thus S is the union of these 2 disks, and is represented by the shaded area in the graph below.
R={ (0,0), (0,1), (0,3), (1,0), (1,1), (2,2), (3,0), (3,3) } .
Is R reflexive? symmetric? transitive?
Solution We'll make use of the digraph for R on the right.
Note It is equally easy to show these properties without resorting to the digraph.
m R n m n (mod) 3 3 | (m-n) .
Show R is an equivalence relation.
Solution We just need to verify that R is reflexive, symmetric and transitive.
7R4 7 4 (mod 3) 7-4 =3 1 4-7 =3 (-1) 4 7 (mod 3) 4R7
Equivalence Relations |
(m,n) R iff m n (mod 4) m,n A .
Recall that m n (mod 4) is
equivalent to saying 4 divides (m-n) or (m-n) is
an integer multiple of 4. Thus it is easy to see
(m,n) | m-n | conclusion | is multiple of 4? | |||
(2,2) | 2-2=0 | (2,2) R | yes, 0 is a multiple of 4 | |||
(2,4) | 2-4=-2 | (2,4) R | no, -2 is not a multiple of 4 | |||
(2,6) | 2-6=-4 | (2,6) R | -4: yes | |||
(2,8) | 2-8=-6 | (2,8) R | -6: no | |||
(2,10) | 2-10=-8 | (2,10) R | -8: yes | |||
(4,2) | 4-2=2 | (4,2) R | 2: no | |||
(4,4) | 4-4=0 | (4,4) R | 0: yes | |||
(4,6) | 4-6=-2 | (4,6) R | -2: no | |||
which gives explicitly
R = { (2,2), (2,6), (2,10), (4,4), (4,8), (6,6), (6,10), (8,8), (10,10), (6,2), (10,2), (8,4), (10,6) } .
This relation R can be drawn as
and is obviously an equivalence relation (cf. examples in the previous lecture). Notice that there are 2 ''connnected'' components, one containing elements 4 and 8 and the other, elements 2, 6 and 10. Here the ''connection'' is made through certain walks along the directions of the arrows. These 2 components are just the 2 distinct equivalence classes under the equivalence relation R. Naturally we may use any element in an equivalence class to represent that particular class which basically contains all elements that are connected to the arbitrarily chosen representative element. Hence, in this case, we may choose 2 to represent the class {2,6,10}, written simply [2]={2,6,10}, and choose for instance 8 to represent the other class {4,8}, that is, [8]={4,8}. Since any member of an equivalence class can be used to represent that class, [6] and [10] will be representing exactly the same equivalence class as [2]. Hence
[2] [6] [10] = { 2, 6, 10 }, [4] [8] = { 4, 8 } .
are the 2 distinct equivalnce classes.
Solution Actually this is more like explanations.
Solution In example 1 we have shown that [2]={2,6,10} and [4]={4,8} are the only distinct equivalence classes. Since A in example 1 is given by A={2,4,6,8,10}, we can easily verify
(a): A = [2] [4] ; (b): [2] [4] = .
From the definition of the set partition (see the earlier lecture for sets) we conclude that { [2], [4] } is a partition of set A.
Solution
[0] ={ x : x R 0} = { ... , -6, -3, 0, 3, 6, ... } .
[1] ={x : x R 1} = { ... , -5, -2, 1, 4, 7, ... } .
[5] ={ x : x R 5} = { ... , -4, -1, 2, 5, 8, ... } .
we see that a transitive closure, or closure w.r.t. the transitivity, can be obtained by adding arrows (0,2) due to (0,1) and (1,2), (1,3) due to (1,2) and (2,3), and (0,3) due to (0,1) and newly obtained (1,3). Hence the directed graph R' will be
i.e. R' ={(0,1), (1,2), (2,3), (0,2), (1,3), (0,3) }.
Note We may make an equivalence relation out of R as follows
Partial Order Relations |
Solution We choose to use digraphs to make the explanations in this case.
u v or uRv , iff u v ,
is a partial order relation. Find a minimal element and a greatest element.
Solution It is easy to verify that '' '' is a partial ordering. Since is a subset of any u A, i.e. u, we see is not only a minimal element, it is also a least element of A. Since for any u A one has u { a,b,c}, i.e. u { a,b,c}, we see that { a,b,c} is a greatest element of A.
It is somewhat ''messy'' and some arrows can be derived from transitivity anyway. If we
This type of graph is called a Hasse diagram, it is often used to represent a partially ordered set.
a b iff a | b .
Draw the Hasse diagram of the relation.
Solution First it is easy to verify that the relation defined above is a partial ordering. The directed graph of relation is
and the Hasse diagram is
A={ 3, 4, 5, 6, 10, 12 }
and a binary relation R on A be defined by
(x, y) R iff x | y ,
i.e. (x,y) R if and only if x divides y. Give explicitly R in terms of its elements and draw the corresponding Hasse diagram.
(x, y) R' if and only if either x | y or y | x
and R'' be the transitive closure of R'. Use directed graphs to represent R, R' and R'' respectively. Which of the three relations R, R' and R'' is an equivalence relation? For the equivalence relation, give all the distinct equivalence classes.
Solution
R = { (3,3), (3,6), (3,12), (4,4), (4,12), (5,5), (5,10), (6,6), (6,12), (10,10), (12,12) } .
Hence the digraph for R is
which induces the following Hasse diagram
Since relation R'' is the transitive closure of R', we can derive R'' from R' by connecting 3 to 4 and 4 to 6 and connecting 4 to 3 and 6 to 4. We connect 3 to 4 via an direct arrow because we can travel from 3 to 12 and then from 12 to 4 all along the arrows, and we connect 4 to 3 because we can travel from 4 to 12 then to 3 all along the arrows too. Similar reasons are applicable for the arrows from 4 to 6 and 6 to 4. Hence R'' can be drawn as
Since there is no arrow from element 12 to element 3 in the digraph of R despite the existence of an arrow from 3 to 12, relation R is not symmetric hence is not an equivalence relation. Since relation R' is not transitive (because its transitive closure R'' is not the same as R' itself), relation R' is not an equivalence relation either. As for the relation R'' , it is obviously reflexive, symmetric and transitive. Hence R'' is an equivalence relation.
Since elements 3, 4, 6 and 12 are all related (connected) to each other through the arrows of the digraph R'' and none of these 4 elements are related to any other elements, they must form a single equivalence class. Hence we have
[3] = { 3, 4, 6, 12 } .
Likewise we can derive another equivalence class
[5] = { 5, 10 } .
Because any element of A is either in the equivalence class [3] or in the equivalence class [5], these two classes are all the distinct equivalence classes.
Recurrence Relations |
an = 7an-1 - 5an-2
is a recurrent relation valid for n 2. The elements in the sequence that are not related by the above formula are a0 and a1. Hence a0 and a1 can be determined by the initial conditions. Once the values of a0 and a1 are specified, the whole sequence {ai}i 0 is completely specified by the recurrence relation.
an = 3an-1 + 2an-2 | (*) |
a0 = 1, a1 = 2 . | (**) |
Solution
Recursively we use (*) repeatedly (''topdown'') to decrease
the indices involved until they all reach the initial ones. Hence
a4 | = | 3a3 + 2a2 | used (*) for n=4 |
= | 3(3a2 + 2a1) + 2a2 | used (*) for n=3 | |
= | 11 a2 + 6a1 | ||
= | 11 (3a1 + 2a0) + 6a1 | ||
= | 39a1 + 22a0 | ||
= | 39 2 + 22 1 = 100 . | used (**) |
a0 | = | 1 , | |
a1 | = | 2 , | |
a2 | = | 3a1 + 2a0 = 8 , | |
a3 | = | 3a2 + 2a1 = 28 , | used (*) for n=3 |
a4 | = | 3a3 + 2a2 = 100 . | used (*) for n=4 |
f(n) | = | n f(n-1), n , n 1 | |
f(0) | = | 1 | (initial condition) . |
Solution We first derive
f(n) | = | nf(n-1) | if n 1 |
= | n(n-1) f(n-2) | if n 2 | |
= | n(n-1)(n-2)f(n-3) | if n 3 | |
= | n! f(0) = n! . |
ak+2 - 5ak+1 - 2ak = 3k+2, k 0 .
In terms of the notation in (***) we have in this case m=2 and
cm=c2=1, cm-1=c1=-5, cm-2=c0=-2, g(n)=3n+2 .
Note An alternative way to construct the characteristic equation: Since the highest index in the recurrence relation is n+1 while the lowest index is n-2, their difference (n+1)-(n-2)=3 must be the order m, i.e. m=3. Likewise the characteristic equation can also be obtained in following way.
an+2 - 5an+1 + 6an = 0 , n 0 .
Give also the particular solution satisfying a0 = 0 and a1=1.
Solution Since the associated characteristic equation is
2 - 5 + 6 = 0
and has 2 distinct roots 1
= 2 and 2 = 3, the
general solution for the recurrence relation, according to the theorem
earlier on, thus read an = A12n +
A23n, n 0,
where A1 and A2 are 2 arbitrary
constants. To find the particular solution, we need to determine
A1 and A2 explicitly by the
initial conditions a0 = 0 and a1 =
1. Hence we require
a0 = A120 + A230 = 0 |
a1 = A1 21 + A231 = 1 |
A1 + A2 = 0 |
2A1 + 3A2 = 1 |
Note It is often a good practice to check your answers, even if just partially. To check the above particular solution, we see
an+2 - 5an+1 + 6an | = | (-2n+2 + 3n+2) -5(-2n+1 + 3n+1) + 6 (-2n + 3n) |
= | -2n (22 - 5 2+6) + 3n (32 - 5 3 + 6) = 0 . |
Solution of Linear Homogeneous Recurrence Relations |
f(n+2)+4f(n+1) +4f(n)=0, n 0
with initial conditions f(0)=1 and f(1)=2.
Solution For clarity we artificially split the solution procedure into 3 steps below.
2+4 +4 =0 ,
which has a repeated root 1=-2. In other words, all of its roots counting the multiplicity are
1, 1 (i.e. m1=2, k=1) .
f(n) = (A1,0+A1,1n)n1 = (B0+B1n)(-2)n ,
where B0 and B1, denoting A1,0 and A1,1 respectively, are arbitrary constants.
f(0) = (B0 +B1 0)(-2)0 =1 |
f(1) = (B0+B1 1)(-2)1 = 2 |
imply
B0=1, -2(B0+B1)=2 .
They are thus B0=1 and B1=-2. Hence the requested particular solution is
f(n)=(1-2n)(-2)n , n 0 .
an+3-3an+2+4an=0 , n 0.
Solution The associated characteristic equation is
F() 3-32+4 =0 .
Although there are formulas to give explicit roots for a 3rd order polynomial in terms of its coefficients, we are taking a shortcut here by guessing one root 1=-1. We can check that 1=-1 is indeed a root by verifying F(-1)=(-1)3-3(-1)2+4 =0. To find the remaining roots, we first factorise F( ) by performing a long division
which implies
3-32+4 = ( +1)(2 -4 +4)=( +1)( -2)2 .
Therefore all the roots, counting the corresponding multicity, are
-1 , 2 , 2 ,
i.e. 1 =-1, m1=1 and 2 =2, m2 =2. Hence the general solution reads (with A=A1,0, B=A2,0, C=A2,1)
an=A(-1)n+(B+Cn)2n , n 0 .
un+3+3un+2+3un+1+un=0 , n 0
satisfying the initial conditions u0=1, u1=1 and u2=-7.
Solution
3+32+3 + 1 ( +1)3 =0
has roots 1 =-1 with multiplicity 3, i.e. m1=3.
un =(A+Bn +Cn2)(-1)n , n 0 .
u0 | gives | A | = | 1 |
u1 | gives | (A+B+C)(-1) | = | 1 |
u2 | gives | A+2B+4C | = | -7 . |
A=1, B=0, C=-2.
finally produces the required particular solution
un =(1-2n2)(-1)n , n 0 .
Basics of Linear Nonhomogeneous Recurrence Relations |
Solution As the r.h.s. is 2 3n, we try the special solution in the form of an=C3n, with the constant C to be determined. The substitution of an=C3n into the recurrence relation thus gives
i.e. 4C=2 or C=1/2. Hence an= (3n)/2 for n 0 is a particular solution.
Solution As the r.h.s. is 6n, we try the similar form
fn = An+B , |
6n | = | fn+1 - 2fn + 3fn - 4 |
= | (A(n+1)+B) - 2(An+B) + 3(A(n-4)+B) | |
= | 2An + (2B-11A) |
2A = 6 , 2B - 11A = 0 |
Therefore our particular solution is fn=3n + 33/2.
an+3-7an+2+16an+1-12an=4nn |
a0=-2 , a1 =0 , a2=5 . |
Solution We first find the general solution
un for the corresponding homogeneous problem. Then
we look for a particular solution vn for the
nonhomogeneous problem without concerning ourselves with the initial
conditions. Once these two are done, we obtain the general solution
an=un+vn for the
nonhomogeneous recurrence relation, and we just need to use the
initial conditions to determine the arbitrary constants in the general
solution an so as to derive the final particular
solution of our interest.
3 -7 2+16 -12 =0 |
1 =3, | (m1=1, simple root) |
2 =2, | (m2=2, double root) . |
The general solutions for the corresponding homogeneous problem thus
reads
un=A3n+(B+C n)2n , n 0 . |
vn=4n(Dn+E) . |
4n n | = | vn+3-7vn+2+16vn+1-12vn |
= | 4n+3(D(n+3)+E)-7 4n+2(D(n+2)+E) | |
+ 16 4n+1 (D(n+1)+E)-12 4n(Dn+E) , |
n | = | 64(Dn+3D+E)-112(Dn+2D+E) |
+ 64(Dn+D+E)-12(Dn+E) | ||
= | 4Dn+4E+32D . |
4D=1 , 4E+32D=0 D=1/4 , E=-2 |
an =4n(n/4 - 2) + A3n+(B+Cn)2n , n 0 . |
Initial Conditions | Induced Equations | Solutions | |||||||||||||||||||||||||||
|
|
|
an=4n(n/4 - 2) + 3n + (3n-1)2n , n 0 . |
Solutions of Linear Nonhomogeneous Recurrence Relations |
Solution First we observe that the homogeneous problem
un+2 + un+1 -6un=0 |
C(n+2)2n+2+C(n+1)2n+1-6Cn2n = 2n , |
an=A2n+B(-3)n + 2n , n 0 . |
Solution Let f(n)=un+vn, with un being the general solution of the homogeneous problem and vn a particular solution.
un+2-6un+1+9un=0 , n 0 |
5 3n | = | vn+2-6vn+1+9vn |
= | C(n+2)23n+2-6C(n+1)23n+1+9Cn23n | |
= | 18C3n . |
f(n) = A + Bn + n2 3n , n 0 . |
an+4-5an+3+9an+2-7an+1 +2an=3 , n 0 |
Solution We first find the general solution un for the homogeneous problem. We then find a particular solution vn for the nonhomogeneous problem without considering the initial conditions. Then an=un+vn would be the general solution of the nonhomogeneous problem. We finally make use of the initial conditions to determine the arbitrary constants in the general solution so as to arrive at our required particular solution.
4-5 3 +9 2 -7 + 2 =0 |
1 =1 | with multiplicity | m1=3 , and |
2=2 | with multiplicity | m2=1 . |
un = (A+Bn+Cn2)1n+D2n , |
3 | = | vn+4-5vn+3+9vn+2-7vn+1+2vn |
= | E(n+4)3-5E(n+3)3+9E(n+2)3-7E(n+1)3+2En3 | |
= | E(n3 + 3n2 4+3n 42+43) -5E(n3 + 3n2 3+3n 32+33) | |
+ 9E(n3 + 3n2 2+3n 22+23) -7E(n3 + 3n2 1+3n 12+13) + 2En3 | ||
= | -6E , |
Note Should you find it very tedious to perform the expansions
in the above, you could just substitute, say, n=0 into
3 = E(n+4)3-5E(n+3)3+9E(n+2)3-7E(n+1)3+2En3 |
an = un + vn = A + Bn + Cn2 + D2n - n3/2. |
Initial Conditions | Induced Equations | Solutions | ||||||||||||||||||||||||||||||||||||
|
|
|
an = 3 - 2n + n2 - n3/2 - 2n, n 0 . |
Solution
n2n+1 = vn+1-vn | = | 2n+1(B+C(n+1)) + D(n+1) - 2n(B+Cn) - Dn |
= | 2n(Cn+B+2C) + D , |
2n ( (C-1)n + (B+2C) ) + (D-1) = 0 . |
C-1=0 , B+2C=0 , D-1=0 . |
an = 2n(n-2)+n+A , n 0 . |
Solution We first observe
S(n+1)= (n+1)m + im = S(n) + (n+1)m . |
S(n+1)-S(n) | = | (n+1)m, n |
S(0) | = | 0 . |