1 / 17

Assignment 1

Assignment 1. 5. X = {x: x = 5 * n, where n  N} Y = {y: y = 7 * n - 2, where n  N} Note: set N is the set of all non-negative integers. N = {0,1, 2, 3, 4 . . . } y = 7 * n – 2 = (7 * n) – 2 ≠ 7 * (n – 2). Assignment 1.

shing
Download Presentation

Assignment 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Assignment 1 5. X = {x: x = 5 * n, where n  N} Y = {y: y = 7 * n - 2, where n  N} Note: set N is the set of all non-negative integers. N = {0,1, 2, 3, 4 . . . } y = 7 * n – 2 = (7 * n) – 2 ≠ 7 * (n – 2)

  2. Assignment 1 5. X = {x: x = 5 * n, where n  N} Y = {y: y = 7 * n - 2, where n  N} Note: set N is the set of all non-negative integers. 5.1 List the first three elements of each set, starting with the smallest one. N: 0, 1, 2, . . . X: 0, 5, 10, . . . Y: -2, 5, 12, . . . 5.2 Give a one-to-one mapping between the two sets. The formula must not contain n. x = 5 * n n = x / 5 y = 7 * n – 2 y = 7 * (x / 5) - 2

  3. Assignment 2 • Relational Algebra • Which tables? • What operations? • Common attributes? • What result (attributes)? • Syntax (Standard Notations and Symbols)

  4. I a) R (A1, A2) R = {(1, 2), (4, 3), (2, 9), (3, 8)} S (B1, B2, A1) S = {(x, a, 1), (y, b, 1), (z, a, 4)} A1, B2 (A1 < 4 and B1  x (S)) = A1, B2 ( { (y, b, 1) } ) = { (1, b) }

  5. I b) R (A1, A2) R = {(1, 2), (4, 3), (2, 9), (3, 8)} S (B1, B2, A1) S = {(x, a, 1), (y, b, 1), (z, a, 4)} A2, B1 (R.A1 > S.A1 ( R  S)) = { (3, x), (3, y), (8, x), (8, y), (9, x), (9, y)} R  S (1, 2, x, a, 1) (1, 2, y, b, 1) (1, 2, z, a, 4) (4, 3, x, a, 1) (4, 3, y, b, 1) (4, 3, z, a, 4) (2, 9, x, a, 1) (2, 9, y, b, 1) (2, 9, z, a, 4) (3, 8, x, a, 1) (3, 8, y, b, 1) (3, 8, z, a, 4) • R.A1 > S.A1 ( R  S) • (4, 3, x, a, 1) • (4, 3, y, b, 1) • (2, 9, x, a, 1) • (2, 9, y, b, 1) • (3, 8, x, a, 1) • (3, 8, y, b, 1)

  6. I c) R (A1, A2) R = {(1, 2), (4, 3), (2, 9), (3, 8)} S (B1, B2, A1) S = {(x, a, 1), (y, b, 1), (z, a, 4)} R S = { (1, 2, x, a), (1, 2, y, b), (4, 3, z, a)} R  S (1, 2, x, a, 1) (1, 2, y, b, 1) (1, 2, z, a, 4) (4, 3, x, a, 1) (4, 3, y, b, 1) (4, 3, z, a, 4) (2, 9, x, a, 1) (2, 9, y, b, 1) (2, 9, z, a, 4) (3, 8, x, a, 1) (3, 8, y, b, 1) (3, 8, z, a, 4) • R.A1 = S.A1 ( R  S) • (1, 2, x, a, 1) • (1, 2, y, b, 1) • (4, 3, z, a, 4)

  7. I d) R (A1, A2) R = {(1, 2), (4, 3), (2, 9), (3, 8)} S (B1, B2, A1) S = {(x, a, 1), (y, b, 1), (z, a, 4)} A2, B1, B2, S.A1 (R S) = { (2, x, a, 1), (2, y, b, 1), (3, z, a, 4)} R  S (1, 2, x, a, 1) (4, 3, x, a, 1) (2, 9, x, a, 1) (3, 8, x, a, 1) (1, 2, y, b, 1) (4, 3, y, b, 1) (2, 9, y, b, 1) (3, 8, y, b, 1) (1, 2, z, a, 4) (4, 3, z, a, 4) (2, 9, z, a, 4) (3, 8, z, a, 4) R S (1, 2, x, a, 1) (1, 2, y, b, 1) (4, 3, z, a, 4)

  8. I e) R (A1, A2) R = {(1, 2), (4, 3), (2, 9), (3, 8)} S (B1, B2, A1) S = {(x, a, 1), (y, b, 1), (z, a, 4)} R S = { (1, 2, x, a), (1, 2, y, b), (4, 3, z, a), (2, 9, null, null), (3, 8, null, null)} R  S (1, 2, x, a, 1) (1, 2, y, b, 1) (1, 2, z, a, 4) (4, 3, x, a, 1) (4, 3, y, b, 1) (4, 3, z, a, 4) (2, 9, x, a, 1) (2, 9, y, b, 1) (2, 9, z, a, 4) (3, 8, x, a, 1) (3, 8, y, b, 1) (3, 8, z, a, 4) R S (1, 2, x, a, 1) (1, 2, y, b, 1) (4, 3, z, a, 4) (2, 9, null, null, null) (3, 8, null, null, null)

  9. II (a) List all hotels Hotel (hotelNo, hotelName, city) * (Hotel) Use H for Hotel * (H)  hotelNo, hotelName, city (Hotel) hotelNo (Hotel) Incorrect! All attributes when not specified.

  10. b) List all single rooms with a price below £20 per night Room (roomNo, hotelNo, type, price) • (type = ‘Single’ and price < 20) (Room)

  11. b) List all single rooms with a price below £20 per night * (  (type = ‘Single’ and price < 20) (Room) ) Projection is NOT Needed! • (type = Single and price < 20) (Room)  (type = “Single” and price < 20) (Room)  (type = ‘Single’ and price < £20) (Room)  (type = ‘Single’ and price < 20 pounds) (Room) • (type = ‘Single’  price < 20) (Room) Incorrect notation!

  12. c) List the name and addresses of all guests Guest (guestNo, guestName, guestAddress) guestName, guestAddress (Guest) One table only! guestAddress: (street, city, state, zipcode) composite attribute

  13. c) List the name and addresses of all guests Guest (guestNo, guestName, guestAddress) guestName, guestAddress (Guest) guestName, guestAddress (Guest Booking Hotel ) Don’t need Joins!

  14. d) List the price and type of all rooms at the Grosvenor Hotel Room (RoomNo, HotelNo, Type, Price) Hotel (HotelNo, hotelName) • price, type ( hotelName = ‘Grosvenor’ (Room Hotel)) Common attribute: HotelNo • price, type (Room (hotelName = ‘Grosvenor’) (Hotel)) Incorrect! It’s the same as the following:  price, type ((hotelName = ‘Grosvenor’) (Room  Hotel))

  15. e) List all guests currently staying at the Grosvenor Hotel Guest (guestNo, guestName, guestAddress) Hotel (hotelNo, hotelName) Booking (hotelNo, guestNo, dateFrom, dateTo, roomNo)  Guest.* ( (fromDate <= CurrentDate and toDate >= CurrentDate) and hotelName = ‘Grosvenor’) (Guest Booking Hotel))

  16. e) List all guests currently staying at the Grosvenor Hotel Guest (guestNo, guestName, guestAddress) Hotel (hotelNo, hotelName) Booking (hotelNo, guestNo, dateFrom, dateTo, roomNo) What is the common attribute between Guest and Hotel?  Guest.* ( (fromDate <= CurrentDate and toDate >= CurrentDate) and hotelName = ‘Grosvenor’) (Guest Hotel Booking) )  Guest.* ( (fromDate <= CurrentDate and toDate >= CurrentDate) and hotelName = ‘Grosvenor’) (Guest (Hotel Booking)))

  17. f) List the details of all rooms at the Grosvenor Hotel, including the name of the guest staying in the room if the room is occupied Room Guest  Room.*, guestName  (hotelName = ‘Grosvenor’ and fromDate <= CurrentDate and CurrentDate <= toDate) ((Room Hotel) (Booking Guest)) Not correct!  Room.*, guestName  (hotelName = ‘Grosvenor’ ( (Room Hotel) ( (fromDate <= CurrentDate and CurrentDate <= toDate) (Booking Guest)))

More Related