0% found this document useful (0 votes)
51 views146 pages

PA,GAS

The document contains practice assignment questions and solutions related to database management systems (DBMS), covering topics such as levels of abstraction, data independence, SQL statements, and data models. It includes multiple-choice questions with correct answers and explanations for each, focusing on concepts like foreign keys, compound keys, and SQL operations. The assignment is structured over two weeks, with various scenarios and examples to illustrate the application of DBMS principles.

Uploaded by

24f1002200
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)
51 views146 pages

PA,GAS

The document contains practice assignment questions and solutions related to database management systems (DBMS), covering topics such as levels of abstraction, data independence, SQL statements, and data models. It includes multiple-choice questions with correct answers and explanations for each, focusing on concepts like foreign keys, compound keys, and SQL operations. The assignment is structured over two weeks, with various scenarios and examples to illustrate the application of DBMS principles.

Uploaded by

24f1002200
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/ 146

BSCCS2001: Practice Assignment with Solutions

Week 1

1. A programmer is working on the data structures that store data internally in a database.
At what level of abstraction is the programmer working?
Logical Level
View Level
Programming Level

Physical Level

Solution:
Logical Level represents the relational model and conceptual schema of the data.
View Level represents the user’s view of the data i.e how the user sees the data

Physical level deals with the actual storage structure of the data internally in the
form of trees and other data structures.

Programming level is not a level of abstraction.

2. From among the given types of applications, choose the ones for which DBMS will be a
preferred choice over filesystems.

Applications with large datasets.

Applications with concurrent transactions.
Applications with small datasets.
Applications with no dedicated database administrators.

Solution:
For applications with small datasets, the overhead in installing the DBMS will be
much more than the advantage obtained due to reduced retrieval time.
If there is no dedicated personnel for maintaining a database, the performance will
begin to deteriorate after a period of time.

3. By the concept of Logical Data Independence, a change in the logical level of DBMS
should not affect which other level(s) of abstraction?

View Level
Physical Level
Both Physical and View Level
None of the above

Solution:
Logical Data Independence: A change in Logical Level of DBMS should not
affect the View Level.

4. By the concept of Physical Data Independence, a change in the physical level of DBMS
should not affect which other level(s) of abstraction?
View Level
Logical Level

Both Logical and View Level
None of the above

Solution:
Physical Data Independence: A change in Physical Level of DBMS should not
affect either the View Level or the Logical Level.

5. Which model is widely used during the planning and designing phase of a database
system?
View Model

Entity-Relationship Model
Object Model
Relational Model

Solution: Entity-Relationship Model is used to define a high level view of the data
entities and the relationships between them. It is used mainly for designing and
planning the database structure.

6. Which of the following are advantages of DBMS over file based data management appli-
cations?

Easy recovery of data

Consistency of data

Efficiency of operation
Ease of initial setup

Page 2
Solution: Initial system setup is costly in the case of DBMS, whereas in file based
systems, it is relatively easy and economical.

7. Which among the following is a good option for exchanging data among different systems
over the internet?
HTML
MS Access
SQL

XML

Solution: HTML is a markup language used mainly for data presentation, whereas
XML is widely used for sharing data over different systems over the web. The other
two are not meant for information exchange over the internet.

8. Planning what attributes should be placed in which table of a database is a part of


Attribute Design

Logical Design
Physical Design
Subsystem Design

Solution: The design of structure of tables is a part of logical design.

9. Which of the following options are examples of data transactions?



Transferring funds using e-wallets

Booking a reservation in railways
Increasing the data storage capacity

Updating KYC in bank.

Solution: Any event which modifies the current state (value) of the data is a data
transaction.
Increasing storage capacity does not make any changes in the current data.

10. Which data model aptly satisfies the need of a system which maintains large set of com-
plex interconnected data, where the semantics of interconnection changes dynamically
(like a social networking site)?

Page 3
Relational Model
XML Model
Object-Relational Model

Graph Model

Solution: Refer Lecture 1.4.

Page 4
BSCCS2001: Practice Assignment with Solutions
Week 2

Modules covered:

1. Attribute Types, Relation Schema and Instance, Keys, Relational Query Languages

2. Operations, Select, Project, Union, Difference, Intersection, Cartesian Product

3. Natural Join, Aggregate Operations

4. Introduction to SQL - History of SQL, Data Definition Language (DDL), Basic Query
Structure (DML)

5. Additional Basic Operations, Set Operations, Null Values, Aggregate Functions


1. Consider the table taskAssignment (in Figure 1) which represents tasks assigned to
each employee for a given day. [MCQ: 2 points]

Figure 1: Table taskAssignment

Select the appropriate compound key for the table.


{ employee num }
{ employee num, task num }

{ employee num, task num, date of assignment }
{ employee num, supervisor num }

Solution: A compound key is a set of more than one attribute which uniquely iden-
tifies all rows of a relation.
The entries for { employee num } are not unique for all the tuples. It is neither a
set of more than one attribute nor uniquely identifies all rows of the given relation.
Thus, it cannot be a compound key.
The entries for { employee num, task num } are not unique for all the tuples. Thus,
it cannot be a compound key.
The entries for {employee num, task num, date of assignment} are unique for all the
rows. So, it is a valid candidate key for the given relation.
The entries for { employee num, supervisor num } are not unique for all the tuples.
Thus, it cannot be a compound key.

Page 2
2. Consider the following relational schema on students of a school. [MCQ: 2 points]
studentInfo (enrollment num, class, section, roll, name).
{enrollment num} and {class, section, roll} are two possible candidate keys. What is
the maximum number of possible superkeys of studentInfo?
16

18
20
22

Solution: This question will be discussed in the Solve with the Instructor session.

Page 3
3. Consider the tables vendor and component as shown in Figure 2. The table com-
ponent has attribute vendor num which is a foreign key that refers to table ven-
dor(vendor num).

Figure 2: Tables vendor and component

Identify the appropriate “CREATE TABLE” statement for table component. [MCQ:
2 points]
CREATE TABLE component(
item_num int NOT NULL,
name varchar(20),
cost numeric(6, 2) NOT NULL,
vendor_num int NOT NULL,
PRIMARY KEY (item_num),
FOREIGN KEY (vendor_num) REFERENCES vendor(vendor_num));
CREATE TABLE component(
item_num int NOT NULL,
name varchar(20),
cost numeric(6, 2) NOT NULL,
vendor_num int NOT NULL,
PRIMARY KEY (item_num, name),
FOREIGN KEY (vendor_num) REFERENCES vendor(vendor_num));
CREATE TABLE component(
item_num int NOT NULL,
name varchar(20),
cost numeric(6, 2) NOT NULL,
vendor_num int NOT NULL,
PRIMARY KEY (item_num, vendor_num),
FOREIGN KEY (vendor_num) REFERENCES vendor(item_num, vendor_num));

CREATE TABLE component(
item_num int NOT NULL,
name varchar(20),

Page 4
cost numeric(6, 2) NOT NULL,
vendor_num int NOT NULL,
PRIMARY KEY (item_num, vendor_num),
FOREIGN KEY (vendor_num) REFERENCES vendor(vendor_num));

Solution:
Option 1: since the table component has duplicate values in the column item num,
the attribute set {item num} cannot be a primary key. Hence, option 1 is incorrect.
Option 2: since table component has duplicate values in columns {item num,
name}, the attribute set {item num, name} cannot be a primary key. Hence, option
2 is incorrect.
Option 3: since the number of columns in the foreign key does not match the number
of columns in the referenced table, option 3 is incorrect.
Option 4: since table component has unique entries in columns {item num, ven-
dor num}, attribute set {item num, vendor num} is the proper primary key and
hence, option 4 is the correct option.

Page 5
4. Identify the appropriate “ALTER TABLE” statement for table vendor such that we can
add a column named vendor phone to store the phone number of the vendors. [MSQ: 2
points]

ALTER TABLE vendor APPEND COLUMN vendor_phone numeric(10);



ALTER TABLE vendor ADD COLUMN vendor_phone numeric(10);

ALTER TABLE vendor ADD vendor_phone numeric(10);
ALTER TABLE vendor INSERT COLUMN vendor_phone numeric(10);

Solution: To add a new column in the given table, we use “ADD” or “ADD
COLUMN” commands. Thus, option 2 and option 3 are correct.

Page 6
5. Identify the correct statement(s) about a Foreign Key. [MSQ: 2 points]
A FOREIGN KEY is a data element/attribute within a data field of a data
record that is not unique, and cannot be used to distinguish one data record
in a database from another data record within a database table.
A FOREIGN KEY constraint prevents data from being inserted into the for-
eign key column.

A FOREIGN KEY is a data element/attribute within a data field of a data
record within a database table that refers to either a primary key or an at-
tribute with unique constraint.

A FOREIGN KEY can be added at the time of ALTER TABLE query.

Solution: Option 1 - A FOREIGN KEY is a data element/attribute within a data


field of a data record that is unique, and this can be used to distinguish one data
record in a database from another data record within a database table.
Option 2 - The FOREIGN KEY constraint prevents invalid data from being inserted
into the foreign key column.
Option 3, 4 are factual statements about Foreign Key.

Page 7
6. Consider the table Employee given in Figure 3.

Figure 3: Table Employee

Determine the correct relation based on the three queries given below: [MCQ: 2 points]

• SELECT COUNT(DISTINCT Salary) as A FROM Employee;


• SELECT COUNT(*) as B FROM Employee;
• SELECT COUNT(Salary) as C FROM Employee;
value of B>A and B=C
value of A>B and B>C
value of A>B and B=C

value of B>A and B>C

Solution: This question will be discussed in the Solve with the Instructor session.

Page 8
7. Consider the table Employee given in Figure 4.

Figure 4: Table Employee

Determine the suitable query that returns the following table: [MCQ: 2 points]

SELECT AVG(Salary) AS AVG_SAL


FROM Employee WHERE Salary IS NOT NULL AND ID>5;
SELECT AVG(Salary) AS AVG_SAL
FROM Employee WHERE Salary IS NOT NULL AND Salary>50;
SELECT AVG(Salary) AS AVG_SAL
FROM Employee WHERE Salary IS NOT NULL AND ID>3;

SELECT AVG(Salary) AS AVG_SAL
FROM Employee WHERE Salary IS NOT NULL AND Salary>35;

Solution: From the table Employee, NOT NULL values that are greater than 35
are 50, 50, 70, 50. The average of 50, 50, 70, 50 is 55.

Page 9
8. Identify the output for the following SQL statement. [MCQ: 2 points]

SELECT max(temperature) - min(temperature)


FROM weatherReport
WHERE state=‘Karnataka’;

4

5
2
0

Solution: The part of the statement:

WHERE state=‘Karnataka’;

extracts all rows having state as “Karnataka”.


max(temperature) returns the maximum temperature from among the given cities
in “Karnataka”, i.e. 36 (for “Bellary”).
min(temperature) returns the minimum temperature from among the given cities
in “Karnataka”, i.e. 31 (for “Bengaluru”).
Therefore, the output is 36 - 31 = 5;

Page 10
9. Using the table Citizen given in Figure 5, answer the question that follows.

Figure 5: Table Citizen

Identify the correct SQL statement(s) to create the given table. [MSQ: 2 points]
CREATE TABLE Citizen (ID int NOT NULL,
profession varchar(255), lastname varchar(255) NOT NULL,
firstname varchar(255), PRIMARY KEY (ID));

CREATE TABLE Citizen (ID int NOT NULL,
profession varchar(255), lastname varchar(255) NOT NULL,
firstname varchar(255), PRIMARY KEY (ID, lastname));

CREATE TABLE Citizen (ID int,
profession varchar(255), lastname varchar(255) NOT NULL,
firstname varchar(255), PRIMARY KEY (firstname, lastname));

CREATE TABLE Citizen (ID int NOT NULL,
profession varchar(255), lastname varchar(255) NOT NULL,
firstname varchar(255), PRIMARY KEY (ID, profession));
CREATE TABLE Citizen (ID int NOT NULL,
profession varchar(255), lastname varchar(255) NOT NULL,
firstname varchar(255), PRIMARY KEY (profession));

Solution: Only an attribute, or a set of attributes that can uniquely identify a row,
can be chosen as the PRIMARY KEY. Here (ID, lastname), (firstname, lastname)
and (ID, profession) can do so. Hence, options 2, 3, 4 are correct.

Page 11
10. Using the table Citizen given in Figure 6, answer the question that follows.

Figure 6: Table Citizen

Let the table Citizen be created using the SQL statement given below: [MSQ: 2
points]

• CREATE TABLE Citizen (ID int, profession varchar(255),


lastname varchar(255) NOT NULL, firstname varchar(255));

Identify the correct INSERT INTO statement for this table.



INSERT INTO Citizen (ID, profession, lastname, firstname)
VALUES (23,‘clerk’, ‘Holmes’, ‘Mark’);
INSERT INTO Citizen TABLE VALUES (23,‘clerk’, ‘Holmes’, ‘Mark’);

INSERT INTO Citizen VALUES (23,‘clerk’, ‘Holmes’, ‘Mark’);
INSERT INTO Citizen VALUES (‘23’,‘clerk’, ‘Holmes’, ‘Mark’);

Solution: To insert values in a table, the generic format is -


INSERT INTO table name (column1, column2, ...) VALUES (value1, value2, ...);
OR
INSERT INTO table name VALUES (value1, value2, ...);
Also, varchar type attributes need to be in ‘ ’ and INT type attributes without ‘ ’.

Page 12
11. Using the table Citizen given in Figure 7, answer the question that follows.

Figure 7: Table Citizen

Let the table Citizen be created with firstname as the primary key, and the values be
inserted as per the schema in the table. [MCQ: 1 points]

Choose the SQL statement to remove the primary key constraint Citizen pkey of the
table Citizen.
ALTER TABLE Citizen
DROP Citizen CONSTRAINT Citizen_pkey;
MODIFY TABLE Citizen
DROP CONSTRAINT Citizen_pkey;
MODIFY TABLE Citizen
DROP Citizen CONSTRAINT;

ALTER TABLE Citizen
DROP CONSTRAINT Citizen_pkey;

Solution: The syntax to remove an existing primary key constraint is -


ALTER TABLE table name DROP CONSTRAINT primary key constraint name;
Hence option 4 is correct.
ALTER TABLE Citizen DROP CONSTRAINT Citizen pkey;

Page 13
12. Let {sup num} be the primary key of table suppliers and {part num, sup num} be the
primary key of table parts. [NAT: 2 points]
Consider the SQL query given below:

SELECT s.sup_num, sum(p.part_qty)


