PA,GAS
PA,GAS
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.
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.
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
Page 4
BSCCS2001: Practice Assignment with Solutions
Week 2
Modules covered:
1. Attribute Types, Relation Schema and Instance, Keys, Relational Query Languages
4. Introduction to SQL - History of SQL, Data Definition Language (DDL), Basic Query
Structure (DML)
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).
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]
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.
Page 7
6. Consider the table Employee given in Figure 3.
Determine the correct relation based on the three queries given below: [MCQ: 2 points]
Solution: This question will be discussed in the Solve with the Instructor session.
Page 8
7. Consider the table Employee given in Figure 4.
Determine the suitable query that returns the following table: [MCQ: 2 points]
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]
4
√
5
2
0
WHERE state=‘Karnataka’;
Page 10
9. Using the table Citizen given in Figure 5, answer the question that follows.
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.
Let the table Citizen be created using the SQL statement given below: [MSQ: 2
points]
Page 12
11. Using the table Citizen given in Figure 7, answer the question that follows.
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;
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:
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:
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.
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:
The above query fetches all 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.
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.
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]
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.
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]
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]
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;
Page 5
5. Consider the relational schema given in Figure 4.
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]
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.
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]
Page 8
to fetch data from the table Dependent. Hence, options 2 and 4 are 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]
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]
Page 12
INSERT INTO Employee VALUES (2,’Accounts’,’Raj’,40000);
SELECT ebonus FROM Employee;
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]
If the given code is executed on this instance, then what will be the output/error?
[MCQ:2 points]
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
√
{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.
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.
• 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]
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:
Page 3
• Batsman and Bowler are overlapping specializations of Member.
Hence,
Page 4
5. Consider the E-R diagram given in Figure 2.
[ MCQ: 2 points:Solve with instructor]
The table for entity set ProjectMember is created using the command below:
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:
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]
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 derived attribute play time does not need to be added in the schema.
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.
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.
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).
Page 11
Consider the E-R diagram given in Figure 6 and answer the questions 11 and 12.
11. The minimum number of tables required to represent the entity sets and relationship
sets is ....... [ NAT: 2 points]
Answer: 3
Solution: 3
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)
• 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:
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)
• 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:
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
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:
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
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
Page 6
6. Which among the following is/are the use(s) of finding closure of attributes? [MSQ: 2
points]
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
F = {A → B, AB → C, 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]
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:
Page 12
12. Consider a relation R(A, B, C, D, E) having the following functional dependencies:
F = {A → BCD, D → E, C → D}
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}
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
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.
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 }
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.
Page 5
5. Consider the instance of relation Course given in Figure 1. [ MSQ: 2 points]
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:
Page 6
• t5 [instructor] = t6 [instructor] = t7 [instructor] and
t8 [instructor] = t9 [instructor] = t10 [instructor],
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
• 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:
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]
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]
Page 13
11. Which of the following statements is/are true regarding temporal relations?
[ MSQ: 2 points]
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.
• 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
Page 3
3. Identify A, B and C marked in Figure 1. [MCQ: 2 points]
• 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.
Page 6
6. Match the appropriate statements for
a. 1-tier architecture
b. 2-tier architecture
c. 3-tier architecture
d. n-tier architecture
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.
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.
• forms basis of new generation of Web applications (called Web 2.0 applications)
offering rich user interfaces
• 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.
Page 10
10. Consider the following tasks in a Java program to execute an SQL query at database
server using JDBC.
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
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
• Scalability
• Performance
• 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
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.
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
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
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.
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
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.
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.
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.
Solution:
• A Secure Digital (SD) card is a type of removable memory card used to read
and write large quantities of data.
• The speed of SSD is much larger than that of HDD as it reads/writes data
at higher input-output per second.
Page 9
Answer questions 12 and 13 based on the given 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.
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
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
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
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]
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.
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.
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.
13. Choose the correct SQL statement from the options to remove the index with the name
‘idx userid’ on User ID.
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
Page 2
2. The number of correct statements among the two given statements are
[ NAT 2points]
Ans: 0
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
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)
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
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:
[MCQ 2points]
0
√
1
2
3
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.
Page 7
We observe that there exists no cycle in this graph and hence the schedule is Conflict
serializable.
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
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.
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.
Page 3
3. Consider the following log records of transactions, where immediate database modifica-
tion scheme is used. [ MSQ: 2 points]
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.
Page 5
5. Figure 1 shows the timeline of four transactions T1, T2, T3 and T4 respectively.
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.
• 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.
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
Page 8
9. Consider the following statements.
[NAT: points]
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.
Page 10
Answer questions 11 and 12 on the basis of the given 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
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.
Page 13
All the statements are correct
Solution:
Page 14
BSCCS2001: Practice Assignment with Solutions
Week 12
1. Consider the relation Students and Activity as shown below [Piyush:MCQ:2points]
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.
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.
Solution:
• Query Cost is generally measured as total elapsed time for answering query.
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:
• 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
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