UIT2201: CS & the IT Revolution
Tutorial Set 5 (Spring 2008)

(D-Problems discussed on Thursday, 21-Feb-2008)
(Q-Problems due on Tuesday, 26-Feb-2008)


(Note: To keep the database tables in one page, I will put them and T5-D2, T5-Q2 right in front here.)

Consider a database with 3 tables, STUDENT-INFO, COURSE-INFO, and ENROLMENT. Assume
    • the STUDENT-INFO table has 30,000 (3x104) rows,
    • the COURSE-INFO table has 1,000 (103) rows, [BiYing checked CORS & said 1365 for this semester. Thx]
    • the ENROLMENT table has 100,000 (105) rows.

STUDENT-INFO
Student-ID Name NRIC-ID Address Tel-No Faculty Major

...

...

...

...

...

...

...

COURSE-INFO
Course-ID Name Day Hour Venue Instructor

...

...

...

...

...

...

ENROLMENT
Student-ID Course-ID

...

...

T5-D2: (Efficient Query Processing) [Note: First read my notes and also do T5-D1.]
(a) Give a "concise English description" of the output of the following primitive DB query statements:

    K1 <-- e-select from ENROLMENT where Course-ID='UIT2201' 
    K2 <-- e-join K1 and STUDENT-INFO 
                  where (K1.Student-ID=STUDENT-INFO.Student-ID);
    LIST <-- e-project Name, Faculty from K2

(b) Give an "SQL query" statement to obtain each of the following:

(c) Now, give the the appropriate sequence of basic primitive DB operations (e-project, e-select, and e-join) to produce the results in (b) above. If you can, make it as efficiently as possible.


T5-Q2: (15 points) (Continued from T5-D2 above)
After discussion on T5-D2, you are given the following new queries: For each problem, do the following:


Practice Problems: (not graded)
(If you have difficulties with these practice problems, please see your classmates or the instructor for help.)

T5-PP1: (SQL Query) Read Chapter 13.3 (pp 598-606) of [SG3].
T5-PP2: (SQL Query) Problems 1, 2, 3 on page 606 (Chapter 13) of [SG].
T5-PP3: (SQL Query) Problems 4, 5 on page 617 (Chapter 13) of [SG].


Discussion Problems: -- Prepare (individually) for tutorial discussion.

T5-D1: (SQL Query)
Problems 6 on page 617 (Ch. 13) of [SG].
(Remarks: Read Ch.13.3 of [SG3] to learn about SQL.)

T5-D2: (This problem is given in the previous page.)


Problems to be Handed In for Grading by the Deadline:
(Note: Please submit hard copy to me. Not just soft copy via email.)

T5-Q1: (10 points) (SQL Query) [Modified from Problems 7, p625, Ch 13 of [SG].]
(a) Using the Employees table of Figure 13.6 and the InsurancePolicies table of Figure 13.7, write an SQL query (the declarative type) that retrieves FirstName, LastName, PlanType, DataIssued for all employees who have insurance policy issued after #1/01/1990#.
(b) Give a sequence of basic DB operations (using only e-project, e-select, and e-join) to implement the above query. If you can, make it as efficiently as possible.

T5-Q2: (Please see previous page for this problem.)

T5-Q3: (10 points) [from MajorityX to Majority]
Recall that in T3-D5, we have defined the majority problem and solved a simpler version using MajorityX(A,n,x) which does not find the majority, but only checks whether or not a given number x is the majority.
(a) Using the algorithm MajorityX (A,n,x) as a high level primitive, design a simple algorithm called Majority(A,n) that finds the majority of the list if it exists, or to report that there are none.
(b) What is the time complexity of your algorithm?


A-Problems: OPTIONAL Challenging Problems for Further Exploration

A6: (Faster Exponentiation Algorithm) In T3-D3, we gave a simple Θ(n) algorithm to compute xn (using repeated multiplication). Can you design a much faster algorithm that accomplishes this in time Θ(lg n)?


UIT2201: CS & IT Revolution; (Spring 2008); A/P Leong HW [Prints well with A4-page-offsets l=r=b=0.5", t=0.7"]