FROM suppliers s, parts p WHERE s.sup_num = p.sup_num
GROUP BY s.sup_num
HAVING SUM(p.part_qty) > 70

How many rows will be returned by the above SQL query?


Answer: 2

Solution: As per the given SQL statement, it first performs a Cartesian product
between suppliers and parts, which output all possible combinations from both the
tables.
The part of the statement:
s.sup num = p.sup num
eliminates the rows which do not satisfy the condition. The output is as shown
below:

The part of the statement:


SELECT s.sup num, sum(p.part qty) ...GROUP BY s.sup num
results in:

Finally, the part of the statement: HAVING SUM(p.part qty) > 70


results in:

Page 14
Thus, the result has 2 rows.

Page 15
BSCCS2001: Practice Assignment with Solutions
Week 3
1. Consider the relational schema given in Figure 1.

Figure 1: Hall Booking Relational Schema

Find the names of departments that have booked all the halls at least once in the month
of January. [ MCQ: 2 points]
SELECT deptName FROM deptsMaster
WHERE deptID IN
(SELECT DISTINCT deptID FROM hallBooking AS hb1
WHERE NOT EXISTS
(SELECT hm.hallID FROM hallsMaster AS hm
INTERSECT
SELECT hb2.hallID FROM hallBooking AS hb2
WHERE hb1.deptID = hb2.deptID
AND monthBooking = ’Jan’));

SELECT deptName FROM deptsMaster
WHERE deptID IN
(SELECT DISTINCT deptID FROM hallBooking AS hb1
WHERE NOT EXISTS
(SELECT hm.hallID FROM hallsMaster AS hm
EXCEPT
SELECT hb2.hallID FROM hallBooking AS hb2
WHERE hb1.deptID = hb2.deptID
AND monthBooking = ’Jan’));
SELECT deptName FROM deptsMaster
WHERE deptID IN
(SELECT DISTINCT deptID FROM hallBooking AS hb1
WHERE EXISTS
(SELECT hm.hallID FROM hallsMaster AS hm
EXCEPT
SELECT hb2.hallID FROM hallBooking AS hb2
WHERE hb1.deptID = hb2.deptID
AND monthBooking = ’Jan’));
SELECT deptName FROM deptsMaster
WHERE deptID IN
(SELECT DISTINCT deptID FROM hallBooking AS hb1
WHERE EXISTS
(SELECT hm.hallID FROM hallsMaster AS hm
INTERSECT
SELECT hb2.hallID FROM hallBooking AS hb2
WHERE hb1.deptID = hb2.deptID
AND monthBooking = ’Jan’));

Solution:

SELECT hm.hallID FROM hallsMaster AS hm


EXCEPT
SELECT hb2.hallID FROM hallBooking AS hb2
WHERE hb1.deptID = hb2.deptID
AND monthBooking = ’Jan’

The above query fetches all hallIDs that have not been booked in January.

SELECT DISTINCT deptID FROM hallBooking AS hb1


WHERE NOT EXISTS (hallIDs that have not been booked in January)

The above query will retrieve all department IDs that have not booked any halls
that have not been booked in January.

SELECT deptName FROM deptsMaster


WHERE deptID IN (all department IDs that have not booked any halls
that have not been booked in January)

The above query fetches the names of departments that have not booked any halls
that have not been booked in January.
Note that if we execute the nested queries directly on the sql prompt, they will give
errors due to the aliases used.

Page 2
2. Consider the relational schema given in Figure 2.

Figure 2: Country Capitals Relational Schema

What should be filled in the blank so that the following query will return the capitals
of all countries that belong to Asia but not Europe? (Write the answer as a single word
in all CAPS) [ NAT: 2 points]

SELECT capitalName FROM capital


WHERE countryID IN (SELECT countryID FROM country
WHERE continent =‘Asia’
-----------------
SELECT countryID FROM country
WHERE continent =‘Europe’);

Answer: EXCEPT

Solution: The first part of the inner query returns all countries that belong to Asia.
If we need to find countries that belong to Asia but not Europe, then from the
rows returned by the first part of the inner query, we have to remove those that
contain countries that belong to Europe as well. Hence, to remove those rows, we
use EXCEPT.

Page 3
3. Based on the relations given in Figure 3 answer the question that follows.

Figure 3: Employee instance

What should be filled in blank (a) in the table employee in Figure 3, if the query given
below returns the value: Akshay? [ NAT: 2 points]

SELECT empName FROM employee


WHERE desgID LIKE ‘%2’ AND deptID LIKE ‘%2’;

Answer: G0002

Solution: Since the value returned is Akshay, it corresponds to second row of table
employee. desgID in employee table is a foreign key that references department
table, hence the desgID can only be any one value from {G0001, G0002, G0003}.
The WHERE condition specifies desgID LIKE ‘%2’. It follows from all three reasons
that the only possible value that can be filled in blank (a) is G0002.

Page 4
4. Consider the following SQL statement: [ MSQ: 2 points]

CREATE TABLE boats(


boatID VARCHAR (8),
boatName VARCHAR (20),
boatColour VARCHAR (8),
yearOfPurchase INTEGER,
weight INTEGER,
PRIMARY KEY (boatID),
CHECK (boatColour IN (‘Black’, ‘White’, ‘Red’, ‘Yellow’)));

Which among the following will cause an integrity constraint violation in the boats
table?
INSERT INTO boats(‘B1’, ‘Liberty’, ‘Red’, 2003, 500);

INSERT INTO boats(‘B1’, ‘Liberty’, ‘Blue’, 2003, 500);

UPDATE boats SET boatColour = ‘Green’ WHERE boatID = ‘B1’;
DELETE FROM boats;

Solution: In option 1, there is no constraint violation.


In option 2, since the permitted colors do not include blue, it will cause a violation.
In option 3, the permitted colors do not include green and hence it will cause a
violation.
In option 4, there is no constraint violation.

Page 5
5. Consider the relational schema given in Figure 4.

Figure 4: Employee Schema

If the relations employee, designation and department have 100, 6, 5 rows respec-
tively, what is the difference between the maximum and the minimum number of rows
returned by the following query? [ NAT: 2 points]

SELECT * FROM employee LEFT OUTER JOIN designation


ON employee.desgID = designation.desgID;

Answer: 0

Solution: Left outer join (also known as Left join) returns all tuples returned by
natural join along with those tuples in the left table (here, employee ) that does not
have matching entry in the right table. In the given question, however, desgID is
the foreign key in Table employee that references Table designation. Therefore,
there will not be any tuple in the left table that does not have a matching entry in
the right table. Thus, the maximum number of rows returned by the left join in the
given example is 100.
The case when employee table has no rows is the case when left outer join will have
the minimum number of rows. In this case, however, the employee table has 100
rows. So, there will be at least 100 rows returned by the left join.
The answer is 100 − 100 = 0.

Page 6
6. Choose the appropriate query/queries to find the names of batsmen who scored the
second-highest runs. [ MSQ: 2 points]

SELECT name, MAX(runs) AS runs
FROM batsman WHERE runs < (SELECT MAX(runs) FROM batsman);

SELECT name, MAX(runs) AS runs
FROM batsman WHERE runs IN
(SELECT runs FROM batsman MINUS (SELECT MAX(runs) FROM batsman));

SELECT name, runs AS runs
FROM batsman WHERE runs = (SELECT runs FROM batsman
ORDER BY runs LIMIT 1,1);
SELECT name, MAX(runs) AS runs FROM batsman
WHERE runs > (SELECT MIN(runs) FROM batsman);

Solution:

• MAX, MIN functions are used to find out the record with maximum and min-
imum values respectively among a record set.

• The SQL MINUS operator is used to return all rows in the first SELECT
statement that are not returned by the second SELECT statement.

• The LIMIT statement is used to limit the number of records returned based
on a limit value.

• The ORDER BY keyword is used to sort the result-set in ascending or de-


scending order.

Option 1 - The inner query will fetch the maximum runs and then the outer query
will return the runs value which is maximum among all and lesser than the value
retrieved by the inner query. Hence, the second-highest value of runs is fetched.
Option 2 - The inner query will fetch all the runs values other than the maximum
runs and from this set, the IN operator will retrieve the maximum value. Hence, the
second-highest value of runs is fetched.
Option 3 - The inner query will fetch the second-highest value of runs using the Limit
operator, then using the ‘=’ the outer query will retrieve it.
Option 4 - The inner query will return the minimum runs and the outer query will
fetch the maximum runs greater than the runs value of the inner query. Hence it is
incorrect.

Page 7
Consider the table Employee, table Department and table Dependent, and answer
the questions 7 and 8.

7. Select the suitable query to retrieve the names of employees who have no dependents. [
MCQ: 2 points]

SELECT name FROM Employee


WHERE NOT EXISTS (SELECT * FROM Dependent AS D WHERE D.ssn = essn);
SELECT name FROM Dependent
WHERE NOT EXISTS (SELECT * FROM Employee WHERE ssn = essn);

SELECT name
FROM Employee
WHERE NOT EXISTS (SELECT * FROM Dependent WHERE ssn = essn);
SELECT name FROM Employee
WHERE IN (SELECT * FROM Employee WHERE ssn = essn);

Solution: The EXISTS/NOT EXISTS condition in SQL is used to check whether


the result of a correlated nested query is empty (contains no tuples) or not.
As per the question, to retrieve the names of employees who have no dependents, the
outer query needs to fetch data from the table Employee and the inner query needs

Page 8
to fetch data from the table Dependent. Hence, options 2 and 4 are incorrect.

In option 1- After aliasing Dependent as D, the condition must be ssn = D.essn.


Hence, option 1 is incorrect.

In option 3 - Inner query will fetch all the dependents where attribute ssn of Employee
is matched with essn from Dependent. Hence, only if there is no matched value, NOT
EXISTS will be true and the names of the employees who have no dependents will
be retrieved.

8. Select the suitable query to retrieve the names of employees who have some dependent(s)
whose name ends with ‘KUMAR’. [ MCQ: 2 points]
SELECT name FROM Dependent
WHERE ssn IN (SELECT essn FROM Employee
WHERE dep_name LIKE ‘%KUMAR’);
SELECT name FROM Employee
WHERE essn IN (SELECT ssn FROM Dependent
WHERE dep_name LIKE ‘%KUMAR%’);

SELECT name FROM Employee
WHERE ssn IN (SELECT essn FROM Dependent
WHERE dep_name LIKE ‘%KUMAR’);
SELECT name FROM Employee
WHERE ssn IN (SELECT essn FROM Dependent
WHERE dep_name LIKE ‘KUMAR’);

Solution: The LIKE operator is used in a WHERE clause to search for a specified
pattern in a column. The percent sign (%) represents zero, one, or multiple charac-
ters and the underscore sign ( ) represents one, single character.

So to retrieve all the names ending with KUMAR, it has to match ‘%KUMAR’.
Hence, options 2 and 4 are incorrect.

In option 1, the inner query needs to fetch from table Dependent and outer query
from table Employee. Hence, incorrect.

In option 3, the inner query will fetch the Dependent(s) whose name ends with
KUMAR and using IN keyword, the outer query will retrieve the names of the
corresponding employees. Hence, correct.

Page 9
9. Consider the table employee and table department as shown in Figure 5, and answer
the question that follows. [ MCQ: 2 points]

Figure 5: employee & department

What will be the output of the following query?

SELECT emp_id, dept_name


FROM employee NATURAL JOIN department
ORDER BY age desc;

Output:

Output:

Page 10
Output:

Output:

Solution: As per the query, after NATURAL JOIN on employee table and depart-
ment table, the resultant table will be -

Page 11
And as and when we put ORDER BY age in descending order, we will fetch the
following resultant table -

10. Consider a table Employee(eid, edept, ename, esalary, ebonus). The table has no
records initially.

[MCQ:2 points]

CREATE OR REPLACE FUNCTION bonus_fun() RETURNS TRIGGER AS $$


BEGIN
IF NEW.edept = ’R/D’ THEN
NEW.ebonus = NEW.esalary * .75;
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER bonus_trig


BEFORE INSERT ON Employee
EXECUTE PROCEDURE bonus_fun();

INSERT INTO Employee VALUES (4,’R/D’,’Diksha’,30000);

Page 12
INSERT INTO Employee VALUES (2,’Accounts’,’Raj’,40000);
SELECT ebonus FROM Employee;

If the given code is executed, then what will be the output?


22500
0
22500
NULL
22500
30000

The code has errors.

Solution: The code is erroneous because the trigger definition does not explicitly
mention its granularity (for each row or for each statement). This trigger checks
each insertion and modifies the value of an attribute (ebonus) when the described
condition satisfies, therefore it should work as a row level trigger.

Page 13
11. Consider an instance of the table Employee given below.

[MCQ:2 points]

Figure 6: Table: Employee

If the given code is executed on this instance, then what will be the output/error?

[MCQ:2 points]

CREATE OR REPLACE FUNCTION salary_fun() RETURNS TRIGGER AS $$


DECLARE
counter INT := 0;
BEGIN
IF NEW.esalary > 75000 THEN
counter = counter + 1;
RAISE NOTICE ’Number of affected rows : %’, counter;
--//This statement prints => NOTICE: <whatever follows>
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER salary_trig


AFTER UPDATE ON Employee
FOR EACH ROW
EXECUTE PROCEDURE salary_fun();

UPDATE Employee SET esalary = esalary * 1.5;

Page 14
NOTICE: Number of affected rows : 4
NOTICE: Number of affected rows : 10
NOTICE: Number of affected rows : 4
NOTICE: Number of affected rows : 4
NOTICE: Number of affected rows : 4
NOTICE: Number of affected rows : 4

None of the above

Solution: The trigger will be executed on every row affected by the UPDATE state-
ment. Only 4 rows in the given instance will have their new salary more than 75000.
The RAISE NOTICE statement is inside the IF clause, thus it will be executed 4 times.
Observe the fact that the trigger fires for each updated row, and hence every time
the variable counter is reinitialized with 0. It will be incremented to 1 with respect
to that specific row, and thus we will get the output as:
NOTICE: Number of affected rows : 1
NOTICE: Number of affected rows : 1
NOTICE: Number of affected rows : 1
NOTICE: Number of affected rows : 1

12. If we want to store/print the number of affected rows when an update or delete statement
is executed, then which type of trigger should we use to count?

[MCQ:2 points]

Statement level trigger
Row level trigger
Both are equally efficient
Table level trigger

Solution: If we want to count the number of affected rows then we need not execute
a trigger every time for each row. After all the modifications are over, a single
execution of a trigger to count the affected rows should be done. Running a row
level trigger will simply do the same job again and again for all the affected rows.
Hence, Statement level triggers should be used here.

