Docsity

CMPSCI 445 - Homework 1: Relational Algebra and SQL, Assignments of Management Information Systems

Toggle sidebar
bg1
CMPSCI 445 — Homework 1
5 Problems, 100 Points
Due September 22, at the beginning of class.
Typed solutions preferred. If hand-written, solutions must be legible.
1. (18 pts) Operator result sizes
Given two relations R1 and R2, where R1 contains N1 tuples, R2 contains N2 tuples, and
N2 >N1 >0, give the minimum and maximum possible sizes (in tuples) for the resulting
relation produced by each of the following relational algebra expressions. Also, in each case,
state any assumptions about the input schemas for R1 and R2 needed to make the expression
meaningful:
(a) R1 ∩R2
(b) R1 ∪R2
(c) R1 −R2
(d) R1 ×R2
(e) σa=5(R1)
(f) πa(R1)
2. (10 pts) Translating relational algebra expressions
Consider the following schema:
•Suppliers(sid: integer, sname: string, address: string)
•Parts(pid: integer, pname: string, color: string)
•Catalog(sid: integer, pid: integer, cost: real)
The domain of each field is listed after the field name. Naturally, the Suppliers and Parts
relations represent supplier entities and part entities and their attributes. The Catalog re-
lation lists the prices charged for parts by suppliers. Describe in words the output of these
relational algebra expressions:
(a) πsname(πsid((σcol or=green P arts)./ (σcost<100Catalog)) ./ Suppliers)
(b) (πsname((σcolor=r edP arts)./ (σcost<100Catalog)./ Suppliers)) ∩
(πsname((σcolor=g reenP ar ts)./ (σcost<100C atalog)./ Suppliers))
1
pf3

Partial preview of the text

Download CMPSCI 445 - Homework 1: Relational Algebra and SQL and more Assignments Management Information Systems in PDF only on Docsity!

CMPSCI 445 — Homework 1

5 Problems, 100 Points

Due September 22, at the beginning of class. Typed solutions preferred. If hand-written, solutions must be legible.

  1. (18 pts) Operator result sizes

Given two relations R1 and R2, where R1 contains N1 tuples, R2 contains N2 tuples, and N2 > N1 > 0, give the minimum and maximum possible sizes (in tuples) for the resulting relation produced by each of the following relational algebra expressions. Also, in each case, state any assumptions about the input schemas for R1 and R2 needed to make the expression meaningful:

(a) R1 ∩ R (b) R1 ∪ R (c) R1 − R (d) R1 × R (e) σa=5(R1) (f) πa(R1)

  1. (10 pts) Translating relational algebra expressions

Consider the following schema:

  • Suppliers(sid: integer, sname: string, address: string)
  • Parts(pid: integer, pname: string, color: string)
  • Catalog(sid: integer, pid: integer, cost: real)

The domain of each field is listed after the field name. Naturally, the Suppliers and Parts relations represent supplier entities and part entities and their attributes. The Catalog re- lation lists the prices charged for parts by suppliers. Describe in words the output of these relational algebra expressions:

(a) πsname(πsid((σcolor=greenP arts) ./ (σcost< 100 Catalog)) ./ Suppliers) (b) (πsname((σcolor=redP arts) ./ (σcost< 100 Catalog) ./ Suppliers)) ∩ (πsname((σcolor=greenP arts) ./ (σcost< 100 Catalog) ./ Suppliers))

  1. (12 pts) Monotonicity

A query or operator on relations is said to be monotone if whenever we add a tuple to one of the input relations, the result contains all the tuples that it contained before adding the tuple, plus perhaps more tuples. That is, there is no way to remove tuples from the output by adding tuples to the input. For each relational algebra operator below, state whether it is monotone. If an operator is not monotone, provide an example that demonstrates this fact.

(a) ∪ (b) ∩ (c) × (d) σ (e) π (f) −

  1. (6 pts) Relational algebra to SQL

Given relational tables with schemas R(A, B), S(A, C), T (C, D), express the following rela- tional algebra query in SQL.

ΠR.A,R.B,S.C (σR.A< 10 ,T.D=11(R 1 S 1 T )))

(Note: There is a tricky part to this question—remember that the relational algebra and SQL handle duplicates differently.)