You are on page 1of 6

Mekelle University Faculty of Business & Economics

Computer Science Department

ICT 252 - Theory of Databases

Final Written Exam – June 2005

Instructor: Terri O’Sullivan Time Allowed: 2.5 hours

Instructions to invigilators:
 The exam is 2.5 hours long.
 Give students as many lined answer papers as they need.
 Students can keep this question paper.
 Students may not take any notes, books or handouts into the exam.

Instructions to students:
 Make sure you have 5 pages and 6 questions in this paper.
 Questions 1 and 2 are compulsory. Answer any two of questions 3,4,5 and 6. If you
answer more than two of questions 3,4,5 and 6, only the first two will be marked.
You may cross out answers you do not want to have marked.
 Write your answers on the separate answer paper provided, clearly numbering your
answers with the appropriate question numbers. Also write your name, section (1 or 2)
and ID number at the top of each separate page.
 The maximum score is 66 marks (this paper is worth 60% of your overall mark for this
course).
 You may not take any notes, handouts or textbooks into the exam with you.
 You may take this paper away with you after the exam.
 Write your answers clearly – you may lose marks for illegible (unreadable) writing.

Compulsory questions – you must answer both of questions 1 and 2.

1. Index File Organization [22 marks total]

a. Compare index-sequential file and B-trees as structures for index file organization. Your
comparison should include information about how the different structures can be searched,
the search performance and any other information you think is relevant. [5 marks]

b. Assume a database table is stored in an ordered sequential file and that it has an index
stored using the index-sequential organization. Assume the index is a dense index.
Outline an algorithm for inserting a new data record to the table (including any updates
necessary to the index). [4 marks]

Page 1 of 6
c. What changes would you make to this algorithm if the index were a sparse index, with an
entry for each block in the data file? [3 marks]

d. List the characteristics of a B tree that distinguish it from normal m-way search trees. [3
marks]

e. What is a B+ tree? [2 marks]

f. What benefit (and why) does a B+ tree have compared to a B tree as an index structure? [1
mark]

g. When talking about an index, what does the term ‘an extra level of indirection’ mean and
why is it used? Use a diagram to support your answer.
Give an example of an index where this might be used. [4 marks]

2. Transactions [22 marks total]

a. What 4 properties must a logical unit of work have in order to be considered a transaction
in a DBMS? Name each property and describe what it means. [10 marks]

b. Which two of the 4 properties are ensured by the concurrency control manager of a
DBMS? [1 mark]

c. Name 3 problems that can occur without concurrency control. [3 marks]

d. Using a diagram, describe in detail one of the problems you named in part c. [3 marks]

e. Define what serializable means for transaction execution. [2 marks]

f. What mechanism is used by the concurrency control manager of a DBMS to avoid these
problems? For one of the problems you described in part c, show how this mechanism
would be used to avoid the problem. [3 marks]

Page 2 of 6
Optional questions - answer any two of questions 3,4,5 and 6

3. Indexing Calculations [12 marks total]

Read the information given and carry out the calculations asked for. Make the steps in your
calculations clear and show the formulae you use. This will help you to get marks if you have
the correct formulae but the wrong answer.

Assume Customer data is stored in an ordered sequential file.


There are r = 30000 Customer records and the file is stored on a disk with block size B = 1024
bytes.
The records are ordered by the CustomerID, a field which is 9 bytes long.
CustomerID is a candidate key for the data.
Records have a fixed size of R = 100 bytes (this includes 9 bytes for the CustomerID) and are
stored using an unspanned organization.

A block pointer, P, is 6 bytes long.


A record pointer, PR, is 7 bytes long.

a. Calculate the blocking factor, bfr, and the number of file blocks, b, required for the data
file. [2.5 marks]

Suppose that we want to build a primary index on CustomerID. Assume it is a sparse index
with one entry per block of the data file.

b. Calculate the number of first-level index entries (ri) and the number of first-level index
blocks (bi). [2.5 marks]

c. Calculate the number of levels required to make it into a multi-level index. For each level,
show the number of blocks in the level. [1.5 marks]

d. Which is faster to search for and retrieve a record from the file, given its CustomerID – to
use the index or to use the data file only? Why? Show the calculations you use to arrive at
your answer. [2.5 marks]

Suppose now that the records are not ordered by the CustomerID and that we want to build a
secondary index on CustomerID.

e. Calculate the number of first-level index entries (ri) and the number of first-level index
blocks (bi) in the secondary index. [2 marks]

f. Calculate the number of levels required to make it into a multi-level index. For each level,
show the number of blocks in the level. [1 mark]

Page 3 of 6
4. SQL/ Relational algebra [12 marks total]

a. You are a database programmer and you have been given the relational database schema
used by a clinic, as shown in Figure 1 below. Write SQL queries to produce the following
sets of data:

(i) Show all patient visits, including columns for the patient name and father’s name,
visit date, notes and staff name. The list should be ordered by patient name and then
by visit date. [2 marks]

(ii) Show only staff who have not been involved in any visits. The list should show
StaffID, name and father’s name. [2 marks]

(iii) Get a count of patients who have taken each type of test. [2 marks]

(iv) Get a list of patients whose first name begins with the letter T. [1 mark]

b. Write relational algebra expressions for the following queries (again using the relational
schema shown in Figure 1 below).

(i) Show the name and father’s name for patients who live in kebele 9. [1.5 marks]
(ii) Show the PatientID, TestTypeID, test Name and test date for all tests taken by
patients. You should use the minimum number of operators and the result should
not have attributes other than PatientID, TestTypeID, test Name and test Date. [1.5
marks]
(iii) Show the PatientID for patients who have taken the test that has name attribute
‘HIV’ and who have also taken the test that has name attribute ‘TB’. The result
does not have to show any attributes other than PatientID. [2 marks]

Page 4 of 6
Figure 1 – clinic database schema

5. Queries [12 marks total]

a. What component of a DBMS deals with running queries? [1 mark]

b. What are the steps that are taken to run a query? Explain what happens at each step. [9
marks]

c. Name 2 algorithms that the DBMS can use to carry out a join. [2 marks]

Page 5 of 6
6. Entity Relationship Modelling [12 marks total]

a. Draw an E-R model based on the following information. Make sure your diagram clearly
shows entities, attributes, identifiers, relationships and cardinalities.
It should also distinguish between identifying relationships and non-identifying
relationships.

The Hiwa dealership in Mekelle sells cars to customers.


When a customer first buys a car from the dealership, his/her details (name, phone number
and PO box number) are recorded. Each customer is also assigned a unique ID number.
Some customers come back again to buy another car.

Each individual car that the dealership has available for sale has a manufactuer (e.g. Toyota
or Nissan), a colour, a model (e.g. Landcruiser, Landcruiser II, Patrol), an engine size and a
price (in birr). Each car is also assigned a unique ID number by the dealership.

The dealership employs sales people; each salesperson is identified by his or her name (no
two of them have the same name). Every car is sold by one sales person. When a customer
buys a car, the purchase is recorded, along with the date of the purchase. The sales person
gets a percentage commission for each sale. The percentage can be different for each sale.

Some cars are sold again – if the customer sells the car back to the dealership. But a car is
never sold again to the same customer. [6 marks]

b. Convert your E-R diagram to a relational database schema. Draw your database schema,
clearly showing relations, attributes, primary keys, foreign keys and relationships. The
primary keys you choose should be candidate keys (minimal super keys). [3 marks]

c. In the relational data model, explain what the following concepts mean and how they are
enforced:
Entity Integrity
Referential integrity
[3 marks]

END OF EXAM

Page 6 of 6

You might also like