Page 15
BSCCS2001: Practice Assignment with Solutions
Week 4

1. Consider the following relations : [ MCQ: 2 points]


A = (P, Q, R)
B = (X, Y, Z)
Let relations a(A) and b(B) be given. Which of the following expressions in the tuple
relational calculus is equivalent to ΠP,Z (σR=X (a × b)) ?


{t | ∃p ∈ a, ∃q ∈ b(t[P ] = p[P ] ∧ t[Z] = q[Z] ∧ p[R] = q[X])}
{t | ∃p ∈ a, ∃q ∈ b(t[P ] = p[P ] ∧ t[Z] = q[Z] ∨ p[R] = q[X])}
{t | ∃p ∈ a, ∃q ∈ b(t[P ] = p[P ] ∧ t[Z] = q[Z] ∧ p[X] = q[R])}
{t | ∃p ∈ a, ∃q ∈ b(t[Z] = p[Z] ∧ t[P ] = q[P ] ∧ p[R] = q[X])}

Solution:
ΠP,Z (σR=X (a × b)) will return attributes P from relation a(A) and Z from relation
b(B). So, options C and D are incorrect.
For SELECT operation, condition R = X must be satisfied, So option B is incorrect.
Thus, option 1 is correct.

Consider the following relational schema and answer questions 2 and 3.


[MCQ:2 points]

• Owner(aadhar number, o name)


• V ehicle(v number, v model)
• Registration(aadhar number, v number, purchase year)

2. Which of the following relational algebra expressions is equivalent to the statement given
below?

• Find the Aadhaar numbers of owners who purchased the vehicle model V 20 after
year 2020.
Q
σaadhar number ( v model=“V 20” ∨ purchase year>”2020” (Registration ./ V ehicle))
σaadhar number (σv model=“V 20” ∧ purchase year>”2020” (Registration ./ V ehicle))
√ Q
aadhar number (σv model=“V 20” ∧ purchase year>”2020” (Registration ./ V ehicle))
Q
aadhar number (σv model=“V 20” ∨ purchase year>”2020” (Registration ./ V ehicle))
Solution: Selection Operator (σ), selects those rows or tuples from the relation that
satisfies the selection condition.
Project operator is denoted by the symbol Π, and it is used to select desired columns
(or attributes) from a table (or relation).
Option 1 and Option 2 are incorrect. Here, the SELECT operator is used, requiring
a specific condition to select tuples from a relation.
Option 3: It will return the Aadhaar number of all the owners who purchased the
vehicle model V 20 and after year 2020.
So, Option 3 is correct.
Option 4: It will return the Aadhaar number of all the owners who purchased the
vehicle model V 20 or after year 2020.

3. Which of the following queries is equivalent to the statement given below?

• Find the names of all owners who purchased vehicles with number 123 before the
year 2019.
{T | ∃O ∈ Owner, ∃R ∈ Registration(O.aadhar number = R.aadhar number∧
R.v number = 123 ∨ R.purchase year < 2019 ∧ T.o name = O.o name)}
{T | ∃O ∈ Owner, ∃R ∈ Registration(O.aadhar number = R.aadhar number∧
R.v number = 123 ∨ R.purchase year < 2019 ∨ T.o name = O.o name)}
{T | ∃O ∈ Owner, ∃R ∈ Registration(O.aadhar number = R.aadhar number∨
R.v number = 123 ∧ R.purchase year < 2019 ∨ T.o name = O.o name)}

{T | ∃O ∈ Owner, ∃R ∈ Registration(O.aadhar number = R.aadhar number∧
R.v number = 123 ∧ R.purchase year < 2019 ∧ T.o name = O.o name)}

Solution:
∃O ∈ Owner, ∃R ∈ Registration(O.aadhar number = R.aadhar number) will per-
form the NATURAL JOIN operation of Owner and Registration schema and
(R.v number = 123 ∧ R.purchase year < 2019 ∧ T.o name = O.o name) is the re-
quired condition for the names of all the owners who purchased the vehicle number
123 before year 2019.

Page 2
4. Consider the E-R diagram for a cricket-training-camp database as given in Figure 1.
[ MCQ: 2 points]

Figure 1: E-R diagram of cricket-training-camp database

Identify the option in which both the statements correctly describe the relations between
the given entity sets.
1. Each member can be either a coach or a player or both in the cricket-
training-camp.
2. Each player can be a batsman or a bowler or both.
1. Each member can be a coach or a player or both.
2. Each player can be either a batsman or a bowler. However, a player cannot
be both, a batsman and a bowler at the same time.
1. Each member can be either a coach or a player. But, a member cannot
be a coach and a player at the same time.
2. Each player can be either a batsman or a bowler, but cannot be both.

1. Each member can be either a coach or a player or just a member of the
cricket-training-camp. But, a member cannot be a coach and a player at
the same time.
2. Each player can be a batsman or a bowler or both.

Solution:

• Coach and Player are disjoint specializations of Member.

Page 3
• Batsman and Bowler are overlapping specializations of Member.

• Both kind of specializations given in Figure 1 are partial specializations.

Hence,

• Each member must be a coach or a player or just a member. But, a member


cannot be a coach and a player at the same time.

• Each player can be a batsman or a bowler or both.

Page 4
5. Consider the E-R diagram given in Figure 2.
[ MCQ: 2 points:Solve with instructor]

Figure 2: E-R diagram

The table for entity set ProjectMember is created using the command below:

CREATE TABLE ProjectMember(


member_id INT NOT NULL,
member_name VARCHAR(20) NOT NULL,
skill_level VARCHAR(20) NOT NULL,
PRIMARY KEY (member_id)
);

Select the appropriate command to create the table for relationship set managed by.
CREATE TABLE managed_by(
member_id INT NOT NULL,
since INT NOT NULL,
PRIMARY KEY (member_id),
FOREIGN KEY (member_id) REFERENCES ProjectMember(member_id)
);

CREATE TABLE managed_by(
member_id INT,
manager_id INT,
since INT NOT NULL,
PRIMARY KEY (member_id, manager_id),
FOREIGN KEY (member_id) REFERENCES ProjectMember(member_id),
FOREIGN KEY (manager_id) REFERENCES ProjectMember(member_id)
);
CREATE TABLE managed_by(
manager_id INT NOT NULL,
since INT NOT NULL,
PRIMARY KEY (manager_id),

Page 5
FOREIGN KEY (manager_id) REFERENCES ProjectMember(member_id)
);
CREATE TABLE managed_by(
member_id INT NOT NULL,
manager_id INT NOT NULL,
since INT NOT NULL,
PRIMARY KEY (member_id, manager_id),
FOREIGN KEY (manager_id) REFERENCES ProjectMember(member_id)
);

Solution: The table managed by must have {member id, manager id} as primary
key, both reference to ProjectMember(member id), and the descriptive attribute
since also becomes an attribute in the table.
Thus, it must be created by the command:

CREATE TABLE managed_by(


member_id INT,
manager_id INT,
since INT NOT NULL,
PRIMARY KEY (member_id, manager_id),
FOREIGN KEY (member_id) REFERENCES ProjectMember(member_id),
FOREIGN KEY (manager_id) REFERENCES ProjectMember(member_id)
);

Please note that since {member id, manager id} is the primary key, the prime at-
tributes member id and manager id by default not NULL.

Page 6
6. Consider the entity set given in Figure 3. [ MCQ: 2 points]

Figure 3: Entity set Gamer

Which of the following relational schemas appropriately represents the E-R diagram?
Gamer(gamer id, gamer name, f name, mname, lname, email id, join time)
Gamer(gamer id, f name, mname, lname, email id, join time, play time)
Gamer email(gamer id, email id)

Gamer(gamer id, f name, mname, lname, join time)
Gamer email(gamer id, email id)
Gamer(gamer id, email id, join time)
Gamer name(gamer id, gamer name, f name, mname, lname)

Solution:

• The identifying attribute gamer id becomes primary key for the schema.

• The composite attribute gamer name will be replaced by its parts f name,
mname and lname in the schema.

• The simple attribute join time becomes another attribute.

• The derived attribute play time does not need to be added in the schema.

• For the multivalued attribute email id a separate relation has to be created


which will be:
Gamer email(gamer id, email id).

Page 7
7. Consider the relations given below: [ MSQ: 2 points:Solvewithinstructor]
• doctor(doc id, doc name, specialization)
• patient(patient num, patient name)
• operationRoster(doc id, patient num, operation cost)
Identify the appropriate statement(s) to find the names of all doctors having specializa-
tion in orthopedics and who have charged more than $1000 as surgery charges.
√ Q
doc name (σspecialization=“orthopedic” ∧ operation cost>1000 (doctor ./ operationRoster))
{s | ∃s ∈ doctor, ∃r ∈ operationRoster(s.doc id = r.doc id ∧ s.specialization =
“orthopedic” ∧ r.operation cost > 1000)}

{t | ∃s ∈ doctor, ∃r ∈ operationRoster(s.doc id = r.doc id ∧ s.specialization =
“orthopedic” ∧ r.operation cost > 1000 ∧ t.doc name = s.doc name)}

{< DN > | ∃DI ∃RP ∃RC (< DI , DN , “orthopedic” >∈ doctor∧
< DI , RP , RC >∈ operationRoster) ∧ RC > 1000}

Solution: As per the specifications given in the question, a natural join needs to be
applied between doctor and operationRoster as:
doctor ./ operationRoster.
Then, a select operation can be applied as:
σspecialization=“orthopedic” ∧ operation cost>1000 (doctor ./ operationRoster).
Finally, apply project the doc name as:
Q
doc name (σspecialization=”orthopedic” ∧ operation cost>1000 (doctor ./ operationRoster)).
The equivalent tuple relational calculus is:
{t | ∃s ∈ doctor, ∃r ∈ operationRoster(s.specialization = “orthopedic”
∧ r.operation cost > 1000 ∧ t.doc name = s.doc name)}.
The equivalent domain relational calculus is:
{< DN > | ∃DI ∃RP ∃RC (< DI , DN , “orthopedic” >∈ doctor∧
< DI , RP , RC >∈ operationRoster) ∧ RC > 1000}.
Please note the tuple relation calculus:
{s | ∃s ∈ doctor∃ r ∈ operationRoster(s.doc id = r.doc id ∧ s.specialization =
“orthopedic” ∧ r.operation cost > 1000)}
projects all attributes rather than doc name alone.

8. Consider the relations below: [ MSQ: 2 points]


• customer(customer id, customer name, customer city)
• invoice(invoice number, customer id, amount payable)
Choose the correct relational algebra expressions that return the names of all customers
having amount payable (amount payable) more than $1,000 and who are located in
Chennai.

Page 8
Q
customer name (σamount payable>1000 ∧ customer city=“Chennai” (customer × invoice))
Q
amount payable>1000 ∨ customer city=“Chennai” (customer ./ invoice))
√ Q
customer name (σamount payable>1000 ∧ customer city=“Chennai” (customer ./ invoice))
√ Q
customer name
(σamount payable>1000 ∧ customer city=“Chennai” ∧ customer.customer id=invoice.customer id
(customer × invoice))

Solution: First, natural join can be applied between the two relations customer
and invoice such that tuples will be combined by equality in customer id. Then,
σ with predicate amount payable > 1000 ∧ customer city = “Chennai” can be
applied to find the tuples as per the specification given.
Alternatively, the same can also be achieved by a Cartesian product between cus-
tomer and invoice along with σ with predicate equality of customer id of both
the relations and σ with predicate amount payable > 1000 ∧ customer city =
“Chennai”. Q
Finally, we project ( ) the customer name.

Page 9
9. Consider the table given in Figure 4. [ MSQ: 2 points]

Figure 4: Relation S1

Choose the correct set of expressions that will return the tuple given below.

σA (ΠB=49 (S1))

{t | ∃p ∈ S1(t[A] = p[A] ∧ p[B] = 49)}
{t | ∃p ∈ S1(t[A] = p[A] ∧ p[B] = 7)}

{< a >| ∃b(< a, b >∈ S1 ∧ b = 49)}

Solution:
σA (ΠB=49 (S1)) is logically incorrect, the correct TRC query is ΠA (σB=49 (S1)), this
will first perform the Select operation and return the row having B = 49 then it will
project the corresponding value of attribute A.

{t | ∃p ∈ S1(t[A] = p[A] ∧ p[B] = 49)} is equivalent to ΠA (σB=49 (S1))

{< a >| ∃b(< a, b >∈ S1 ∧ b = 49)} is equivalent to ΠA (σB=49 (S1))

Page 10
10. Consider the E-R diagram in Figure 5. [ NAT: 2 points]

Figure 5: ERD

What is the minimum number of tables needed to represent this E-R diagram?

Solution: 1
The minimum and maximum cardinality is 1 (1..1).

• A minimum value of 1 indicates total participation.

• A maximum value of 1 indicates that the entity participates in at most one


relationship.

Thus, it can be represented using a single table:


team captain(team code, team name, player num, player name).

Page 11
Consider the E-R diagram given in Figure 6 and answer the questions 11 and 12.

Figure 6: E-R diagram

11. The minimum number of tables required to represent the entity sets and relationship
sets is ....... [ NAT: 2 points]
Answer: 3

Solution: 3

• E1 is associated with E2 via R1 in a one-to-many relation.

• E3 is associated with E2 via R2 in a one-to-many relation.

Many-to-one and one-to-many relationship sets that are total on the many-side can
be represented by adding an extra attribute to the “many” side, containing the
primary key of the “one” side. Thus, we can represent the entire ERD using 3 tables
as follows:

• E1(a1, a2)

• E2(c1, c2, a1, b1)

• E3(b1, b2)

12. What will be the correct attribute set for the table corresponding to the entity set E2?
[ MCQ: 2 points:Solvewithinstructor]

E2(c1, c2)
E2(c1, a1, c2)
E2(c1, a1, b1, c2)

E2(c1, c2, a1, b1)

Page 12
Solution:

• R1 is a one-to-many relationship set from E2 to E1.

• R2 is a one-to-many relationship set from E2 to E3.

Many-to-one and one-to-many relationship sets that are total on the many-side can
be represented by adding an extra attribute to the “many” side, containing the
primary key of the “one” side. Thus, we can represent the entire ERD using 3 tables
as follows:

• E1(a1, a2)

• E2(c1, c2, a1, b1)

• E3(b1, b2)

13. Consider the E-R diagram with aggregation given in Figure 7. [ MCQ: 2 points]

Figure 7: ERD

What will be the correct attribute set for the table corresponding to relationship-set A1?

