DM Assignment 2
DM Assignment 2
1.1) Let A1, A2, ..…, An be sets. An ‘n - ary’ relation on these sets is a subset of A1 × A2 × …
× An. The sets A1, A2, ..…, An are called the domains of the relation, and ‘n’ is its degree.
1.1.1) A database of records consisting of ‘n’ tuples made up of fields. The fields are the
entries of the ‘n’ tuples. For instance, a database of student records containing the name,
student ID number, major and grade point average(GPA) of the student is made of fields.
The relational data model represents a database of records as an n - ary relation.
Thus, student records are represented as 4-tuples of the form “Student name, Student ID
number, Major, GPA.” A sample database of such records is :-
(Vishal, 840396, Physics, 4.99)
(Mohan, 353375, Chemistry, 4.90)
(Ramu, 778849, Zoology, 4.45)
(Shyam, 357693, Mathematics, 4.99)
(Jay, 653681, Computer Science, 4.85)
(Steve, 486087, Botany, 4.72)
Relations used to represent databases are also called tables, because these
relations are often displayed as tables. Each column of the table corresponds to an aspect of
the database. For instance, the same database of students is displayed in the above table.
The aspects of this database are Student Name, Student ID Number, Major, and GPA.
A domain of an n - ary relation is called a ‘primary key’ when the value of the
n-tuple from this domain determines the n-tuple i.e. a domain is a primary key when no two
n-tuples in the relation have the same value from this domain.
Records are often added to or deleted from databases. Because of this, the
property that a domain is a primary key is time-dependent. Consequently, a primary key
should be chosen that remains one whenever the database is changed. The current
collection of n-tuples in a relation is called the extension of the relation. The more
permanent part of a database, including the name and aspects of the database, is called its
intension. When selecting a primary key, the goal should be to select a key that can serve as
a primary key for all possible extensions of the database. To do this, it is necessary to
examine the intension of the database to understand the set of possible n-tuples that can
occur in an extension.
1.1.2)
Selection :- σ
The SELECT operation is used for selecting a subset of the tuples according to a given
selection condition. The symbol “σ” denotes sigma which is used as an expression to choose
tuples that meet the selection condition. The SELECT operator selects tuples that satisfy a
given predicate.
Register No.: 19ETCS002106 Name : Sakil Mustak
“σp(r)” where ‘σ’ is the predicate, ‘r’ stands for relation which is the name of the table and
‘p’ is prepositional logic.
An example is :-
Projection :- π
The projection eliminates all the attributes of the input relation except those mentioned in
the projection list. The projection method defines a relation that contains a vertical subset of
relation. This helps to extract the values of all specified attributes to eliminates duplicate
values. π (pi) is used to choose attributes from a relation. This operator helps you to keep
specific columns from a relation and discards the other columns.
Join :-
It allows us to establish the connections among data in different relations, taking advantage
of the valuebased nature of the relational model. Join operations are denoted by the symbol
⋈. There are various types of the join operation :
i) Inner joins
Theta join ( A ⋈θ B)
EQUI join (When a theta join uses only equivalence condition)
Natural join (A ⋈ B)
r1 (X1), r2 (X2)
r1 ⋈ r2 (natural join of r1 and r2) is a relation on X1X2 (the union of the two sets):
{ t on X1X2 | t [X1] ∈ r1 and t [X2] ∈ r2 } or, equivalently
{ t on X1X2 | exist t1 ∈ r1 and t2 ∈ r2 with t [X1] = t1 and t [X2] = t2 }
Offences :
Cars :
Offenses ⋈ Cars :
References :
i) Discrete Mathematics and Its Applications Seventh Edition book by Kenneth H Rose.
ii) https://www.guru99.com/
Part B :
2.1)
Given,
B1 = 1; B2 = 4; B3 = 9
Bn = Bn-1 – Bn-2 + Bn-3 + 4n-6 [∀n > 4]
B4 = B3 – B2 + B1 + 10 = 16
Register No.: 19ETCS002106 Name : Sakil Mustak
B5 = B4 – B5 + B2 + 14 = 16 -9 +4 +14 = 25
B6 = B5 – B4 + B3 + 18 = 25 – 16 + 9 + 18 = 36
By conjecturing we observe Bn = n2
2.2)
2.2.1)
We have n colours here.
P of the n colours can be selected in nCp ways.
The colours are painted on the p carriages of the train can be arranged in p! ways.
Therefore, total number of possible ways = nCp x p!
2.2.2)
In circular arrangement,
P colours can be arranged in (p-1)! ways.
Now, p arrangements of the (p-1)! ways will be the same.
P of the n colours can be selected in nCp ways.
Part C :
3.1)
3.1.1)
Given,
R be a relation on the set A={a,,b,c,d,e}, defined by
R = {(a,b),(a,c),(a,e),(b,a),(b,c),(c,a),(c,b),(d,a),(e,d)}
A = {a ,b ,c ,d ,e}
Reflexive closure is
Rc = {(a ,a ), (a ,b ), (a ,c ), (a ,d ), (a ,e ), (b ,a ), (b,b ), (b ,c ), (c ,e ), (c ,a) (c,b ), (d ,d ), (d ,a ),
(e ,d ), (e ,e )}
Symmetric closure is
S = {(a ,b ), (a ,c ), (a ,e ), (e, a ), (d ,a ), (a ,d ), (e ,d ), (d ,e ), (b ,a ), (b ,c), (c ,b ), (c ,a ),}
3.1.2)
Given,
R = {(a,b),(a,c),(a,e),(b,a),(b,c),(c,a),(c,b),(d,a),(e,d)}
Register No.: 19ETCS002106 Name : Sakil Mustak
From the above relation R can be taken in matrix form as
3.2)
3.2.1)
The required Hasse’s diagram is
or
3.2.2)
Using topological sorting :
Here,
c - chosen
m - minima
e - element
c
m a b c
e
Register No.: 19ETCS002106 Name : Sakil Mustak
c
m d e f
e
i
c
m g h i
e