0% found this document useful (0 votes)
3 views6 pages

DM Assignment 2

The document discusses the concepts of n-ary relations in databases, including primary keys, selection, projection, and join operations with examples. It also covers mathematical induction to prove a conjecture about a sequence, as well as combinatorial arrangements of colors on train carriages. Additionally, it explores reflexive, symmetric, and transitive closures of relations, along with Hasse diagrams and topological sorting.

Uploaded by

Pranav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

DM Assignment 2

The document discusses the concepts of n-ary relations in databases, including primary keys, selection, projection, and join operations with examples. It also covers mathematical induction to prove a conjecture about a sequence, as well as combinatorial arrangements of colors on train carriages. Additionally, it explores reflexive, symmetric, and transitive closures of relations, along with Hasse diagrams and topological sorting.

Uploaded by

Pranav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Register No.

: 19ETCS002106 Name : Sakil Mustak


Solutions :
Part A :

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.

Student name Student ID number Major GPA

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

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 :-

σ sales > 30000 (Buyers)


Output : Selects tuples from Buyers where sales is greater than 30000.

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.

An example is shown below :

Consider the following table.


Company ID Company Name Status
01 Amazon Active
02 Big Basket Inactive
03 Flipkart Active
04 Jiomart Active

Π Company Name, Status (Company).

Here, the projection of Company Name and status will show.


Company Name Status
Amazon Active
Big Basket Inactive
Flipkart Active
Jiomart Active

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)

ii) Outer joins

 Left Outer Join (A ⋈ B)


 Right Outer Join (A ⋈ B)
 Full Outer Join ( A ⋈ B)
Register No.: 19ETCS002106 Name : Sakil Mustak
An example of Natural Join :

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 :

Code Date Officer Deparment Registration


969533 01/06/1993 567 75 9673 AB
840375 03/06/1993 456 75 8472 XY
784935 14/06/1993 456 75 8472 XY
638135 29/06/1993 456 47 8472 XY
115123 21/06/1993 567 47 9673 AB

Cars :

Owner Deparment Registration


Justin 75 8472 XY
Waugh 47 9673 AB
Mark 75 9673 AB
Langer 47 8472 XY

Offenses ⋈ Cars :

Code Date Officer Deparment Registration Owner


969533 01/06/1993 567 75 9673 AB Mark
840375 03/06/1993 456 75 8472 XY Justin
784935 14/06/1993 456 75 8472 XY Justin
638135 29/06/1993 456 47 8472 XY Langer
115123 21/06/1993 567 47 9673 AB Waugh

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

To prove Bn = n2 by Mathematical induction


Basic Step : B1 = 12 = 1 is true.
Inductive step : Let us assume that Bk is true.
Then, Bk+1 must also be true.
Bk = Bk-1 - Bk-2 + Bk-3 + 4k-6 (where k > 4)
Bk+1 = Bk - Bk-1 + Bk-2 +4k-2
= Bk-1 - Bk-2 + Bk-3 + 4k-6 + Bk-1 + Bk-2 + 4k-2
= Bk-3 + 8k – 8
Bk = k 2

Bk+1 = (k+1)2 = B (k+2) - 1 – B(k+1) - 2 + B(k+6) - 3 + 4(k+2) – 6


P(k) -> P(k+1) is true
Therefore, by mathematical induction Bn = n2 ∀ n.

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

01101 01101 11101


10100 11101 11101
W0 = 1 1 0 0 0 W1 = 1 1 1 0 1 W2 = 1 1 1 0 1
10000 11101 11101
00010 00010 00010

11101 11101 11111


11101 11101 11111
W3 = 1 1 1 0 1 W4 = 1 1 1 0 1 W5 = 1 1 1 1 1
11101 11101 11111
00010 11111 11111

Therefore, transitive closure is


RT = {(a,a) (a,b) (a,c) (a,d) (a,e) (b,a) (b,b) (b,c) (b,d) (c,a) (c,b) (c,c) (c,d) (c,e) (d,a) (d,b) (d,c)
(d,d) (d,e) (e,a) (e,b) (e,c) (e,d) (e,e)}

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

You might also like