c1, e1, d1
a1, b1, d1, c1, e1, e2
a1, b1, d1, e1, e2

a1, b1, e1, d1

Page 13
Solution: The ER-diagram presents a scenario of aggregation. Thus, the relation-
ship set A1 must be mapped to a table having the following:

• Primary keys of E1, E2 and E3.

• Any descriptive attributes of A1.

So the attribute set for A1 is: {a1, b1, e1, d1}

Page 14
BSCCS2001: Practice Solutions
Week 5
1. Consider the following [MCQ: 2 points]
X = {A → BC, B → A, C → A}
Y = {A → B, B → C, C → A}
X covers Y
Y covers X
X and Y are equivalent

All the above

Solution: Let us check X covers Y , every functional dependency in Y logically


implies in X.
FDs in Y : A → B, B → C, C → A
check for A → B,
A+ → ABC {A → BC in X}
Check for B → C
B + → BAC, {A → BC, B → A in X}
Check for C → A
C + → CAB {C → A, A → BC in X}
Therefore, X covers Y
Let us now check, If Y covers X
FDs in X: A → BC, B → A, C → A
Check for A → BC
A+ → ABC {A → B, B → C in Y }
Check for B → A
B + → BCA {B → C, C → A in Y }
Check for C → A
C + → A {C → A in X}
Therefore, Y covers X
Since, both X & Y covers each other, so they are equivalent X ≡ Y

Page 2
2. Consider relation R(A,B,C,D,E,F) with the following functional dependencies:

F = {AB → C, AC → E, EF → D, AB → F }

[MSQ: 2 points]
Which among the following is true about R?
R1(D, E, F), R2(A, B, C, E, F) is a lossy decomposition of R.

R1(A, B, D), R2(C, E, F) is a lossy decomposition of R.
R1(A, D, E, C), R2(B, E, C) is a lossless decomposition of R.

R1(D, E, A, B), R2(C, F, B) is a lossy decomposition of R.

Solution:

This problem will be solved in the Solve With the Instructor session.

Page 3
3. Consider relation T20WC defined as W(Team, Ranking, Captain, Points, Players)
with the following functional dependencies:

F = {T eam, Ranking → Captain, Ranking → P layers, Captain → P oints}

Then, which of the following is true ? [MCQ:2points]


W1(Team, Ranking, Captain), W2(Captain, Points) is a lossless-join decom-
position.

W1(Team, Ranking, Captain), W2(Points, Players) is a lossy-join decomposi-
tion
W1(Team, Ranking, Captain), W2(Ranking, Points, Players) is a lossless-join
decomposition.
None of the above

Solution:
Option 1 : W1(Team, Ranking, Captain), W2(Captain, Points)
W 1 ∪ W 2 6= W
Thus, it is lossy join decomposition.
Option 2 : W1(Team, Ranking, Captain), W2(Points, Players)
W1 ∪ W2 = W
W1 ∩ W2 = φ
Thus, it is lossy join decomposition. So, option 2 is correct
Option 3 : W1(Team, Ranking, Captain), W2(Ranking, Points, Players)
W1 ∪ W2 = W
W 1 ∩ W 2 = Ranking
Ranking + → Ranking, P layers
Ranking is not superkey for any relation. Hence, we can’t determine W 1 and W 2
from it. So, it is lossy decomposition.

Page 4
Numerical Answer Type
4. Consider the relation Book(Author, Publisher, Pages, Ratings, Type) having the fol-
lowing functional dependencies : [NAT: 2 points]
F= { Author → P ublisher, P ages
P ublisher → Ratings
P ages, Ratings → T ype
T ype → Author }
What is the maximum number of candidate keys for Book?
Ans : 4

Solution: By estimating the closure of all combination of attributes, it can be ob-


served that the closure of the following attributes produces all other attributes:
Author, T ype, (P ublisher, P ages), (P ages, Ratings).
Hence, these 4 are the candidate keys.

Page 5
5. In a relation R(A, B, C, D, E), each attribute is a candidate key. Then, what is the
maximum number of super keys possible for R?
[NAT: 2 points]
Ans: 31

Solution: Consider a relation R(A1 , A2 , A3 .....An ), then maximum number of super


keys are 2n -1. (If Each attribute of a relation is candidate key)
Here, n = 5, so, the number of super keys for a given relation R is 31.

Page 6
6. Which among the following is/are the use(s) of finding closure of attributes? [MSQ: 2
points]

Find if an attribute or set of attributes is a superkey.


Compute the canonical cover of a given set of functional dependencies
Test if a specific functional dependency holds
Compute the closure of a given set of functional dependencies

All the above

Solution: The solution follows from the lectures.

Page 7
7. Let R(A, B, C, D, E) be a relation with the following functional dependencies:

F = {A → C, A → B, C → D, BC → E}

[MCQ: 2 points]
Then,
F + = {A → C, A → B, C → D, BC → E}
F + = {A → C, A → B, C → D, A → D, BC → E}
F + = {A → BC, C → D, BC → E}

F + = {C → D, BC → E, A → BCDE}

Solution: This problem will be solved in the Solve With the Instructor session.

Page 8
8. Let R(A, B, C, D, E) be a relation with the following functional dependencies:
[MCQ: 2 points]
F = {A → B, C → D, BD → E}
Then, which of the following functional dependencies can be derived from F using Arm-
strong’s Axioms?

AC → E
BE → D
B→A
C→E

Solution:
A→B
AC → BC {Augmentation}
C→D
BC → BD {Augmentation}
BD → E
AC → E {Transitivity}

Page 9
9. Choose the correct canonical cover of the set of functional dependencies F that occur in
a relation R(A, B, C, D), where

F = {A → BC, AB → C, A → D, D → C}

[MCQ: 2 points]

A → BC, AB → C
A → BC, AB → C, A → D

A → B, A → D, D → C
A → B, B → C, A → D

Solution: Given A → BC, AB → C, A → D, D → C.


A → D, D → C ⇒ A → C
That is, in the FD A → BC, A → C is redundant.
Hence we can remove A → C from A → BC.

F = {A → B, AB → C, A → D, D → C}

Since A → C is a stronger constraint than AB → C and since A → C can be derived


from A → D, D → C, we can remove AB → C from F.
Therefore
F = {A → B, A → D, D → C}

Page 10
10. Choose the set of FDs equivalent to:

A → BC, B → CE, C → ED

[MSQ: 2 points]


A → BE, B → CD, C → ED
A → B, B → D, C → E

A → B, B → C, C → ED
A → B, B → C, C → D, D → A

Solution:

This problem will be solved in the Solve With the Instructor session.

Page 11
11. Given the relation hospital and its decomposition into hosp1 and hosp2 as shown in
Figure 1, choose the correct set of options. [MCQ: 2 points]

Figure 1: Decomposition of hospital relation

The given decompostion is lossless and the natural join of hosp1 and hosp2
has 5 rows.
The given decompostion is lossless and the natural join of hosp1 and hosp2
has 3 rows.

The given decompostion is lossy and the natural join of hosp1 and hosp2 has
5 rows.
The given decompostion is lossy and the natural join of hosp1 and hosp2 has
3 rows.
Solution:

Figure 2: Natural join of hosp1 and hosp2

Page 12
12. Consider a relation R(A, B, C, D, E) having the following functional dependencies:

F = {A → BCD, D → E, C → D}

Which among the following are lossy decompositions? [MSQ: 2 points]

R1 (A, B, C), R2 (B, C, D), R3 (C, D, E)


R1 (A, B, C), R2 (A, C, D), R3 (A, D, E)

R1 (A, B, C), R2 (A, C), R3 (A, D)
R1 (A, B, C, D), R2 (A, C, D, E)

Solution:

This problem will be solved in the Solve With the Instructor session.

Page 13
BSCCS2001: Practice with Solutions
Week 6
1. Consider the relational schema R(A, B, C, D, E), where the domains of A, B, C, D and
E include only atomic values. Identify the possible set of functional dependencies that
R can have such that R is in BCNF.
[MSQ: 2 points]

FD: {AB → CDE}
FD: {AB → CD, B → E}
FD: {AB → CD, C → D, D → E}
FD: {AB → CDE, D → A, E → B}

Solution: Given that in R each attribute is a single-valued attribute. Thus R is


already in 1NF.
Option-1: FD: {AB → CDE}
The only candidate key (thus primary key) is: AB as (AB)+ = {ABCDE}.
As all the non-prime attributes are fully functionally dependent on the candidate
key, it is already in 2NF.
{AB → CDE}, where AB is a superkey. Thus, it is in 3NF and also in BCNF.
Option-2: {AB → CD, B → E}
The only candidate key (thus primary key) is: AB as (AB)+ = {ABCDE}.
B → E is a partial functional dependency. Thus, it is in 1NF but not in 2NF.
Option-3: FD: {AB → CD, C → D, D → E}
The only candidate key (thus primary key) is: AB as (AB)+ = {ABCDE}.
There is no partial functional dependency. Thus, it is already in 2NF.
AB → CD, where AB is superkey.
But, for C → D, D → E

• the functional dependencies are not trivial.

• L.H.S of the functional dependencies are not superkeys.

• R.H.S of the functional dependencies are not prime attributes.

Thus, these two FDs violate 3NF rules. So, R is in 2NF but not in 3NF based on
this set of FDs.
Option-4: FD: {AB → CDE, D → A, E → B}
The candidate keys are: AB and DE as (AB)+ = {ABCDE} and (DE)+ =
{ABCDE}. The prime attributes are A, B, D, E.
There is no partial functional dependency. Thus, it is already in 2NF.
AB → CDE, where AB is superkey.
For D → A, E → B R.H.S of the functional dependencies are prime attributes.
Thus, it is in 3NF. However, These two FDs do not satisfy BCNF (as L.H.S are not
superkeys). So, R is in 3NF but not in BCNF based on this set of FDs.

Page 2
2. Consider the relational schema R(A, B, C, D, E, F ), where the domains for A, B, C, D, E
and F include atomic values only. If R satisfies the functional dependencies {AB →
CDE, E → F, BF → A, C → B}, then identify the correct statement(s).
[ MSQ: 2 points]
R is in 1NF but not in 2NF

R is in 2NF and also in 3NF

R is in 3NF but not in BCNF
R is in 3NF also in BCNF

Solution:
Candidate keys are: AB, BF, AC, BE, CF and CE. So, prime attributes are: A, B, C, E
and F . For the FDs: E → F and C → B, B and F are prime attributes. Thus,
there is no partial dependency, thus R is in 2NF.
AB → CDE and BF → A, as AB and BF both are candidate keys, the FDs are in
3NF.
C → B and E → F also in 3NF, since B and F are prime attributes. Thus, R is in
3NF.
C → B and E → F violate BCNF conditions as C and E are not superkeys. Thus,
R is not in BCNF.

Page 3
3. Consider the relational schema Z(P, Q, R, S ) and the following functional dependencies
on Z. [ MCQ: 2 points]

• P → QRS
• Q→R
• RS → P

Which of the following is/are correct?


Z is in 3NF and also in BCNF

Z is in 3NF but not in BCNF
Z is in 2NF but not in 3NF
Z is in BCNF but not in 3NF

Solution: FD = {P → QRS, Q → R, RS → P }
P + = PQRS
RS + = PQRS
QS + = PQRS
So, candidate keys are P, QS & RS and prime attribute are P, Q, R & S.
Since the schema Z has no partial dependencies or transitive dependencies, so it is
in 3NF.

Check for BCNF


P → QRS (P is candidate key) X
Q → R (Q is not candidate key) ×
RS → P (RS is candidate key) X

So, Z is in 3NF but not in BCNF.

Page 4
4. Let R(P,Q,R,S,T,U,V,W ) be a relation (all attributes have atomic values only) with
the following functional dependencies:

• {P Q → RST U }
• {P → R}
• {Q → S}
• {R → U V }
• {V → W }
• {W → U }
• {V → U }

Find the highest normal form in which the relation R is in.


[ MCQ: 2 points]

1NF
2NF
3NF
BCNF

Solution: Since all attributes in R have atomic values, it follows that R is in 1NF.

In order to check if R is in 2NF, we must find the candidate keys. Using the given
FDs, we find that PQV is the only candidate key. Hence P, Q and V are the prime
attributes and the rest are non-prime.
Now due to the presence of partial dependency, the relation R is not in 2NF.

Note: Partial dependency occurs when a non-prime attribute is functionally depen-


dent on a subset of a candidate key.

Page 5
5. Consider the instance of relation Course given in Figure 1. [ MSQ: 2 points]

Figure 1: An instance of relation Course

Which among the following multivalued dependencies can be inferred from the given
information?

course name →→ instructor
course name →→ book
course name →→ edition

course name →→ book, edition

Solution:
Let us first number the tuples as t1 , t2 , · · · , t10 .
Test for course name →→ instructor:
In relation Course, there exist two tuples t1 and t2 such that
t1 [course name] = t2 [course name].
We also have two tuples t3 and t4 in Course with the following properties:

• t1 [course name] = t2 [course name] = t3 [course name] = t4 [course name],

• t3 [instructor] = t1 [instructor] and t2 [instructor] = t4 [instructor],

• t1 [book, edition] = t2 [book, edition] and t3 [book, edition] = t4 [book, edition].

Thus it satisfies MVD conditions.


In the relation Course, there are three tuples t5 , t6 and t7 such that
t5 [course name] = t6 [course name] = t7 [course name].
We also have three tuples t8 , t9 and t10 in Course with the following properties:

• t5 [course name] = t6 [course name] = t7 [course name] = t8 [course name] =


t9 [course name] = t10 [course name],

Page 6
• t5 [instructor] = t6 [instructor] = t7 [instructor] and
t8 [instructor] = t9 [instructor] = t10 [instructor],

• t5 [book, edition] = t8 [instructor, edition],


t6 [book, edition] = t9 [instructor, edition]
and t7 [book, edition] = t10 [book, edition].

Thus, MVD conditions are satisfied.


Test for course name →→ book, edition:
MVD Complementation rule: In a relation R, if X →→ Y , then X →→ R − XY .
Since we already have course name →→ instructor, it follows that course name →→
book, edition also correct.
If we follow the same procedures as discussed above, we will be able to show that
the MVDs:
course name →→ book
course name →→ edition
are not satisfied on relation Course.

Page 7
6. Consider the relational schema:
Intern(intern code, intern name, project, hobby).
An intern can work in several projects and can have several hobbies. However, it main-
tains the FD: intern code → intern name.
Identify the most appropriate 4NF decomposition for the given schema.
[ MCQ: 2 points]
R1(intern code, intern name, project, hobby), R2(intern code, project, hobby)
R1(intern code, intern name, project), R2(intern code, hobby)
R1(intern code, intern name, hobby), R2(intern code, project)

