Thursday-solution_-1139956641

.PDF

School

University of Toronto *

*We aren’t endorsed by this school

Course

343

Subject

Computer Science

Date

Jan 9, 2024

Type

PDF

Pages

9

Uploaded by ProfBuffalo3824

Fall 2023 Midterm CSC 343 H1F Duration: 90 min. Question 1. [11 marks] Part (a) [1 mark] Using bag semantics, what is {8, 4, 4, 2, 10, 10, 10, 1} ∩ {1, 1, 4, 5, 10, 10}? {4, 10, 10, 1} Part (b) [4 marks] Consider this schema: Ocean(wave, surf, dolphin) Beach(sand, sun) Ocean[surf] ⊆ Beach[sand] Suppose we know that relation Beach has 15 tuples. 1. What is the fewest tuples that Ocean could have? 0 2. What is the most tuples that Ocean could have? (write “no limit" if there is no limit) no limit Suppose we know instead that relation Ocean has 21 tuples. 3. What is the fewest tuples that Beach could have? 1 4. What is the most tuples that Beach could have? (write “no limit" if there is no limit) no limit Part (c) [3 marks] Consider this schema with two relations and no other constraints: R1(alpha, bravo, charlie ) R2(charlie, echo , foxtrot) Suppose we know that R2 has 5 tuples (but nothing about what’s in them), and that the contents of R1 a alpha bravo charlie 1 2 3 4 2 5 4 6 5 1. What is the most tuples possible from this query? ( 𝜎 𝑎𝑙𝑝 𝑎 = foxtrot ( 1 ⋈ 2)) 𝑅 𝑅 10 2. What is the most tuples possible from this query? Π 𝑏𝑟 𝑎𝑣𝑜 , ℎ 𝑐 𝑎𝑟𝑙𝑖𝑒 ( 𝜎 𝑎𝑙𝑝 𝑎 = foxtrot ( 1 ⋈ 2)) 𝑅 𝑅 3 3. What is the most rows possible from the SQL query below? 10 Note: the reference to charlie in this query was ambiguous; it should have said R1.charlie, below.Many students didn’t notice. We told many who asked that it should be R1.charlie. We also accepted the answer 0 if there was an explanation saying that the query doesn’t run. SELECT bravo, R1.charlie FROM R1, R2 WHERE alpha = foxtrot; Part (d) [3 marks] Suppose we have tables Pony with 12 rows, and Cow with 8 rows, and there are no NULL values in t Assume each of the queries below runs without error. This is all you know. For each of the queries below, what is the fewest possible rows it could yield? 1. SELECT * FROM Pony RIGHT JOIN Cow ON hoof = ear; 8 2. SELECT * FROM Pony LEFT JOIN Cow ON hoof = ear; 12 3. SELECT * FROM Pony NATURAL JOIN Cow; 0
Fall 2023 Midterm CSC 343 H1F Duration: 90 min. This space is for any rough work you might like to do. It will not be marked.
Fall 2023 Midterm CSC 343 H1F Duration: 90 min. Question 2. [6 marks] Recall this schema which you saw in a prep exercise: Relations Employee(eid, name, salary, dept) Department(did, name, division) Sales(eid, day, amount) The employee with this eid had sales valued at this amount on this day. Manages(manager, junior) Employee“manager” manages employee “junior”. Integrity constraints Employee[dept] ⊆ Department[did] Sales[eid] ⊆ Employee[eid] Manages[manager] ⊆ Employee[eid] Manages[junior] ⊆ Employee[eid] We want to find the eid of every employee who has had a day with sales valued at over 20, but has neve with sales valued at over 50. For each query below circle one answer to indicate whether the query is invalid (cannot be evaluated): in this case, explain why it is invalid. valid (can be evaluated) but incorrect: in this case, give a valid instance of relation Sales that dem this, as well as the expected query result and the actual query result. The expected result must be non-empty, unless that is impossible. or correct : in this case, no explanation or instance is required. 1. Π 𝑒𝑖𝑑 ( 𝜎 𝑎𝑚𝑜𝑢𝑛𝑡 650 ( 𝜎 𝑎𝑚𝑜𝑢𝑛𝑡 >20 𝑆𝑎𝑙𝑒𝑠 )) Invalid Valid but incorrect Correct Explanation below: Instance below: No explanation or instance required The inner sigma keeps only tuples with an amount over 20. It keeps entire tuples with all 3 attributes. Of these, the next sigma keeps the tuples that have an amount at most 50. The net effect of both sigmas is to keep tuples with an amount in the range (20, 50] . The project keeps the eids from these rows, so we end up with the eid of anyone who had a day of sales valued in the range (20, 50] . This does not guarantee that they’ve never had a day over 50! Any instance that has a person with a day in the range (20, 50] AND a day over 50 demonstrates the bug. The question also requires a non-empty expected result, so we must inc someone who has had a day over 20 but never had a day over 50. (NB: This explanation was NOT required on the test. It’s just for your learning.) Input instance: eid day amount 123 A 23 123 B 51 456 C 48 Expected result: eid 456 Actual result: eid 123 456
Fall 2023 Midterm CSC 343 H1F Duration: 90 min. 2. 𝑒𝑖𝑑 𝜎 𝑎𝑚𝑜𝑢𝑛𝑡 >20 𝑆𝑎𝑙𝑒𝑠 ) − (Π 𝑒𝑖𝑑 𝜎 𝑎𝑚𝑜𝑢𝑛𝑡 >50 𝑆𝑎𝑙𝑒𝑠 ) Invalid Valid but incorrect Correct Explanation below: Instance below: No explanation or instance required No explanation or instance required. 3. 𝑒𝑖𝑑 ( 𝜎 𝑎𝑚𝑜𝑢𝑛𝑡 >20 𝑆𝑎𝑙𝑒𝑠 )] ∩ [Π 𝑒𝑖𝑑 ( 𝜎 𝑎𝑚𝑜𝑢𝑛𝑡 650 𝑆𝑎𝑙𝑒𝑠 )] Invalid Valid but incorrect Correct Explanation below: Instance below: No explanation or instance required This expression intersects the eids of people who’ve had a day over 20 with the eids of people w a day of at most 50. As in part (1), we end up with the eid of anyone who had a day of sales valued range(20, 50] , which does not guarantee that they’ve never had a day over 50! The same instance (1), or any instance that has a person with a day in the range (20, 50] AND a day over 50, demonstrates the bug. Input instance: eid day amount 123 A 23 123 B 51 456 C 48 Expected result: eid 456 Actual result: eid 123 456
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help