Machine-translated by Google. Questions are authored in English.
Top

Discussion

The relation schema, Person(pid,city), describes the city of residence for every person uniquely identified by pid. The following relational algebra operators are available: selection, projection, cross product, and rename.

To find the list of cities where at least 3 persons reside, using the above operators, the minimum number of cross product operations that must be used is

  • A.1
  • B.2
  • C.3
  • D.4

Answer: B

The minimum is 2 cross products.

Without aggregation, 'at least 3 persons' must be expressed by finding three distinct persons in the same city. Rename gives three copies of Person, P1, P2 and P3, and two cross products combine them:

\[ \pi_{P1.city}(\sigma_{\theta}(P1 \times P2 \times P3)) \]

where \(\theta\) requires equal cities and pairwise different pids (P1.pid \(\lt\) P2.pid \(\lt\) P3.pid will do).

One cross product only compares two tuples at a time, which can show a city with at least 2 persons but not 3. Three or four cross products would work but are not the minimum.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.