R1(intern code, intern name), R2(intern code, project), R3(intern code, hobby)

Solution:
From the given information in the question, intern code cannot be a super key for
the given relation. Thus, intern code → intern name violates BCNF conditions.
Thus, a possible BCNF decomposition would be:
R1(intern code, intern name), where intern code is the candidate key, and
R2(intern code, project, hobby).
R2 violates 4NF conditions as it has the following MVDs:
intern code →→ project, and
intern code →→ hobby
So the 4NF decomposition is:
R2(intern code, project), and
R3(intern code, hobby).
Thus, the 4NF decomposition is:
R1(intern code, intern name),
R2(intern code, project),
R3(intern code, hobby).

Page 8
7. Let S(Y, U, V ) be a relation. Let R(P, W, X, Y, Z ) be another relation with the
following functional dependencies:
F = {X → ZW, Y → X, W → P }
R contains 300 tuples and S contains 250 tuples. What is the maximum number of
tuples possible as output of R o
n S?
[ MCQ: 2 point]
75000

250
300
50

Solution: From the given set of functional dependencies, Y is a candidate key of


relation R. So all 300 values of Y must be unique in R.
There is no functional dependency given for S and to get the maximum number of
tuples in output, there can be two possibilities for S.

• All 250 values of Y in S are same and there is an entry in R that matches with
this value. In this case, we get 250 tuples in output.

• All 100 values of Y in S are different and these values are present in R also.
In this case also, we get 250 tuples.

Page 9
8. Let A(T,U,V,W ) be a relational schema with the following functional dependencies:
F = {W → U T, U V → W, V → T, W → U }
It is given that A is not in BCNF.
Suppose A is decomposed into two relational schemas, B(TV ) and C(UVW ).
Which of the following statement(s) is/are correct?
[ MSQ: 2 points]
Decomposition of schema A into B and C is dependency preserving

Decomposition of schema A into B and C is lossless
Both B and C are in BCNF

Relation B is in BCNF

Solution:

• B(TV ) preserves {V → T } and has V as the candidate key. So, relation B is


in BCNF.

• C(UVW ) preserves {UV → W, W → U } and has UV and VW as the candi-


date keys. So, relation C is in 3NF but not in BCNF, as W is not a superkey.

• The decomposition of schema A into two relational schemas, B and C, does


not cover all the functional dependencies of the original relation A. Hence, it
is not dependency preserving.

• The decomposition has common attribute (i.e., V ) which is superkey of relation


B(TV ), so decomposition of A into B and C is lossless join decomposition.

Page 10
9. Consider the relational schema:
prescription(doctor id, doctor name, patient id, patient name, medicine id, medicine name),
where the domains of all the attributes consist of atomic values. Consider the following
FDs for the relation department.
[ MCQ: 2 points]

• doctor id → doctor name,


• patient id → patient name,
• medicine id → medicine name,
• doctor id →→ patient id,
• doctor id →→ medicine id

From among the decompositions given, identify the one that is in 4NF.
(doctor id, doctor name),
(patient id, patient name),
(medicine id, medicine name),
(doctor id, doctor name),
(patient id, patient name),
(medicine id, medicine name),
(doctor id, patient id, medicine id)
(doctor id, doctor name, patient id, patient name),
(doctor id, doctor name, medicine id, medicine name)

(doctor id, doctor name),
(patient id, patient name),
(medicine id, medicine name),
(doctor id, patient id),
(doctor id, medicine id)

Solution: For the given relation, the candidate key is {doctor id, patient id, medicine id}
and it is in 1NF. However, it is not in 2NF as the FDs:
doctor id → doctor name,
patient id → patient name,
medicine id → medicine name, are partial functional dependencies. Thus, a possi-
ble decomposition is:
R1(doctor id, doctor name), where doctor id is the candidate key,
R2(patient id, patient name), where patient id is the candidate key,
R3(medicine id, medicine name), where medicine id is the candidate key,
R4(doctor id, patient id, medicine id), where {doctor id, patient id, medicine id} is
the candidate key,
R1, R2, R3 and R4 are already in 3NF and BCNF.

Page 11
R1, R2 and R3 are already in 4NF. The MVDs,
doctor id →→ patient id, and
doctor id →→ medicine id violate 4NF conditions. Thus, R4 is decomposed as:
R41(doctor id, patient id) and
R42(doctor id, medicine id).
Thus, the 4NF decomposition is:
R1(doctor id, doctor name),
R2(patient id, patient name),
R3(medicine id, medicine name)
R41(doctor id, patient id) and
R42(doctor id, medicine id).

Page 12
10. Consider the relational schema R as:
R(A, B, C, D, E, F, G, H), where the domains of all the attributes consist of atomic
values. Consider the following FDs for the relation department.

• A → D,
• D → EF ,
• BH → CG,
• G → H,

From among the decompositions given, identify the one that is in BCNF.
[ MCQ: 2 points]

(A, D, E, F ), (G, H), (B, C, G, H) and (A, B, H)


(D, E, F ), (A, D), (G, H) and (B, C, G)

(D, E, F ), (A, D), (G, H), (B, C, G) and (A, B, H)
(D, E, F ), (A, D), (B, C, G, H) and (A, B, H)

Solution: Due to atomic values, the relation R is in 1NF.


Candidate key is: ABH as (ABH)+ = R.
Test for 2NF: FD: A → D and BH → CG violate 2NF conditions (these are
partial functional dependencies). Thus, the decomposition of R is:
Since (A)+ = ADEF , R1(A, D, E, F ), where A is the candidate key,
since (BH)+ = BHCG, R2(B, H, C, G), where BH is the candidate key, and
R3(A, B, H) consists of the original candidate key of R.
Now, R1, R2 and R3 are in 2NF.
Test for 3NF: In R1, FD D → EF violates 3NF conditions (as D is not a su-
perkey). Thus, the decomposition is:
R11(D, E, F ), where D is the candidate key and R12(A, D), where A is the candi-
date key.
The relations R3 and R2 are already in 3NF (since in R2, FD: G → H satisfies
3NF conditions as H is a prime attribute).
Test for BCNF: The relations R11, R12 and R3 are already in BCNF. However,
in relation R2, FD: G → H violates BCNF conditions as G is not a super key).
Thus, the decomposition is:
R22(G, H), where G is the candidate key and R22(B, C, G), where BCG is the
candidate key.
The final relations after decomposition are:
R11(D, E, F ), R12(A, D), R21(G, H), R22(B, C, G) and R3(A, B, H). Please
note that although the decomposition is lossless, it is not dependency preserving.

Page 13
11. Which of the following statements is/are true regarding temporal relations?
[ MSQ: 2 points]

A uni-temporal relation can have only valid time.


A uni-temporal relation can have only transaction time.

A uni-temporal relation can have either valid transaction time or transaction
time.

A bi-temporal relation can have both valid transaction time and transaction
time.

Solution:

• An uni-temporal relations has one axis of time, either valid time or transaction
time.

• A bi-temporal relation has both axis of time, valid time and transaction time.
It includes valid start time, valid end time, transaction start time, transaction
end time.

Page 14
BSCCS2001: Practice with Solutions
Week 7
1. Select the correct statement(s) from the following options: [MSQ: 2 points]

Common Gateway Interface (CGI) is a standard interface between web and
database server.
The main function of the server side scripting is to correspond within a web-
page.

URIs can be classified as locators(URLs), or as names (URNs), or both.
HTTP can be used to format most of the web documents into hypertext doc-
uments.

Solution:

• The Common Gateway Interface (CGI) provides the middleware between WWW
servers and external databases and information sources.

• The main function of the server side scripting is to carry out a task at the
server’s end and then send the result to the client side.

• URNs and URLs are the subsets of the URIs.

• HTML can format most of the web documents into hypertext documents.

Page 2
2. Identify the three main components of Application Architecture Layer. [MSQ: 2 points]
Controller Layer, Data Access Layer, Backend Layer
Presentation Layer, Controller Layer, Model Access Layer

Presentation Layer, Middle Layer, Backend

Presentation Layer, Business Logic Layer, Data Access Layer

Solution: Application layer consists of 3 sub-layers namely:

• Frontend or Presentation Layer

• Middle Layer or Application / Business Logic Layer

• Backend or Data Access Layer

Presentation layer follows model-view-controller (MVC) architecture.

Page 3
3. Identify A, B and C marked in Figure 1. [MCQ: 2 points]

Figure 1: Web/Application Server

A - View, B - Controller, C - Business Logic Layer,


A - View, B - Controller, C - Presentation Layer
A - Controller, B - View, C - Business Logic Layer

A - Controller, B - View, C - Presentation Layer

Solution: Presentation Layer is constituted by MVC architecture where M is model,


V is view, C is controller.

• The Controller component acts as an interface between Model and View com-
ponents to process all the business logic and incoming requests, manipulate
data using the Model component and interact with the Views to render the
final output.

• The Model component corresponds to all the data-related logic that the user
works with.

• The View component is used for all the UI logic of the application.

Page 4
4. Which among the following is a Python library for parsing HTML? [MCQ: 2 points]
Requests

Beautiful Soup
Paramiko
Twisted Python

Solution: Beautiful Soup is an HTML parser that can handle all sorts of HTML.
Requests is a powerful HTTP client library.
Paramiko is used for implementing the SSH2 protocol.
Twisted Python is a framework for asynchronous network programming.

Page 5
5. Which of the following is/are the disadvantage(s) of using single factor authentication
with password? [MSQ: 2 points]

The password can be disclosed by guessing or sniffing of packets, if passwords
are not encrypted.
Using single factor authentication can be a time-consuming process, as it in-
volves multiple steps like password plus one-time password sent by SMS.

Passwords can be exposed if passwords are reused by a user across sites.

Passwords can be captured by the specially designed spyware.

Solution: Please refer to slide: 35.13

Page 6
6. Match the appropriate statements for

a. 1-tier architecture
b. 2-tier architecture
c. 3-tier architecture
d. n-tier architecture

Statement-1 : It distributes different components of the 3-tiers between different servers


and add interface tiers to enable interactions and load balancing.
Statement-2 : It keeps all the components of an application on a single server or platform.
Statement-3 : It separates its tiers as Presentation, Logical and Data Access.
Statement-4: It is based on client-server architecture, where all the interactions between
client and server take place directly, without presence of any intermediate.
[MSQ: 2 points]
a)-statement-1, b)-statement-3, c)-statement-2, and d)-statement-4.
a)-statement-4, b)-statement-2, c)-statement-3, and d)-statement-1.
a)-statement-4, b)-statement-3, c)-statement-2, and d)-statement-1.

a)-statement-2, b)-statement-4, c)-statement-3, and d)-statement-1.

Solution: Please refer to slide: 31.17 - 31.20.

Page 7
7. Which of the following tasks is/are performed by a web server?
[MSQ: 2 points]
It has the core software component, named as rendering engine, that trans-
forms HTML documents and other resources of a web page into an interactive
visual representation on a user’s device.

It receives HTTP/HTTPS requests, and responds to the requests with the
content of that requested resource or an error message.

If the requested document is an executable program, it executes the program,
and sends back the HTML document that is generated.
It is used to access World Wide Web, and it can fetch content from the Web
and display it on a user’s device.

Solution:

• A web server is software and underlying hardware that accepts requests via
HTTP or its secure variant, HTTPS.

• A web browser or crawler, requests for a specific resource using HTTP, and the
server responds with the content of that resource or an error message.

• When a web server receives a request for a document which is an executable


program, it executes the program, and sends back the HTML document that
is generated.

Page 8
8. Which of the following tasks is/are widely performed by a client-side script?
[MSQ: 2 points]

It can check input validity of Web pages to avoid many round trips to server.
It can make any system call, and can also access the file system of the host
machine to perform read, write operations.

It can provide rich user interface.
It always executes at server-end and sends the result back to the client-end.

Solution: Client-side scripts are widely used to:

• forms basis of new generation of Web applications (called Web 2.0 applications)
offering rich user interfaces

• check input for validity

However, in general, client-side scripts are

• firstly downloaded at the client-end and then interpreted and executed by the
browser.

• not allowed to make any system calls directly, and disallowed with dangerous
actions such as file writes.

Page 9
9. Which of the following is not true about ODBC?
[MSQ: 2 points]
ODBC is designed with an objective to support various Windows versions.
Thus, it is not supported by the non-Windows operating systems.

ODBC is a standard API for database connectivity, used by the application
programs to communicate with database servers.
ODBC is a Java-based technology developed by Sun Microsystems.

An application written using ODBC can be easily ported to heterogeneous
client and server platforms.

Solution: Please refer to Slide: 33.8

Page 10
10. Consider the following tasks in a Java program to execute an SQL query at database
server using JDBC.

1. Create a ”Statement” object


2. Use the ”Statement” object to execute the SQL statement
3. Create a ”Connection” object
4. Fetch the query results in a ”ResultSet” object

Identify the correct order in which the tasks must be performed. [MCQ: 2 points]
1→2→3→4
2→1→3→

3→2→1→4
3→1→2→4

Solution: The appropriate order must be:

1. Create a ”Connection” object

2. Create a ”Statement” object

3. Use the ”Statement” object to execute the SQL statement

4. Fetch the query results in a ”ResultSet” object

Page 11
11. Among the given options, which is/are a challenge in Web Application development?
[MSQ: 2 points]
The number of rows that have been affected (modified, inserted, or deleted)
by the last execute() procedure.

Knowledge of framework and platforms
Limited computing power

Web security threats
Limited memory

Solution: The challenges for Web application development are:

• User interface and user experience

• Scalability

• Performance

• Knowledge of framework and platforms

• Security

Limited computing power and limited memory are the challenges for Mobile appli-
cation development.

Page 12
BSCCS2001: Practice Solutions
Week 8
1. Which of the following does not belong to disk interface standards families?
[MCQ:2points]
Serial ATA
Small Computer System Interconnect

Storage Area Networks
Serial Attached SCSI

Solution: Disk interface standards families

• ATA (AT Attachment) range of standards

• SATA (Serial ATA)

• SCSI (Small Computer System Interconnect) range of standards

• SAS (Serial Attached SCSI)

• Several variants of each standard (different speeds and capabilities)

Please refer to slide No. 39.16

Page 2
Answer questions 2 and 3 on the basis of the following data.

Consider you have a file named “ IITM BSc ” in your hard disk. The file size is 1000
KB.
Seek time of your hard disk read head is 3ms, rotational speed is 30,000 RPM. The disk
has 200 sectors/track and sector size is 512 bytes.

