Blog
Discrete Structure Past Paper 2013 – BSCS 2nd Term UOS (CMP-200)
University of Sargodha BS Computer Science 2nd term Discrete Structure (CMP-200) paper, 2013 exam (80 marks, 2:30 hours). The paper is retyped below without the handwritten working on the original, followed by solved answers for all 16 short questions and all subjective questions: membership and truth tables, logical equivalence, graph isomorphism, tree traversals, predicate logic, the pigeonhole principle and relations.
Solved answers
Q1 – Short answers (16 × 2)
I. De Morgan’s law of intersection: (A ∩ B)′ = A′ ∪ B′. Membership table (1 = element belongs):
| A | B | (A ∩ B)′ | A′ | B′ | A′ ∪ B′ |
|---|---|---|---|---|---|
| 1 | 1 | 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 | 1 | 1 |
| 0 | 1 | 1 | 1 | 0 | 1 |
| 0 | 0 | 1 | 1 | 1 | 1 |
The columns (A ∩ B)′ and A′ ∪ B′ are identical, so the law is true.
II. f(x) = x² + 2x + 3 is O(x²). For x ≥ 1: x² + 2x + 3 ≤ x² + 2x² + 3x² = 6x². So |f(x)| ≤ 6|x²| for all x > 1, i.e. f(x) is O(x²) with witnesses C = 6, k = 1.
III. Σi=03 Σj=24 i·j. Inner sum = i(2 + 3 + 4) = 9i. Outer sum = 9(0 + 1 + 2 + 3) = 54.
IV. Directed vs undirected graph. In an undirected graph edges have no direction: {u, v} means u–v both ways, e.g. a friendship graph. In a directed graph (digraph) each edge is an ordered pair (u, v) from u to v, e.g. web links or one-way roads; vertices have in-degree and out-degree.
V. Representing graphs in memory. Adjacency matrix (n × n matrix with aij = 1 if there is an edge from vi to vj), adjacency list (for each vertex a linked list of its neighbours), and incidence matrix (vertices × edges).
VI. Value of + − * 2 3 5 / ↑ 2 3 4. Evaluate right to left: ↑ 2 3 = 8; / 8 4 = 2; * 2 3 = 6; − 6 5 = 1; + 1 2 = 3. (Infix: (2*3 − 5) + (2↑3)/4.)
VII. f(a) = b, f(b) = a, f(c) = c, f(d) = d. Different elements have different images and every element of {a, b, c, d} is an image, so f is one-to-one and onto (a bijection).
VIII. R = {(a, b) | a ≤ b}. (1,1), (1,2) and (2,2) are in R; (2,1) and (1,−1) are not, because 2 ≰ 1 and 1 ≰ −1.
IX. Negation. “This is not the month of March.” (It is not the case that this is the month of March.)
X. Tree with 8 vertices. A tree with n vertices has n − 1 edges, so it has 7 edges.
XI. f o g(x). f(g(x)) = 2(x² − 1) + 1 = 2x² − 1.
XII. Smallest integer N with ⌈N/6⌉ = k. The value on the right is cut off in the original scan. In general ⌈N/6⌉ = k first happens when N = 6(k − 1) + 1. For example, ⌈N/6⌉ = 8 gives N = 6·7 + 1 = 43 (since ⌈42/6⌉ = 7 and ⌈43/6⌉ = 8).
XIII. Inverse of R = {(1,1), (1,2), (1,4), (3,4), (4,1)}. R−1 = {(1,1), (2,1), (4,1), (4,3), (1,4)} – swap each pair.
XIV. f(n) = 3f(n − 1) + 1, f(0) = 2. f(1) = 3·2 + 1 = 7, f(2) = 3·7 + 1 = 22, f(3) = 3·22 + 1 = 67.
XV. Remainder of −11/3. −11 = 3·(−4) + 1, with 0 ≤ r < 3, so the quotient is −4 and the remainder is 1.
XVI. ⌊−4.56⌋. The floor is the greatest integer ≤ −4.56, so ⌊−4.56⌋ = −5. (The ceiling would be ⌈−4.56⌉ = −4.)
Q2 – Distributive law and logical equivalence
(a) Union over intersection: A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C).
| A | B | C | B ∩ C | A ∪ (B ∩ C) | A ∪ B | A ∪ C | (A ∪ B) ∩ (A ∪ C) |
|---|---|---|---|---|---|---|---|
| 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 0 | 0 | 1 | 1 | 1 | 1 |
| 1 | 0 | 1 | 0 | 1 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 | 1 | 1 | 1 | 1 |
| 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Columns 5 and 8 are the same in all 8 rows, so the law holds.
(b) ¬(p ∨ (¬p ∧ q))
| Step | Law |
|---|---|
| ≡ ¬p ∧ ¬(¬p ∧ q) | De Morgan |
| ≡ ¬p ∧ (¬(¬p) ∨ ¬q) | De Morgan |
| ≡ ¬p ∧ (p ∨ ¬q) | Double negation |
| ≡ (¬p ∧ p) ∨ (¬p ∧ ¬q) | Distributive |
| ≡ F ∨ (¬p ∧ ¬q) | Negation law (¬p ∧ p ≡ F) |
| ≡ ¬p ∧ ¬q | Identity law |
Hence ¬(p ∨ (¬p ∧ q)) ≡ ¬p ∧ ¬q.
Q3 – Isomorphism and tree traversal
(a) G: edges u1u2, u2u4, u4u3, u3u1 (a 4-cycle). H: edges v1v3, v1v4 (diagonal), v2v3 (diagonal), v2v4 – also a 4-cycle v1–v3–v2–v4–v1 (the diagonals cross but there is no vertex at the crossing). Both have 4 vertices, 4 edges and every vertex has degree 2.
Define f(u1) = v1, f(u2) = v3, f(u4) = v2, f(u3) = v4. Then the edges map as u1u2 → v1v3, u2u4 → v3v2, u4u3 → v2v4, u3u1 → v4v1 – all edges of H. f is a one-to-one, onto map that preserves adjacency, so G and H are isomorphic. (Adjacency matrices in the orders u1, u2, u4, u3 and v1, v3, v2, v4 are identical.)
(b) Tree: a has children b, d; b has e, c; c has k, m; k has h, j; d has f, i; i has g.
| Traversal | Rule | Order |
|---|---|---|
| Pre-order | root, then subtrees left to right | a, b, e, c, k, h, j, m, d, f, i, g |
| Post-order | subtrees left to right, then root | e, h, j, k, m, c, b, f, g, i, d, a |
Q4 – Predicate calculus and sequences
(a) Let the domain be all people. S(x): x is a student in your class; C(x): x has a computer; P(x): x is perfect; D(x): x drinks coffee.
- i) ∀x (S(x) → C(x))
- ii) ¬∃x P(x), equivalently ∀x ¬P(x)
- iii) ∃x (S(x) ∧ D(x))
(b) i) 1, 1/2, 1/4, 1/8: each term is half the previous one, an = (1/2)n−1 = 1/2n−1 for n = 1, 2, 3, … ii) 1, 3, 5, 7: odd numbers, an = 2n − 1 for n = 1, 2, 3, …
Q5 – Pigeonhole principle and functions
(a) i) There are 2 colours (pigeonholes). With 3 socks, at least two must have the same colour (⌈3/2⌉ = 2), while 2 socks could be one brown and one black. So 3 socks.
ii) In the worst case he first takes all 12 brown socks; then 2 more must be black. So 14 socks.
(b) i) f(a) = 4, f(b) = 2, f(c) = 1, f(d) = 3: all images are different (one-to-one) and every element of {1, 2, 3, 4} is used (onto), so f is a bijection.
ii) If f(x1) = f(x2) then x1 + 1 = x2 + 1, so x1 = x2. Hence f(x) = x + 1 is one-to-one (on the integers or the reals).
Q6 – Cartesian product and relation properties
(a) A × B = {(1,a), (1,b), (1,c), (2,a), (2,b), (2,c)} and B × A = {(a,1), (a,2), (b,1), (b,2), (c,1), (c,2)}. For example (1, a) ∈ A × B but (1, a) ∉ B × A (ordered pairs, and 1 is not in B). So A × B ≠ B × A.
(b) R = {(x, y) | x ≠ y} on the integers:
| Property | Holds? | Reason |
|---|---|---|
| Reflexive | No | (1, 1) ∉ R because 1 = 1 |
| Symmetric | Yes | x ≠ y ⇒ y ≠ x |
| Anti-symmetric | No | (1, 2) and (2, 1) are both in R but 1 ≠ 2 |
| Transitive | No | (1, 2), (2, 1) ∈ R but (1, 1) ∉ R |
