Assignment 2 Solution 1
Assignment 2 Solution 1
1. Determine whether the graph shown in figure i to iv has directed or undirected edges, whether
it has multiple edges, and whether it has one or more loops. Use your answers to determine
the type of graph.
Solution:
i) It has undirected edges. It has
multiple edges.
It has no loops.
It is undirected Multigraph.
2. The intersection graph of a collection of sets A1, A2,…, An is the graph that has a vertex for
each of these sets and has an edge connecting the vertices representing two sets if these
sets have a nonempty intersection. Construct the intersection graph of these collections of
sets.
i) A1 = {0, 2, 4, 6, 8}, A2 = {0, 1, 2, 3, 4}, A3 = {1, 3,
5, 7, 9}, A4 = {5, 6, 7, 8, 9}, A5 = {0, 1, 8, 9} ii) A1
= {…,−4,−3,−2,−1, 0}, A2 = {…,−2,−1, 0, 1, 2,…},
A3 = {…,−6,−4,−2, 0, 2, 4, 6,…}, A4 = {…,−5,−3,−1,
1, 3, 5,…},
A5 = {…,−6,−3, 0, 3, 6,…}
Solution:
lOMoAR cPSD| 46205556
i) ii)
3. (a) Find the number of vertices, the number of edges, and the degree of each vertex in the
given undirected graph. Also find the neighborhood
vertices of each vertex in given graphs. i) Number of
Vertices: 5 Number of edges:13 Degree of vertices:
deg(a) = deg(b) = deg(c) = 6, deg(d) = 5, deg(e) = 3.
Neighborhood Vertices:
N(a) = {a, b, e}, N(b) = {a, c, d, e}, N(c) = {b, c, d}, N(d) =
{b, c, e}, N(e) = a, b, d}
(b) Determine the number of vertices and edges and find the in-degree and out-degree of each
vertex for the given directed multigraph.
i) In-degree of a vertices
deg−(a) = 6, deg−(b) = 1, deg−(c) = 2, deg−(d) = 4, deg−(e) = 0.
4. (a) Suppose that a new company has five employees: Zamora, Agraharam, Smith, Chou, and
Macintyre. Each employee will assume one of six responsibilities: planning, publicity, sales,
marketing, development, and industry relations. Each employee is capable of doing one or
more of these jobs: Zamora could do planning, sales, marketing, or industry relations;
Agraharam could do planning or development; Smith could do publicity, sales, or industry
relations; Chou could do planning, sales, or industry relations; and Macintyre could do
planning, publicity, sales, or industry relations. Model the capabilities of these employees
using appropriate graph. Solution: Bipartite Graph
lOMoAR cPSD| 46205556
(b) Suppose that there are four employees in the computer support group of the School of
Engineering of a large university. Each employee will be assigned to support one of four
different areas: hardware, software, networking, and wireless. Suppose that Ping is qualified
to support hardware, networking, and wireless; Quiggley is qualified to support software and
networking; Ruiz is qualified to support networking and wireless, and Sitea is qualified to
support hardware and software. Use appropriate graph to model the four employees and their
qualifications. Solution: Bipartite Graph
5. Find which of the following graphs are bipartite. Redraw the bipartite graphs so that their
bipartite nature is evident. Also write the disjoint set of vertices.
i) ii) iii) iv)
Solution:
(a) Not bipartite (since a is adjacent to b & f vertices)
(b)Bipartite (A (V1, V3, V5) & B (V2, V4, V6))
(c) Not bipartite (since V4 & V5 are adjacent vertices)
(d)Not Bipartite (since b is adjacent to d & e vertices)
6. Draw a graph with the specified properties or show that no such graph exists.
a) A graph with four vertices of degrees 1, 1, 2, and 3
b) A graph with four vertices of degrees 1, 1, 3, and 3
c) A simple graph with four vertices of degrees 1, 1, 3, and 3
Solution:
a) No such graph is possible. By Handshaking theorem, the total degree of a graph is
even.
But a graph with four vertices of degrees 1, 1, 2, and 3 would have a total degree of 1 + 1 + 2 +
3 = 7, which is odd. b) Let G be any of the graphs shown below.
lOMoAR cPSD| 46205556
In each case, no matter how the edges are labeled, deg(a) = 1, deg(b) = 1, deg(c) =3, and
deg(d) = 3.
c) There is no simple graph with four vertices of degrees 1, 1, 3, and 3.
7. a) In a group of 15 people, is it possible for each person to have exactly 3 friends? Explain.
(Assume that friendship is a symmetric relationship: If x is a friend of y, then y is a friend of
x.) Solution:
By using Handshaking theorem.
No! there is no graph possible, such that 15 vertices have degree 3. Since (15 * 3) ≠ 2e.
b) In a group of 4 people, is it possible for each person to have exactly 3 friends?
Why? Solution:
By using Handshaking theorem.
Yes! there is graph possible, such that 4 vertices have degree 3. Since (4 * 3) = 2e.
8. (a) Find the union of the given pair of simple graphs. (Assume edges with the same endpoints
are the same.)
i) ii)
Solution:
i) ii)
b) How many vertices does a regular graph of degree four with 10 edges
have? Solution:
lOMoAR cPSD| 46205556
9. For given pair (G, G’) of graphs. Determine whether they are isomorphic. If they are, give
function g: V (G) →V (G/) that define the isomorphism. If they are not, give an invariant for
graph isomorphism that they do not share. i)
Solution: Both graph G and G’ are satisfying all the invariant. Hence, they are isomorphic.
Function: g(V1) = W2, g(V2) = W3 g(V3) = W1 g(V4) = W5 g(V5) = W4
ii)
Solution: Both graph G and G’ are satisfying all the invariant. Hence, they are isomorphic.
Function: g(V1) = U5, g(V2) = U2 g(V3) = U4 g(V4) = U3 g(V5) = U1 g(V6) = U6
iii)
Solution: Both graph G and G’ are satisfying all the invariant. Hence, they are isomorphic.
Function: g(V1) = U5, g(V2) = U4 g(V3) = U3 g(V4) = U2 g(V5) = U7
g(V6) = U1 g(V7) = U6
iv)
lOMoAR cPSD| 46205556
Solution: Graph G has no vertex of degree 4 where G’ has vertex V2 with degree 4. Hence, they
are not isomorphic.
10. Find the length of a shortest path between a and z in the given weighted graph by using
Dijkstra’s algorithm. i)
ii)
lOMoAR cPSD| 46205556
i) Solution:
Hamiltonian Circuit are: ABCDA = 125; ABDCA = 140; ACBDA =
Hence ABCDA = 125 is the minimum distance 155.
travelled. ii) Solution:
Hamiltonian Circuit are: ABCDA = 97; ABDCA = 108; ACBDA =
Hence ABCDA = 97 is the minimum distance travelled. 141.
12. (a) The following is a floor plan of a house. Is it possible to enter the house in room A,
travel through every interior doorway of the house exactly once, and exit out of room E?
If so, how can this be done?
Solution:
Yes! Path: A
→H→G→B→C→D→G→F→E
(b)The floor plan shown below is for a house that is open for public viewing. Is it possible
to find a trail that starts in room A, ends in room B, and passes through every interior
doorway of the house exactly once? If so, find such a trail.
lOMoAR cPSD| 46205556
13. Find Hamiltonian circuits AND Path for those graphs that have them. Explain why the other
graphs do not.
i) ii) iii)
i) Solution:
Hamiltonian Circuit: V0, V1, V2, V6, V5, V4,
V7, V3, V0 Hamiltonian Path: V0, V1, V2, V6,
V5, V4, V7, V3 ii) Solution:
Hamiltonian Circuit: doesn’t
exist Hamiltonian Path: b, c, f,
g, h, e, a, d iii) Solution:
Hamiltonian Circuit: d, c, b, a, g, f, e, d
Hamiltonian Path: d, c, b, a, g, f, e
14. a) Determine which of the graphs have Euler circuits. If the graph does not have an Euler
circuit, explain why not. If it does have an Euler circuit, describe one.
i) ii)
(b)Determine whether there is an Euler path from u to w. If the graph does not have an Euler
path, explain why not. If it does have an Euler path, describe one.
i) ii)
i) Solution:
Euler Path doesn’t exist because four vertices have odd degree.
ii) Solution: Euler Path exists because exact two vertices have odd degree.
Euler path: U, V1, V0, V7, U, V2, V3, V4, V2, V6, V5, W, V6, V4, W
15. (a) Use an incidence matrix to represent the graph shown below.
i) ii)
Solution: i) ii)
Solution:
i) ii)
16. Use an adjacency list and adjacency matrix to represent the given graph. i)
lOMoAR cPSD| 46205556
(ii)
iv)
Solution:
i) What is the level of n? Level of n is 3.
ii) What is the level of a? Level of a is 0.
iii) What is the height of this rooted Height of this rooted tree is 5
tree?
lOMoAR cPSD| 46205556
18. Use Prim’s algorithm to find a minimum spanning tree starting from V0 for given graphs.
Indicate the order in which edges are added to form
each tree. i) Solution: MST Cost = 61
(V0,V5) = 4, (V5,V6) = 8, (V4,V5) = 10,
(V3,V4) = 2, (V1,V3) = 5, (V6,V7) = 13,
(V2,V7) = 19.
ii)
19. Use Kruskal’s algorithm to find a minimum spanning tree for given graphs. Indicate the order
in which edges are added to form each tree.
i) ii)
21. Determine the order in which preorder, Inorder and Postorder traversal visits the
vertices of the given ordered rooted tree.
i) ii)
lOMoAR cPSD| 46205556
Solution:
i)
Preorder: a b e k l m f g n r s c d h o I j p q
Inorder: k e l m b f r n s g a c o h d i p j q
Postorder: k l m e f r s n g b c o h I p q j d a
ii)
Preorder: a b d e i j m n o c f g h k l p
Inorder: d b i e m j n o a f c g k h p l
Postorder: d i m n o j e b f g k p l h c a
22. (a) How many edges does a tree with 10000 vertices have? Solution:
A tree with n vertices has n – 1 edge. Hence 10000 – 1 = 9999 edges.
(b) How many edges does a full binary tree with 1000 internal vertices have?
Solution:
A full binary tree has two edges for each internal vertex. So, we’ll just multiply the
number of internal vertices by the number of edges. Hence 1000 * 2 = 2000 edges.
(c) How many vertices does a full 5-ary tree with 100 internal vertices have?
Solution:
25. Find a spanning tree for the graph shown by removing edges in simple circuits. Write
down the removed edges.
(i) ii) iii)
Solution:
i) ii) iii)
13
lOMoAR cPSD| 46205556
26. (--------------------------)
27. Let R be the following relation defined on the set {a, b, c, d}:
R = {(a, a), (a, c), (a, d), (b, a), (b, b), (b, c), (b, d), (c, b), (c, c), (d, b), (d, d)}
Determine whether R is:
(a) Reflexive: (b) Symmetric (c)
Antisymmetric
(d) Transitive (e) Irreflexive (f) Asymmetric
Solution:
(a) R is reflexive because R contains ( a, a ), ( b, b ), ( c, c ), and ( d, d ).
(b)R is not symmetric because R contains ( a, c ) but not ( c, a ) ∈ R .
(c) R is not antisymmetric because both ( b, c ) ∈ R and ( c, b ) ∈ R , but b = c.
(d)R is not Transitive because both ( a, c ) ∈ R and ( c, b ) ∈ R , but not ( a, b ) ∈ R.
(e) R is not irreflexive because R contains ( a, a ), ( b, b ), ( c, c ), and ( d, d ).
(f) R is not Asymmetric because R is not Antisymmetric.
28. List the ordered pairs in the relation R from A = {0, 1, 2, 3, 4} to B = {0, 1, 2, 3}, where (a,
b) ∈
R if and only if
a) a = b. b) a + b = 4. c) a > b.
d) a | b. e) gcd(a, b) = 1. f) lcm (a, b) =
2.
Solution:
a) { (0,0), (1, 1), (2, 2), (3, 3) }
b) { (1, 3), (2, 2), (3, 1), (4, 0) }
c) { (1, 0), (2, 0), (3, 0), (4, 0), (2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3) }
d) { (1, 0), (2, 0), (3, 0), (4, 0), (1, 1), (1,2), (2,2), (1,3), (3,3) }
e) { (1,0), (0,1), (1,1), (1,2), (1,3), (2,1), (3,1), (4,1), (2,3),(3,2),(4,3) } f) { (1,2), (2,1), (2,2) }
29. List all the ordered pairs in the relation R = {(a, b) | a divides b} on the set {1,
2, 3, 4, 5, 6}. Display this relation as Directed Graph(digraph), as well in
matrix form. mSolution:
R= { (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (1, 6), (2, 2), (2, 4), (2, 6), (3, 3), (3, 6), (4, 4), (5, 5), (6, 6)
}
𝟏 𝟏 𝟏 𝟏 𝟏 𝟏
𝖥𝟎 𝟏 𝟎 𝟏 𝟎 𝟏1 𝟎 𝟎 𝟏 𝟎𝟎𝟏
𝟎𝟎 𝟎 𝟏𝟎𝟎
I𝟎𝟎 𝟎 𝟎 𝟏 𝟎I
[𝟎𝟎 𝟎 𝟎 𝟎 𝟏]
30. For each of these relations on the set {1, 2, 3, 4}, decide whether it is
reflexive, whether it is symmetric, whether it is antisymmetric, and whether
it is transitive.
lOMoAR cPSD| 46205556
a) { (2, 2), (2, 3), (2, 4), (3, 2), (3, 3), (3, 4) }
Solution:
a. R is not reflexive: It doesn’t contain (1,1) and (4,4).
b. R is not symmetric because R contains (2, 4) but not (4, 2) ∈ R.
c. R is not antisymmetric: we have (2,3) and (3,2) but 2 ≠ 3.
d. R is Transitive because for any numbers a, b, and c, if (a, b), (b, c) ∈ R then (a,
c) ∈ R.
b) { (1, 1), (1, 2), (2, 1), (2, 2), (3, 3), (4, 4) }
Solution:
a. R is reflexive: It contains (1,1) ,(2,2), (3,3) and (4,4).
b. R is symmetric because (a,b) and (b,a) ∈ R.
c. R is not antisymmetric: we have (1,2) and (2,1) but 1 ≠ 2.
d. R is Transitive because for any numbers a, b, and c, if (a, b), (b, c) ∈ R then
(a, c) ∈ R.
f) {(1, 3), (1, 4), (2, 3), (2, 4), (3, 1), (3, 4)}
Solution:
31. Determine whether the relation R on the set of all people is reflexive,
symmetric, antisymmetric, Asymmetric, irreflexive and/or transitive,
where (a, b) ∈ R if and only if: a) a is taller than b. Solution:
lOMoAR cPSD| 46205556
c) a
has the same first name as b.
Solution:
Find:
a) R2 𝖴 R4. b) R3 𝖴 R6. c) R3 ∩ R6. d) R4 ∩
R6.
e) R3 − R6. f) R6 − R3. g) R2 ⊕ R6. h) R3 ⊕
R5.
i) R2 ◦ R1. j) R6 ◦ R6.
Solution:
R1= { (2,1), (3,1), (3,2) } R2= { (1,1), (2,2), (3,3), (2,1), (3,1), (3,2) }
R3= { (1,2), (1,3), (2,3) } R4= { (1,1), (2,2), (3,3), (1,2), (1,3), (2,3) }
R5= { (1,1), (2,2), (3,3) } R6= {(1,2), (1,3), (2,1), (2,3), (3,1), (3,2) }
iv) { ( 1 , 3), ( 3 , 1) 𝟏
} 𝟎]
𝟎 𝟎 𝟎
Solution: [𝟎 𝟎 𝟏
𝟎
35. (a) Suppose that R is the relation on the set of strings of English letters such that aRb if
and only if l(a) = l(b), where l(x) is the length of the string x. Is R an equivalence relation?
Solution:
Show that all of the properties of an equivalence relation hold.
• Reflexivity: Because l(a) = l(a), it follows that aRa for all strings a.
• Symmetry: Suppose that aRb. Since l(a) = l(b), l(b) = l(a) also holds and bRa.
• Transitivity: Suppose that aRb and bRc. Since l(a) = l(b),and l(b) = l(c), l(a) = l(a)
also holds and aRc.
(b) Let m be an integer with m > 1. Show that the relation R = {(a,b) | a ≡ b (mod m)}
is an equivalence relation on the set of integers.
Solution:
Recall that a ≡ b (mod m) if and only if m divides a − b.
• Reflexivity: a ≡ a (mod m) since a − a = 0 is divisible by m since 0 = 0 ∙ m.
• Symmetry: Suppose that a ≡ b (mod m). Then a − b is divisible by m, and so a − b
= km, where k is an integer. It follows that b − a = (− k) m, so b ≡ a (mod m).
• Transitivity: Suppose that a ≡ b (mod m) and b ≡ c (mod m). Then m divides both
a − b and b − c. Hence, there are integers k and l with a − b = km and b − c = lm.
We obtain by adding the equations: a − c = (a − b) + (b − c) = km + lm = (k + l) m.
Therefore, a ≡ c (mod m).
lOMoAR cPSD| 46205556
36. (a) Find the first five terms of the sequence for each of the following general terms
where n >0.
(i) 𝟐𝒏 − 𝟏
Solution:1,2,4,8,16 are the first five terms of the given sequence.
𝟑
(ii) 𝟏𝟎 − 𝒏
𝟐
Solution:
𝟏𝟏 𝟓
𝟏𝟕 , 𝟕, , 𝟒, are the first five terms.
𝟐 𝟐 𝟐
𝒏
(iii) (−𝟏)
𝒏𝟐
Solution:
𝟏 𝟏 𝟏 𝟏
−𝟏, , − , , − are the first five terms.
𝟒 𝟗 𝟏𝟔 𝟐𝟓
(iv) 𝟑𝒏+𝟒
𝟐𝒏−𝟏
𝟏𝟎 𝟏𝟑 𝟏𝟔 𝟏𝟗
Solution: 𝟕, , , , are the first five terms.
𝟑𝟓𝟕𝟗
(b) Identify the following Sequence as Arithmetic or Geometric Sequence then find the
indicated term.
𝟐
𝒏 𝟏𝟕 = 𝟑𝟐( )
𝟖
lOMoAR cPSD| 46205556
𝑻𝟓 = 𝒂𝒓𝟒 = 𝟖 ----(i)
𝑻𝟖
𝟔𝟒 -------
= 𝒂𝒓𝟕 = − (ii)
𝟐𝟕
lOMoAR cPSD| 46205556
𝟐
Now, dividing (ii) by dividing (i) we get r = − and putting it in (i) we get a = 𝟖𝟏.
𝟑 𝟐
Now the required G.P is 𝟖𝟏 , −𝟐𝟕, 𝟏𝟖, −𝟏𝟐, 𝟖,...
𝟐
38. (a) How many numbers are there between 256 and 789 that are divisible by 7. Also find
their sum.
Solution:
First, we find the A.P with the common difference (d)= 7 259,266,273,
280, ,……. 784
Since 𝑻𝒏 = 𝒂 + (𝒏 − 𝟏)𝒅 ;
𝟕𝟖𝟒 = 𝟐𝟓𝟗 + (𝒏 − 𝟏)(𝟕) ;
n = 76.
𝒏
Now for Sum; 𝑺𝒏 = 𝟐 [𝟐𝒂 + (𝒏 − 𝟏)𝒅];
𝟕𝟔
𝑺𝟕𝟔 = 𝟐 [𝟐(𝟐𝟓𝟗) + (𝟕𝟔 − 𝟏)(𝟕)] = 39,634.
𝟐−𝒏+𝟏
(b) Find the sum to n terms of an A.P whose first term is and the last term is 𝒏 𝟏 .
𝒏 𝒏
Solution:
𝒏
------
Since, 𝑺𝒏 = 𝟐 [𝟐𝒂 + (𝒏 − 𝟏)𝒅] (i)
st
1 we have to find “d”
Now, 𝑻𝒏 = 𝒂 + (𝒏 − 𝟏)𝒅
𝒏𝟐 − 𝒏 + 𝟏 𝟏
= + (𝒏 − 𝟏)𝒅
𝒏 𝒏
Finally, d = 1. Hence putting it in we get,
𝒏𝟐−𝒏+𝟐 𝑺𝒏
= 𝟐
.
lOMoAR cPSD| 46205556
39. (a) Use summation notation to express the sum of the first 100 terms of the sequence {aj
}, where
𝟏 aj = for j = 1,
2, 3….
𝖩̅
Solution: 𝟏𝟎𝟎 𝟏
The lower limit for the index of summation is 1, and the upper limit is 100. We write this sum as
𝒋 𝟏 𝒋
Solution:
= (−1)4 + (−1)5 + (−1)6 + (−1)7 +
8
(−1) = 1 + (−1) + 1 + (−1) + 1 = 1.
(ii) ∑𝟓 (𝒋)𝟐 ⋅
𝒋=𝟏
Solution:
= 12 + 22 + 32 + 42 +
52 = 1 + 4 + 9 + 16 + 25 =
55.
40. Find the first six terms of the sequence defined by each of these recurrence
relations and initial conditions.
a) an = −2an−1, a0 = −1
Solution:
b) an = an−1 − an−2, a0 = 2, a1 =
−1 Solution:
c) an = 3a2n−1, a0 = 1 Solution:
lOMoAR cPSD| 46205556
41. As we have discussed, the practical application of all the topics in the class. Now
you are required to submit at least two real world applications of the following topics.
(a) Propositional Logic
3. “Is φ valid?” corresponds to “Is the set represented by φ the universal set?”
These connections allow using propositional formulas as a data structure in
some applications in which conventional enumerative data structures for sets
are not suitable because of the astronomic number of states. For example, if
there are 100 state variables, then any formula consisting of just one atomic
proposition represents a set of 2 99 =
633825300114114700748351602688 bit-vectors, which would require
7493989779944505344 TB in an explicit enumerative representation if each of
the 100-bit vectors was represented with 13 bytes (wasting only 4 bits in the 13th
byte.)
Basic Boolean search commands (quotes, AND and OR) are supported in
Google search, however Google defaults to AND searches automatically, so you
don't need to enter AND into the search box. Google search uses additional
symbols and words to refine searches such as "site:" to search a specific site
or domain or use $ in front of a number to search for a price.
Note: No further parentheses are needed here, and according to the syntax on
the handout, no further parentheses are possible. But “extra parentheses” are
in general considered acceptable, and if you find them helpful, I have no
objection. So I would also count as correct any of the following: x (love (Mary,
x)), ( x love (Mary, x)), ( x (love (Mary, x)))
Computer infers new conclusions in the same way using predicate logics and quantifiers.
Predicate Logic can be utilized to check legitimacy of a deduced conclusion. Using predicate
logic, we can validate inferences.
Consider these statements, of which the first three are premises and the fourth is a valid
conclusion.
Let P(x), Q(x), R(x), and S(x) be the statements “x is a hummingbird,” “x is large,” “x lives
on honey,” and “x is richly colored,” respectively. Assuming that the domain consists of
all birds, express the statements in the argument using quantifiers and P(x), Q(x), R(x),
and S(x).
Solution: We can express the statements in the
argument as ∀x(P(x) → S(x)).
¬∃x(Q(x) 𝖠 R(x)).
∀x(¬R(x)→¬S(x)).
∀x(P(x)→¬Q(x)).
(c) Sets
Clusters are likely the most well-known assortment type. A cluster stores an arranged
assortment of qualities. As I referenced before, the qualities put away in an exhibit are of a
similar sort. Sets and exhibits share a few highlights for all intents and purpose. The two
of them store an assortment of estimations of a similar kind. You can include and
evacuate components if the set or cluster is variable in this way exhibit is inferred for the
idea of set wherein each position has interesting worth simply like sets.
EXAMPLES:
Char array [6] = {‘a’, ‘b’, ‘c’, ‘d’, ‘e’,
‘f’}
In sets, this can be represented in the following way:
{(0,a), (1,b), (2,c), (3,d), (4,e),
(5,f)}
SQL is a domain-specific language used in programming and designed for managing data
held in a relational database management system, or for stream processing in a relational
data stream management system.
lOMoAR cPSD| 46205556
EXAMPLE:
1. Union:
This set operator is used to combine the outputs of two or more queries into a
single set of rows and columns having different records.
2. Union All:
This set operator is used to join the outputs of two or more queries into a single
set of rows and columns without the removal of any duplicates.
3. Intersect:
This set operator is availed to retrieve the information which is common in both
tables. The number of columns and data type must be same in intersect set
operator.
(d) Functions
Functions is the essential part of learning PC writing computer programs is tied in with taking
a contribution from the client then in the wake of experiencing some work restoring a worth
simply like taking an area and delivering a range.