2. What is the transfer rate of your hard-disk (in KB/ms)?


[MCQ:2 points]

50 KB/ms
100 KB/ms
33.33 KB/ms
95 KB/ms

Solution:
Transfer rate is the rate at which data is read from the disk. It can be calculated as
follows.
The given rotational speed of the disk = 30,000 RPM.
i.e. disk rotates 30,000 times in 60 sec.
So, time required for making 1 rotation = 60/30, 000 = 2 ms

Total number of bytes present on one track= number of sectors/track * sector size
Total number of bytes present on one track= 200 ∗ 512 = 102400 bytes

Transfer Rate = Bytes on one track / time for making one rotation
Transfer Rate = 102400/2 = 51200 bytes/ms

Converting into KB/ms = 51200/1024 = 50 KB/ms.


Hence, option 1 is correct.

3. Considering the fact that the file data is stored in all non-consecutive sectors, how much
time will be required to read the whole file after the read request is made?
Note: Consider, Access time + Transfer time
[MCQ:2 points]

10.02 seconds

8.02 seconds
0.024 second

Page 3
0.026 second

Solution:
Rotational latency= (1/2) * time for making one rotation.
Therefore, Rotational latency= (1/2) ∗ 2 = 1 ms

Transfer time = File size / transfer rate


= 1000 ∗ 1024/51200 = 20 ms

Since the file data is stored in random sectors (i.e., non-consecutive),


hence each sector would require a new seek.
So each sector would have both seek latency and rotational latency.
Seek time + Rotational latency = 3 + 1 = 4 ms.
Number of sectors in which the file is stored,= 1000 ∗ 1024/512 = 2000 sectors.
Time required for placing the head on sectors = 4 ∗ 2000 = 8000 ms

Time required = Time required for placing the head on sectors (Access time) + trans-
fer time
Therefore, time elapsed = 8000 + 20 = 8020 ms or 8.02 seconds.
Hence, option 2 is correct.

Page 4
4. Consider the following statements, [MCQ:2 points]

1. DNA data storage is the process of encoding and decoding binary data to and from
synthesized strands of DNA.
2. A DNA synthesizer machine builds synthetic DNA strands matching the sequence
of digital code
3. Both DNA Digital Storage and Quantum Memory can store enormous data which
is not possible in file based storage system.
4. Quantum Memory stores the information in binary states.

Choose the correct option below


Statements 2,3 & 4 are correct
Statements 1,3 & 4 are correct

Statements 1,2 & 3 are correct
All the statements are correct

Solution: Please refer to slide no 39.31 and 39.32

5. Choose the correct Binary Search Tree (BST) for the following sequence:
15,10,20,6,12,17,23,2,8,11,14,27 [MCQ:2 points]

Page 5

Solution:
Option 1: It represents the BST for sequence
15,10,20,8,12,27,23,2,6,11,14,17

Option 2: It represents the BST for sequence


15,10,6,20,27,2,23,17,8,14,11,12

Option 3: It represents the BST for sequence


15,23,6,20,12,2,10,17,8,14,11,27

option 4: Is a correct answer.

6. Which of the following is an example of a volatile storage medium?


[MCQ:2 points]

Flash memory

Main memory
Hard disk
Magnetic tape

Solution:
All the options except main memory are examples of non-volatile storage. Main
memory or RAM is a volatile storage medium. Hence, option 2 is correct.

Page 6
7. Heap file organization is used for storing records of a relation R. The cardinality of
R is 8192. A given selection operation (SELECT query) is such that it fetches only
one specific record from R. What is the maximum number of search steps/compare
operations required to run this SELECT statement?

[MCQ:2 points]

1

8192
13
8193

Solution:
In heap file organization records can be stored in any available free space and no
ordering is done in this file organization. Hence a selection operation has to go
through all the possible records to find the required record. In worst case the required
record can be the last one and so 8192 search steps/comparisons will be required.
Hence option 2 is correct.

8. Which of the following statements is/are correct about physical storage media?
[MSQ: 2points]
Cache are the non-volatile and most costly form of storage.

Flash memory are widely used in embedded devices such as digital cameras,
phones, and USB keys.

In magnetic-disk, data must be moved from the disk to main memory for
access, and written back for storage.
Reads and writes are faster in optical disk storage than magnetic disk.

Solution: Please refer to lecture no 8.4

Page 7
9. Which of the following statements is/ are correct about a Buffer Manager?
[MSQ: 2 points]

If the block is already in the buffer, the buffer manager returns the address of
the block in the main memory.
If the block is in the buffer, the buffer manager allocates space in the buffer
for the block.
In Buffer manager, the subsystem responsible for allocating buffer space in
secondary memory.

If the block is not in the buffer, the buffer manager reads the block from the
disk to the buffer, and returns the address of the block in main memory to the
requester.

Solution:

• If the block is already in the buffer, the buffer manager returns the address of
the block in the main memory.

• If the block is not in the buffer, the buffer manager

– Allocates space in the buffer for the block.


– Reads the block from the disk to the buffer, and returns the address of
the block in the main memory to the requester.

• In Buffer manager, the subsystem responsible for allocating buffer space in


main memory.

Page 8
10. Which of the following statements is/ are correct? [ MSQ:2points]

Disk controller is the interface between the computer system and the disk drive
hardware.
NOR flash storage is much cheaper than NAND flash storage.

USB flash drives are removable and rewritable storage devices.
All of the above

Solution:

• Disk controller is the interface between the computer system and the disk drive
hardware.

• NAND flash storage is much cheaper than NOR flash storage.

• USB flash drives are removable and rewritable storage devices.

Please refer to Lecture no 8.4

11. Which of the following statements is/are correct? [MSQ:2 points]


A Secure Digital (SD) card is a type of removable memory card which is used
to read large quantities of data only.

SSDs do not include any moving parts unlike HDD.
The speed of SSD is lesser than that of HDD as it reads/writes data at lower
input/output per second.

Cloud storage supports file sharing dynamically as it can be shared anywhere
with network access.

Solution:

• A Secure Digital (SD) card is a type of removable memory card used to read
and write large quantities of data.

• SSDs do not include any moving parts unlike HDD.

• The speed of SSD is much larger than that of HDD as it reads/writes data
at higher input-output per second.

• Cloud storage supports file sharing dynamically as it can be shared anywhere


with network access.

Page 9
Answer questions 12 and 13 based on the given data.

Consider a disk with 10 platters, 64 tracks/surface, 256 sectors/track, 512 bytes/sector.


4 bytes/sector is reserved for storing file system information (formatting data).

12. How much free space is available for use (in MB, upto two decimal places)?

[NAT:2 points]

Answer: 158.75

Solution:
Total number of surfaces = 2 ∗ 10 = 20
Total number of sectors = 20 ∗ 64 ∗ 256 = 327680 sectors.
Total space reserved for file system data= 4 * no. of sectors = 1310720 bytes.
Converting to MB = 1310720/220 = 1.25 MB
Total disk space = 20 ∗ 64 ∗ 256 ∗ 512 = 167772160 bytes.
Converting to MB = 167772160/220 = 160 MB
Disk space left for the user = 160 − 1.25 = 158.75 MB.
Answer is 158.75.

In a 32 GB pen drive, the file’s system information, called format overhead, is stored
and hence not all of the 32 GB is available for use.

13. How many bits are required for addressing all the sectors ? [NAT:2 points]

Answer: 19

Solution:
No. of sectors = 327680
No. of bits required to address all of them = dlog2 327680e = 19 bits.
Answer is 19.

14. Consider a string of pending block references in the given order: 3, 4, 1, 4, 2, 3, 1, 4, 2, 3.


The system has a buffer with 3 slots. Assume that initially the buffer is empty. If LRU
buffer replacement policy is used, then how many misses will occur while referencing all
the requested blocks ? [NAT:2 points]

Answer: 9

Page 10
Solution:
Will be explained in practice live session.
This is an example of block reference order, where LRU worsens the working and
increases the misses. As mentioned in the slides.

15. Choose the correct arrangement of the given growth functions in increasing order.

[MCQ:2points]

log log N < N log N < N 2 < 2N < N N
log log N < N log N < N 2 < N N < 2N
N log N < log log N < N 2 < N N < 2N
N log N < log log N < 2N < N 2 < N N

Solution: Refer slide 36.18, 36.19 for the concept and similar example.

Page 11
16. What will be the worst-case asymptotic running time of the following code?
Hint: O(n!) = O(nn ) follows from ‘Stirling’s approximation’.

[MSQ:2points]

int sum = 0;
for(int i = 1 ; i <= n ; i++){
for(int j = 1 ; j <= i ; j=j*2){
sum = sum + i + j;
}
}

O(n log n)

O(log(n!))
O(n! log n)
O(nn )

Solution: The outer loop runs n times and for each iteration of the outer loop the
inner loop runs log(i) times. Therefore, the total number of iterations are
Σ log(i) and i ∈ {1,2,3...n}.
= log(1) + log(2) + ... + log(n)
= log(1.2.3....n)
= log(n!) ≈ log(nn )........using Stirling’s approximation
= n log n

Page 12
BSCCS2001: Practice Solutions
Week 9

1. Consider a B-tree of order 17.


[ MCQ: 2 points]
What are the minimum number of child pointers and keys that can be placed in a
non-root node?

min. number of child-node pointers = 9,
min. number of keys = 8.
min. number of child-node pointers = 2,
min. number of keys = 1.
min. number of child-node pointers = 9,
min. number of keys = 9.
min. number of child-node pointers = 17,
min. number of keys = 16.

p  17 
Solution: A non-root node
 p−1of
 a B-tree
 17−1 of order p = 17 has minimum 2
= 2
=9
child-node pointers and 2 = 2 = 8 keys.
2. Consider a non-empty B + -tree of order 17.
[ MCQ: 2 points]
What are the maximum and minimum number of keys that can be placed in the root
node?
max. number of keys = 16,
min. number of keys = 8.
max. number of keys = 17,
min. number of keys = 8.

max. number of keys = 16,
min. number of keys = 1.
max. number of keys = 16,
min. number of keys = 2.

Solution: A non-empty B + -tree must have a minimum of one key and a maximum
of p − 1 keys, where p is the order of the B + -tree. Thus, in this case the maximum
number of keys = 16, and the minimum number of keys = 1.

Page 2
3. Suppose a data file has 1,00,000 records. Each disk block contains 10 such records
(records are unspanned and of fixed-length) and the total space required to store the file
is 100 MB (megabytes). We consider a primary (sparse index with an index entry for
every block in file) index is constructed on the data file. The key field is 30 bytes and
pointer field is 10 bytes for each entry of the index. How many blocks are required to
store the index?
[ NAT: 2 points]
Answer: 382

Solution: Since the data-file has 1,00,000 records and each disk block contains 10
such records, the total number of blocks required to store the entire data-file is
100000
10
= 10000.
The 10,000 blocks are stored in 100 MB (megabytes). Thus, each disk block size is

100 × 220
= 10485.76 bytes.
10000

But we must consider the nearest smaller whole number as the usable block size
because the records are unspanned.
Therefore, block size = 10485 bytes.
A dense index on the primary key requires one entry for each record in the given
relation (thus, 1,00,000 entries) and the size of each entry is:
size-of-key-field + size-of-pointer-field = 30 + 10 = 40 bytes.
So, the space required to store the index is 40 × 100000 = 4000000 bytes.
Thus, the number of blocks required to store the index is
l 4000000 m
= 382
10485
.

Page 3
Consider a multilevel index with four levels as L1 , L2 , L3 and L4 . Let L1 be the innermost
and L4 be the outermost levels. Let the index blocking factor or the maximum number
of entries held by a block be 50. With the given information, answer the questions 4 and
5.
4. If the number of blocks in level L1 is 1,00,000, then how many blocks are required at
L2 , L3 and L4 ?
[ MCQ: 2 points]


Number of blocks at L2 is 2000,
Number of blocks at L3 is 40,
Number of blocks at L4 is 1
Number of blocks at L2 is 2000,
Number of blocks at L3 is 50,
Number of blocks at L4 is 1
Number of blocks at L2 is 2000,
Number of blocks at L3 is 200,
Number of blocks at L4 is 4
Number of blocks at L2 is 20000,
Number of blocks at L3 is 2000,
Number of blocks at L4 is 10

Solution: Number of blocks in L2 is d 100000


50
e = 2000.
2000
Number of blocks in L3 is d 50 e = 40.
Number of blocks in L4 is d 40
50
e = 1.

5. Given the multilevel access structure, the number of block accesses required to read a
record is .........
[ MCQ: 2 points]


5
4
3
17

Solution: For each level, there is a block access and access to the block having the
target record. Thus, the number of block accesses required is 5.

Page 4
6. Consider a B-tree based index with order p = 19. Assume each node of the B-tree is
73% full. If the height of the tree is 3, then what is the maximum number of keys that
can be accommodated in the given B-tree?
[ MCQ: 2 points]

38,415
8,663
12,765
68,605

Solution: On an average, each node will have 0.73 × 19 or approximately 14 tree


pointers. Thus, on an average, each node will have 13 keys.

Level Nos. of nodes Nos. of Keys Nos. of pointers


Level-0 (root) 1 1 × 13 = 13 1 × 14 = 14
Level-1 14 14 × 13 = 182 14 × 14 = 196
Level-2 196 196 × 13 = 2, 548 196 × 14 = 2, 744
Level-3 2,744 2, 744 × 13 = 35, 672

Thus, the number of keys that can be accommodated is 13 + 182 + 2, 548 + 35, 672 =
38, 415.

Page 5
7. Consider a B-tree of order 3. If we have 9 elements to be inserted into the tree, then
what will be the maximum number of splits that take place in the nodes?
[ NAT: 2 points]
Answer: 5

Solution: Assume that the elements are 1 < 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9.
The elements are in ascending order such that the B-tree becomes skewed, and the
maximum number of splits take place. The steps for insertion are as shown in the
figure, and it may be observed that the number of splits is 5.

Page 6
8. Consider the instance of a 2-3-4 tree given in Figure 1 and answer the question that
follows.
[MCQ: 2 points]

Figure 1: Instance of 2-3-4 tree

If we perform the following operations (in the given order) in the instance given in Figure
1, then choose the correct statement(s) about the resultant 2-3-4 tree.

• Insert value 38
• Insert value 89
• Insert value 100
Insertion of value 38 will lead to a split.

Insertion of value 100 will lead to a split.

Insertion of value 89 will lead to a split.
Insertion of value 100 will not lead to a split.

