Professional Documents
Culture Documents
ASSIGNMENT
by Jiten Shrestha
VICTORIA UNIVERSITY
Sydney Campus
NIT2212 Database2 Assignment 1
Contents
Question 1.............................................................................................................................................2
ER Diagram........................................................................................................................................2
Assumptions:.....................................................................................................................................2
Relational Schema:............................................................................................................................2
Question 2.............................................................................................................................................2
ER Diagram........................................................................................................................................2
Assumptions:.....................................................................................................................................2
Relational Schema:............................................................................................................................2
Question 3.............................................................................................................................................2
Question 4.............................................................................................................................................3
Question 4.1......................................................................................................................................3
Question 4.2......................................................................................................................................3
Question 5.............................................................................................................................................4
Question 1
ER Diagram
Assumptions:
The following assumptions are made in the ER Diagram above:
Each person has unique PersonID.
Person should be either an author/writer or a reader.
Book can have many editions.
Book can have many readers and a reader can read many books.
Book is written by only one author, but an author can write many books.
Relational Schema:
Table Field Type Description
PERSON PersonID INTEGER Primary Key
references Person(PersonID)
Rating INTEGER
Price INTEGER
Question 2
ER Diagram
Assumptions:
The following assumptions are made in the ER Diagram above:
A player has unique PlayerID.
Player plays with one opponent at a time and vice versa.
A player can play many matches and a match can have many players.
Relational Schema:
Table Field Type Description
PLAYER PlayerID INTEGER Primary Key
Ranking INTEGER
Score INTEGER
Question 3
Given two relations R and S such that R contains two attributes A and B and S
contains only one attribute B. Implement the division operator R/S by using
other relational algebra operators (e.g., Cartesian product, projection, minus
etc.). In other words, the result obtained by your relational algebra expressions
must be the same as the result obtained by R/S.
Solution:
Considering relations R and S with their attributes and values as:
R S
A B
a 1
b 2
c 2
B
1
2
A B C A B
a 1 1 A B b 2
a 1 2 a 1 c 2
b 2 1 b 2
b 2 2 c 2
c 2 1
c 2 2
Difference: R-S Division: R /S
A
Jiten Shrestha (s4581847) b Page | 5
c
NIT2212 Database2 Assignment 1
A B
a 1
If T be the result of the required expression, the division of the given relations can be
shown in the basic relational algebraic term as:
T1←∏C(R)
T2←∏C((T1 × S) − R)
T ← T1 − T2
T2←∏C((T1 × S) − R)
T ← T1 − T2
Question 4
Suppose that a page can contain at most 4 data values and all data values are
integers. Using B+ trees of order 2, give examples of each of the following:
Question 4.1
a B+ tree with number of levels changed from 1 to 2 when the value 60 is inserted.
Show your structure before and after the insertion. (2 Marks).
Solution:
B+ tree with number of levels changed from 1 to 2 before the insertion is:
2 5 10 20
12 30 40
1 2
6 8
2 5 10 20 40
40
20 12 16
1 2
6 8
Question 4.2
a B+ tree in which the deletion of the value 10 leads to a redistribution. Show
your structure before and after the deletion (2 Marks).
Solution:
B+ tree before the deletion is:
2 5 10 20 40
40
20 12 16
1 2
6 8
After deletion of the value 10 leads to the redistribution and the B+ tree becomes as:
3 6 12 20 40
40
20 12 16
1 2
6 8
Question 5
For each of the following transactions, determine if it is conflict serializable or
not? Show your working.
a.1) W1(X), R2(X), R1(Y), R3(X), W3(Y), R3(Y), R2(Y) (1 mark)
Solution:
Showing the above transactions in the table as:
T1 T2 T3
W1(X)
R2(X)
R1(Y)
R3(X)
W3(Y)
R3(Y)
R2(Y)
Which shows:
Write and read conflict between T1 and T2 on X variable
Read and write conflict between T1 and T3 on Y variable
Write and read conflict between T3 and T2 on Y variable
T1 T2
T3
The above graph shows an incomplete cycle, which means there is a conflict and
serializable.
Which shows:
Read and Write Conflict between T1 and T2 on X
Write and read conflict between T2 and T3 on Y
Showing the above transactions in the graph as:
T1 T2
T3
The above graph shows an incomplete cycle, so the transaction is conflict and
serializable.