Solution: When value 38 is inserted, we can add it to the leaf node beside 29 and
no split is required. When value 89 is inserted, the block containing values 61, 83,
87 will need to be split. When value 100 is inserted, the block containing values 97,
103, 153 will need to be split. Figure 2 shows the resultant 2-3-4 tree.

Figure 2: Resultant tree

Page 7
9. Consider the table Food(Fid, Fname, Foodtype, Rating). There can only be two types
of food - Dessert or Soup. The rating value is an integer in the range 1 to 5.
[ MCQ: 2points]
Let the bitmap indexes for columns Foodtype and Rating be as given below:
Foodtype: 1010 for Dessert, 0101 for Soup
Rating: 0101 for 1, 0010 for 2, 0110 for 3, 0000 for 4, 1000 for 5
In order to find the Fname of an item that is a dessert with a rating of 2, which of the
following operations will be performed?
Logical AND operation on 0101 and 0010

Logical AND operation on 1010 and 0010
Logical OR operation on 1010 and 0010
Logical XOR operation on 1010 and 0010

Solution: Dessert has a bitmap index of 1010 and Rating 2 has a bitmap index of
0010. Hence, in order to find Fname of an item that is a dessert and has a rating of
2, we must perform the Logical AND operation on 1010 and 0010.

Page 8
10. Consider a B + tree in which the maximum number of keys allowed in a node is 7. Which
among the following options are correct about the given tree?
[MSQ: 2 points]
The minimum number of keys in any non-root node is 2.

The B + tree has a maximum of 8 child pointers.
The B + tree has a maximum of 7 child pointers.

The minimum number of keys in any non-root node is 3.

Solution: Let the order of the given B + tree be p. Then, the maximum number of
keys will be (p–1). Hence the number of keys in the B + tree is 8. The minimum
number of keys in any non-root node will be d p−1
2
e = 3.

Page 9
11. From among the given options, choose the incorrect statement(s) about static and dy-
namic hashing.
[MSQ: 2 points]
Static hashing uses a fixed hash function to partition the set of all possible
search-key values into subsets, and then maps each subset to a bucket.

Static hashing is a method of hashing in which a variable number of buckets
are allocated to a file to store the records.
Dynamic hashing may use a second stage of mapping to determine the bucket
associated with some search-key value.
In dynamic hashing, memory is well utilized as it grows and shrinks with the
data. Hence, there will not be any unused memory.

Solution: Static hashing is a method of hashing in which a fixed number of buckets


are allocated to a file to store the records.
The other statements follow from definitions of static and dynamic hashing.

Page 10
Consider the given table USER and answer the questions 12 and 13.
USER(User ID,User name, User city, User country, User skill )
[MCQ: 2 points]

12. Choose the correct SQL statement from the options to create an index with the name
‘idx userid’, for the attribute User ID.

CREATE INDEX AS idx_userid ON USER (User_ID);


CREATE INDEX idx_userid AS USER (User_ID);
CREATE INDEX AS idx_userid ON User_ID;

CREATE INDEX idx_userid ON USER (User_ID);

Solution: The syntax to create index on a table is:

CREATE INDEX index_name ON table_name (indexed_attribute_name);

13. Choose the correct SQL statement from the options to remove the index with the name
‘idx userid’ on User ID.

REMOVE INDEX ON idx_userid;


DELETE INDEX ON User_ID;

DROP INDEX idx_userid;
DROP INDEX OF USER ON idx_userid;

Solution: The syntax to remove an existing index on a table is:

DROP INDEX index_name;

Page 11
14. Which of the following statements is/are correct about the B + tree data structure that
is used for creating an index of a relational database table?
[MSQ: 2 points]

B + Trees are considered balanced because the lengths of the paths from the
root to all leaf nodes are equal.
Non-leaf nodes have pointers to data records.
B + Trees are considered balanced because the number of records in any two
leaf nodes differ by at most 1.

Key values in each node are kept in sorted order.

Solution: The statements follow from the definition and structure of a B + tree.

Page 12
BSCCS2001: Practice with Solutions
Week 10
1. Which of the following properties of transactions will be satisfied for a serial schedule
always?
[MCQ 2points]
Atomicity of all the transactions in the schedule

Isolation of all the transactions in the schedule
Consistency of all the transactions in the schedule
Durability of all the transactions in the schedule

Solution: If a schedule is serial, then it implicitly follows the Isolation property of


all its constituting transactions.
Isolation property makes it essential that each of the transaction should be able to
operate in such a way that it does not get affected by the execution of another trans-
action in parallel. In a serial schedule, transactions are executed serially with no
interleaving. Hence, Isolation property is trivially satisfied.

In a serial schedule, it is not a guarantee that all transactions in it will be com-


pletely executed. Hence, Atomicity is not guaranteed.

A transaction may keep the database inconsistent in a serial schedule. Hence, it


is not a guarantee for Consistency

Serial schedules have nothing to do with Durability property.

Page 2
2. The number of correct statements among the two given statements are
[ NAT 2points]

1. All conflict serializable schedules are cascadeless recoverable


2. All strict schedules are conflict serializable

Ans: 0

Solution: Consider the schedule


S1: r1(A), w1(A), r2(A), T2.commit, w1(B), T1.commit
This schedule is conflict serializable but not recoverable. Hence, statement 1 is false

Consider the schedule


S2: r1(X), w2(X), w2(Y), T2.commit, r1(Y)
This schedule is strict but not conflict serializable.
So both statements are incorrect.

Page 3
3. What is the number of schedules which are view equivalent to the given schedule S?

[NAT 2points]

Figure 1: S

Ans: 11

Solution: Two schedules S1 and S2 are said to be view equivalent, if they satisfy
all the following conditions:

1. Initial read of all data items must be done by same transactions in both sched-
ules

2. Final write of all data items must be done by same transactions in both sched-
ules

3. If in schedule S1, the transaction T1 is reading a data item updated by T2 and


then, in schedule S2. T1 should read the value after the write operation of T2
on same data item

In the given schedule there are total 5 operations- 2 writes and 3 reads. This sched-
ule does not have any instance where the update done by one transaction is read by
another, and hence all possible arrangements of these 5 operations will follow the 3rd
and 1st conditions implicitly.
But to make the schedules follow 2nd condition, we must ensure that w3(Q) is kept
at its place.
Thus, except w3(Q) we have 4 operations in a grouping of (2, 1, 1) for (T 1, T 2, T 3).
Hence, the number of possible arrangements following the rules are

4!
= 2!1!1!
= 12

Since the given schedule is itself one arrangement, the number of other view equiva-
lent schedules are 11

Page 4
For the given schedule S, answer questions 4 and 5
S: r5(Z), w1(Y), r2(Y), w3(Y), r4(Y), w2(P), r5(P), w4(X), r1(Q), r5(X), w5(Y)

4. The schedule S is serializable to which of the following serial schedules?[MCQ 2points]



T3 → T4 → T1 → T2 → T5
T1 → T5 → T3 → T2 → T4
T5 → T4 → T3 → T2 → T1
T3 → T2 → T5 → T1 → T4

Solution: As the read-write relations should be maintained, hence


Transaction T2 must be after T1.
Transaction T4 must be after T3
Last write of attribute Y must be preserved. Therefore, T5 must be the last trans-
action in a serial schedule.
Thus, the answer is : T 3 → T 4 → T 1 → T 2 → T 5

5. Given,
m = Number of serial schedules to which S is equivalent
n = Number of serial schedules to which S is conflict equivalent.
What is the value of m−n?

[NAT 2points]

Ans: 1

Solution:
T 3 → T 4 → T 1 → T 2 → T 5 : is a serial schedule equivalent to S
T 1 → T 2 → T 3 → T 4 → T 5 : is a serial schedule conflict equivalent to S.

Page 5
6. Tom is working as a System Designer in a reputed firm. He has 3 transactions to be
analyzed as follows. [NAT 2points]
T1: w1(A), w1(C).
T2: r2(D), w2(E).
T3: w3(B).
His analysis involves checking each possible concurrent schedule that can be made using
the transactions.
How many schedules does Tom have to check?

Ans: 30

Solution: If a schedule has 3 transactions with a, b, c number of operations in each


respectively, then the number of concurrent schedules that can be formed using these
transactions = (a+b+c)!
a!.b!.c!

Keep in mind that there should not be any reader-writer relation among the op-
erations. Otherwise, all possible arrangements will not hold.
Putting a= 2, b=2, c=1 we get the answer = 30

Page 6
7. Schedule S is as given: w2(P), w1(P), w3(P), w2(Q), w1(Q)
Consider the statements:

• All Conflict serializable schedules are 2-P lockable


• The given schedule S is Conflict serializable
• The given schedule is 2-P lockable

The number of correct statements is

[MCQ 2points]

0

1
2
3

Solution: Let’s try to apply 2 phase locking on the schedule:

We see that the red colored X(Q) is not allowed according to the rule of 2 phase
locking protocol, since unlocking phase of T1 has started already because U(P) was
done previously by T1. So this schedule is not 2 phase lockable.

The precedence graph of the given schedule is :

Page 7
We observe that there exists no cycle in this graph and hence the schedule is Conflict
serializable.

Hence, only the second statement is true.


The number of correct statements is 1.

Page 8
8. Schedule S is as given: w2(A), r1(A), r3(A), w1(A), w3(A), r2(B), w1(C)
If the timestamps for transactions T1, T2, T3 are 20, 5, 10 respectively, then choose all
the correct options.

[MSQ 2points]

Timestamp ordering protocol does not allow the transaction.
Timestamp ordering with Thomas Write rule allows the transaction.

Neither Timestamp ordering nor Thomas Write rule allows the transaction
None of the above

Solution: When T3 tries to perform w3(A), it checks what is the read and write
timestamp of A.
T1 has both read and written A previously in the schedule. Therefore, both read
and write timestamp of operand A will be set to 20, as a result of which w3(A) will
not be performed since T 3.timestamp(10) < A.writetimestamp(20).
So T3 is rolled back by Timestamp ordering protocol.

Even Thomas write rule will not allow T3 to get executed because Thomas write
rule ignores a late write only if the write timestamp of the operand is greater. In the
given schedule, both read and write timestamps of operand A are greater than the
timestamp value of T3.
So neither of the two protocols allow this schedule.
So correct choices are option 1 and 3.

Page 9
9. Schedule S is as given: w2(A), r3(A), w1(A), w3(A), r2(B), w1(C)
If the timestamps for transactions T1, T2, T3 are 20, 5, 10 respectively, then choose the
correct options from the following.

[MSQ 2points]

Timestamp ordering protocol does not allow the transaction

Timestamp ordering with Thomas Write rule allows the transaction
Neither Timestamp ordering nor Thomas Write rule allows the transaction
None of the above

Solution: When T3 tries to perform w3(A), it checks what is the read and write
timestamp of A.
As T1 has the greatest timestamp value and it has till now only wrote operand A
and never did read it, so write timestamp of A will be 20 and read timestamp of A
will be 10 at this point of time.
Timestamp ordering protocol will not allow the transaction since
writetimestampof A(20) > timestampof T 3
but Thomas write rule will allow the transaction since
readtimestampof A(10) = timestampof T 3.
Thomas write rule ignores the write timestamp.
So, option 1 and 2 are correct choices.

Page 10
10. In the wait-die scheme for deadlock prevention, starvation can be avoided to a large
extent by: [ MCQ: 2 points]
non pre-emptive rollback of younger transactions

restarting rolled back transactions with original timestamp
pre-emptive rollback of older transactions
detecting deadlocks using precedence graphs

Solution: When both younger and older transactions are restarted, they both start
with same timestamp and hence the older transactions lose the advantage of their
seniority. There is a possibility that even in the next rollback step, the same trans-
action gets rolled back again. This can lead to starvation. When the timestamp
of transactions are retained during rollback, the older transactions get precedence
over younger ones, and hence the likelihood of starvation is reduced, though not
completely avoided.

Page 11
11. Choose the correct statement(s) about the lock-based protocols.
Statement I: A transaction will never be granted a lock on an item, even if the requested
lock is compatible with locks already held on the item by other transactions.
Statement II: Any number of transactions can hold shared locks on an item, unless
any transaction holds an exclusive on the item.
Statement III: If a lock cannot be granted, the requesting transaction is made to wait
until all incompatible locks held by other transactions have been released.
[ MCQ: 2 points]
I & II

II & III
I & III
I, II, & III

Solution: Statements II & III are correct by the definitions of shared and exclusive
locks. In the case of Statements I, the correct statement would be - a transaction
may be granted a lock on an item if the requested lock is compatible with locks
already held on the item by other transactions.

Page 12
12. Choose the correct output obtained on running the given SQL statements on Table Em-
ployee. [ MCQ: 2 points]
SQL> SAVEPOINT SP1;
EID EName SQL> UPDATE Employee SET EName=‘Jainie’
E01 Arthur WHERE EID=‘E06’;
E02 Raina SQL> SAVEPOINT SP2;
E03 Meena SQL> DELETE FROM Employee WHERE EID=‘E02’;
E04 Arthur SQL> SAVEPOINT SP3;
E06 Joey SQL> UPDATE Employee SET EName=‘Raina’
Table Employee WHERE EID=‘E04’;
SQL> ROLLBACK TO SP1;
EID EName
E01 Arthur
E02 Raina
E03 Meena
E04 Arthur
E06 Jainie
EID EName
E01 Arthur
E03 Meena
E04 Arthur
E06 Jainie
EID EName
E01 Arthur
E03 Meena
E04 Raina
E06 Jainie
EID EName
E01 Arthur
√ E02 Raina
E03 Meena
E04 Arthur
E06 Joey

Solution: Since savepoint SP1 is the first savepoint added before any of the DML
statements in the list are executed, a rollback to SP1 will undo all modifications
(since no commit statements have been executed).

Page 13
13. Given below are four statements. Match each of them with the corresponding property
in the set of ACID properties.
Statement 1 : Any data written to the database must be valid according to all the defined
rules like the check and key constraints and triggers.
Statement 2 : Every completed transaction is saved into the secondary storage.
Statement 3 : During money transfer, either the amount debited from the source account
must be credited to the destination account or the money should not be debited from
the source account at all.
Statement 4 : If multiple transactions are being executed concurrently, then the final
result should be the same immaterial of the sequence in which the transactions were
executed.
Let A denote Atomicity, C denote Consistency, I denote Isolation and D denote Dura-
bility. From among the given options, find the correct match.
[ MCQ: 2 points]

1 - A, 2 - C, 3 - I, 4 - D

1 - C, 2 - D, 3 - A, 4 - I
1 - D, 2 - I, 3 - C, 4 - A
1 - I, 2 - A, 3 - D, 4 - C

Solution: The statements follow from definition of each property in the set of ACID
properties.

Page 14
BSCCS2001: Practice Assignment with Solutions
Week 11

{Write general instructions here}


1. Which of the following statements is/are true? [MSQ:2 points]
If a crash/rollback occurs before the operation completes, then the logical undo
is performed and the physical undo information for the operation is ignored.
If a crash/rollback occurs after the operation completes, then the physical
undo information is used to undo the operation.

If a crash/rollback occurs after the operation completes, then the operation-
end log record is found.

If a crash/rollback occurs before operation completes, then the operation-end
log record is not found.

Solution:

• If crash/rollback occurs before the operation completes, then the physical undo
information is used to undo the operation.

• If crash/rollback occurs after the operation completes, then the logical undo is
performed and the physical undo information for the operation is ignored.

• If crash/rollback occurs after the operation completes, then the operation-end


log record is found.

• If crash/rollback occurs before the operation completes, then the operation-end


log record is not found.

Page 2
2. Which of the following statements is/are true regarding checkpoints in the transaction?
[MSQ: 2 points]

Any transactions committed before the last checkpoint should be ignored.
Any transactions committed since the last checkpoint should be ignored.

It scans backwards from the end of the log to find the most recent < checkpointL >
record.
Any transaction that was running at the time of failure needs to be redone.

Solution:

• It scans backwards from end of log to find the most recent < checkpointL >
record.

• Any transactions that committed before the last checkpoint should be ignored.

• Any transactions that committed since the last checkpoint need to be redone.

• Any transaction that was running at the time of failure needs to be undone
and restarted.

So, options 1 and 3 are correct.

Page 3
3. Consider the following log records of transactions, where immediate database modifica-
tion scheme is used. [ MSQ: 2 points]

step Details of log


1 < T0 , start >
2 < T0 , A, 1200, 900 >
3 < T0 , B, 1000, 800 >
4 < T1 , start >
5 < T1 , D, 200, 50 >
6 < T0 , commit >
7 < T2 , start >
8 < T2 , P, 700, 300 >
9 < T2 , Q, 1150, 670 >
10 < checkpointL >
11 < T1 , E, 400, 320 >
12 < T1 , commit >
13 < T2 , R, 300, 100 >

Suppose the transactions failed after step 13, then which of the following is/are correct?
Transaction T1 needs no recovery

Transaction T2 needs to be undone
Transaction T0 and T1 need no recovery

Transaction T1 needs to be redone

Solution:
Any transactions that committed before the last checkpoint should be ignored. So
T0 can be ignored.
Any transactions that committed since the last checkpoint need to be redone. So,
T1 need to be redone.
Any transaction that was running at the time of failure needs to be undone and
restarted. So, T2 need to be undone and restarted.

Page 4
4. Consider the following statements: [MCQ:2Points]

1. Hot backup refers to keeping a database up and running while the backup is being
performed concurrently.
2. Hot backup is mainly used for Transaction Log Backup.
3. Transactional Logging is used in circumstances where a possibly inconsistent backup
is taken.

Choose the correct option.


Statements 1 & 2 are correct
Statements 1 & 3 are correct

All the statements are correct
Only Statement 1 is correct

Solution: Refer to slide No. 51.25

Page 5
5. Figure 1 shows the timeline of four transactions T1, T2, T3 and T4 respectively.

Figure 1: State of transactions

Which of the following action(s) will be taken by the recovery manager? [MSQ: 2
points]
Transaction T1 is ignored.
Transaction undo is performed for T2.

Transaction redo is performed for T1 and T2.

Transaction undo is performed for T3 and T4.

Solution:

1. Transaction T1 starts before the checkpoint and commits before system crash,
so T1 needs to be redone.

2. Transaction T2 starts after the checkpoint and commits before system crash,
so T2 needs to be redone.

6. Consider the following log involving three transactions T1, T2, T3: -

Page 6
Which of the following will happen after the crash occurs? [MSQ: 2 points]

T1 is committed before the checkpoint, it will be ignored.
T2 is committed but after the checkpoint, so it should be ignored.
T3 did not commit, so redo all its updates.

T2 is committed but after the checkpoint, so redo all its updates.

Solution:

• Transaction T1 started before the checkpoint and committed before the check-
point as well, so T1 will be ignored.

• Transaction T2 started after the last checkpoint and committed before the
system crash, so the changes made to T2 needs to be redone.

• Since T3 did not commit before the system failure, so any changes made to T3
needs to be undone.

7. Consider the following statements:-

• Since B+ tree insertions and deletions release lock early, they can be restored by
physical undo logging.
• Redoing the previous updates should be logged physically as they do not conflict
with the early lock release.

Page 7
Choose the correct option. [MCQ: 2 points]
Statement 1 is correct & Statement 2 is wrong.
Both the statements are correct.

Statement 1 is wrong & Statement 2 is correct.
All the statements are wrong.

Solution: Please refer to slide 54.8 & 54.9.

8. What happens if a crash occurs after the operation in the logging process is completed?
[MSQ: 2 points]
Physical undo operation is used to undo the operation.

A logical undo operation is performed using the operation identifier.

Physical undo operation is ignored.
None of the above

Solution: Please refer to slide 54.12.

Page 8
9. Consider the following statements.

[NAT: points]

1. It is mandatory to perform a full backup at least once.


2. Recovery from a full backup is the easiest.
3. There is very little to no dependency between consecutive full backups.

How many among the given statements are true regarding Full Backup?

Ans: 3

Solution: Statement 1 is true because we must have one full backup initially.
Statement 2 is true because, while recovering directly from a full backup one consol-
idated read would restore everything in the database.
It’s the least complex recovery process.
Statement 3 is true. Since full backup backs up everything there will not be any
dependency on multiple versions of backup.

Page 9
10. Consider the given backup schedule, and answer the question.

Figure 2: .

You can have at most one differential backup in a week and all other backups shall be
incremental (except the one full backup given).
On which day will you do the differential backup so as to minimise the number of backup
sets required for recovery on any arbitrary day?

[MCQ: points]

Friday
Sunday

Wednesday
Number of sets required for recovery is independent of the day of differential
backup.

Solution: If we keep the differential backup on Wednesday then irrespective of the


day of failure we will not require more than 4 backup sets, which is the minimum
considering all other scenarios.

Page 10
Answer questions 11 and 12 on the basis of the given data.

A RAID-5 storage system with similar arrangement of parity blocks as described in


slide 55.16 is used for storing the following data:

Figure 3: RAID-5 data

11. According to the figure disk-2 has crashed. What data is present in the two blocks of
disk-2?
Note: Assume block size is 4 bits

[2 points:MCQ]

block 1: 0100, block 2: 0100
block 1: 0101, block 2: 0100
block 1: 0001, block 2: 0100
block 1: 0001, block 2: 0001

Solution:
RAID-5 uses XOR recovery facility for lost data.So the data stored in a block of
disk-2 can be obtained by performing bitwise XOR of all blocks of other disks in the
same row.
So block 1 of disk-2 stores = 0100 XOR 0100 XOR 0001 XOR 0101= 0100
block 2 of disk-2 stores = 0101 XOR 0100 XOR 0100 XOR 0001= 0100
Hence option 1 is correct.

Page 11
12. Assume that the binary values represent 8 bit ASCII code. What is the data word
present inside this RAID-5 storage system?

[2 points:MCQ]

IITM
IITB

DATA
DBMS

Solution:
ASCII is 8 bit code so we will group every successive 8 bits from the RAID-5 storage,
except the parity bits.
Disk-5 block-1, Disk-4 block-2 are parity blocks hence these will not be added into
the data part.
So the data is :01000100 (68 =‘D’), 01000001 (65 =‘A’),01010100(84 =‘T’), 01000001
(65 =‘A’).
So the word is ‘DATA’. Option 3 is correct.

Page 12
13. For the given set of statements below:

• RAID-1 can allow parallel read of two different disk blocks always
• RAID-4 cannot allow parallel read of different disk blocks always
• RAID-5 allows parallel processing of multiple write requests
• In a system where small write operations occur frequently RAID-5 is better than
RAID-1

How many statement(s) is/are FALSE ? [2 points:NAT]

Answer: 1

Solution:
statement 1: is true. Since data in RAID-1 is stored in two redundant copies, at
any time it can allow two different reads of disk blocks.

statement 2: is true. Since RAID4 uses block interleaved parity, a single data
instance may be distributed among all the disk’s blocks. When a read of such a data
is going on it will operate on all the disks at the same time and hence no disk would
be free to service a different read request.

statement 3: is true, since RAID5 does not use a reserved disk for parity. Hence,
all disks can separately maintain their own parity information. Two or more simul-
taneous write operation on different disks can work because there is no bottleneck
for updating one parity disk for an ongoing write, like in case of RAID 3, 4.

statement 4: is false. A system where the frequency of small write is higher RAID
5 is not a good choice. As every write in RAID 5 requires read-modify-write cycle
which is time consuming and therefore performing frequent writes is bad for RAID5.
RAID 1 is a better choice in this scenario.

14. Consider the following statements regarding RAID 3. [MCQ:2points]

1. RAID 3 consists of byte-level striping with dedicated parity.


2. RAID 3 uses multiple designated drives for parity.
3. RAID 3 cannot service multiple requests simultaneously.

Choose the correct option.


Statement 1 & 2 are correct
Only statement 1 is correct

Only statements 1 & 3 are correct

Page 13
All the statements are correct

Solution:

• RAID 3 consists of byte-level striping with dedicated parity.

• RAID 3 has a single check disk with parity information.

• RAID-3 cannot service multiple requests simultaneously: This is so because any


single block of data will be spread across all members of the set and will reside
in the same physical location on each disk. Thus, every single I/O request has
to be addressed by working on every disk in the array.

Page 14
BSCCS2001: Practice Assignment with Solutions
Week 12
1. Consider the relation Students and Activity as shown below [Piyush:MCQ:2points]

Name RollNo Age Marks Subject


David M003 23 78 Maths Aid Sports Awards Points
Matthew S007 29 54 English M003 Cricket 2 67
Anand C001 22 89 JAVA S007 Football 4 90
Mitchel M006 21 56 Maths C001 Cricket 5 80
Shaun M009 26 92 Maths M006 Tennis 8 70
Jimmy C009 29 42 JAVA M009 Hockey 3 75
Richard S003 20 99 English
Relation Activity
Relation Classroom

Choose the correct output of relational algebra expression


ΠRollN o,Age,Awards ((σSubject=‘M aths‘ (Classroom)) o
nRollN o=Aid (σSports=‘Cricket‘ (Activity)))

RollNo Age Awards


M003 23 2
S007 29 4
M006 21 8
M009 26 3
√ RollNo Age Awards
M003 23 2
RollNo Age Awards
M003 23 2
M006 21 8
M009 26 3

Invalid relational algebra query

Solution: From the equivalence rules,

σθ1 ∧θ2 (E1 o


nθ E2 ) = (σθ1 (E1 )) o
nθ (σθ2 (E2 ))

The given relational algebra expression is equivalent to


ΠRollN o,Age,Awards (σSubject=‘M aths‘∧Sports=‘Cricket‘ ((Classroom) o
nRollN o=Aid (Activity)))

Firstly, it will perform the join operation between Classroom and Activity, based
on the theta condition RollNo = Aid.

Page 2
Then, based on the select conditions, σSubject=‘M aths‘∧Sports=‘Cricket‘ , it will filter the
tuples and then by using Projection operator, it will project RollNo, Age and
Awards.

2. Consider the following statements. [Piyush:MCQ:2points]

1. Query Cost is generally measured as total elapsed time for answering query.
2. Cost to write a block is less than cost to read a block.

Choose the correct option.



Statement 1 is true and Statement 2 is false
Statement 1 is false and Statement 2 is true
Both the statements are true
Both the statements are false

Solution:

• Query Cost is generally measured as total elapsed time for answering query.

• Cost to write a block is greater than cost to read a block.

Page 3
3. Consider the follwoing relations:
employee(EID, ENAME, CONTACT, SALARY ),
project(PID, PNAME, LOCATION, DURATION ),
allotment(EID, PID, DATE OF ALLOTMENT )
Consider the following equivalent join statments:
E1 : employee ./ allotment = allotment ./ employee,
E2 : (employee ./ allotment) ./ project = employee ./ (allotment ./ project)
E3 : σLOCAT ION =”Chennai” (project ./ allotment) = project ./ σLOCAT ION =”Chennai” (allotment).
Segregate the equvalences hold by the Commutative property, Associative property, and
Distributive property. [ARUP:MCQ:2points]

E1 by Commutative property, E2 by Associative property, E3 Distributive
property
E1 by Associative property, E2 by Commutative property, E3 by Distributive
property
E1 by Distributive property, E2 by Commutative property, E3 by Associative
property
E1 by Commutative property, E2 by Distributive property, E3 by Associative
property

Solution:

• E1 hold by commutative property of natural join

• E2 hold by associative property of natural join

• E3 hold by distributive property of select operation over the natural join oper-
ation

Page 4
4. Consider the following relations:
employee(EID, ENAME, CONTACT, SALARY ),
project(PID, PNAME, LOCATION, DURATION ),
allotment(EID, PID, DATE OF ALLOTMENT )
Identify the most optimized expression tree from the given options that finds out names
of all the projects alloted to (ENAME) RAJ and the project location (LOCATION)
is Chennai. We assime that employee ./ allotment is much larger than allotment ./
project. [ARUP:MCQ:2points]

Page 5

Solution:

• Option-2 is more efficient from option-1, since performing the selection as early
as possible reduces the size of the relation to be joined

• Option-3 is more efficient from option-2, since performing the projection as


early as possible reduces the size of the relation to be joined

• Option-4 is more efficient from option-3, since employee ./ allotment is much


larger than allotment ./ project

Page 6
5. Consider a nested loop join for the given relation instructor and teaches:

Assuming the worst-case memory availability, find out the estimated cost i.e., the number
of blocks transfers and seeks. [Anjana: MCQ: 2 points]
Block Transfers= 800300, Seeks= 2300

Block Transfers= 510400, Seeks= 2100
Block Transfers= 600400, Seeks= 2300
Block Transfers= 800300, Seeks= 2100

Solution: As the outer relation should be smaller, we take teaches as the outer
relation and instructor as the inner relation.
Number of Block Transfers= nt * bi + bt =1700 * 300 + 400 = 510400
Number of Seeks= nt + bt = 1700 + 400 = 2100

Page 7

You might also like