## Due: 11/16/2023 at 11:59pm EST

Collaboration Policy: As mentioned in the syllabus, you are encouraged to communicate, discuss, and collaborate with your peers. However, you must write and submit your own version. We do not condone plagarism and cheating as defined by the BU handbook. If you have any concerns regarding your conduct,please don’t hesitate to reach out to us for clarification. If you work with others, and again I encourage it,please write the names of your collaborators under your name on your submission. For example,if I worked with Lamar, Ruoqi, and Victoria (our teaching staff) as well as Barack Obama on a submission,the beginning of my submission would look something like:

1 HW2 Solutions

2 By: Andrew Wood

3 Collaborators: Lamar Alsubhi, Ruoqi Yang, VictoriaYu, and Barack Obama  编程作业辅导

P.S. I don’t care how you generate your pdf. I am using LATEX, but you certainly do not have to. Please use some kind of typesetting software: hand written submissions are extremely painful to grade (because of handwriting). If I ask you to draw something though, feel free to draw it by hand and take a picture.

### While Loops (20 pts)

Please write a function that implements the following functionality. Your code must use a while loop. A reminder that you should consider different cases of inputs. For instance, if I ask you to write a function that processes a string, your function should work for strings with no characters in it (i.e. an empty string), a string with a single character, with two characters, and so on.

1.(10 pts): Given a string as input, produce a string with the same characters as the input, only in the reverse order. Call this function reverse str w.

2.(10 pts): Given a positive integer, produce a list of pairs (i.e. tuples containing two values). Each pair will contain two positive integers, the sum of which is equal to the input integer. Call this function compute pieces w.

### For Loops (20 pts)  编程作业辅导

Please repeat the following two exercises, this time using a for loop instead of a while loop. Call your functions reverse str f and compute pieces f respectively.

### Keys (20 pts)

1. (2 pts): What is a key?
2. (2 pts): What is a super key?
3. (2 pts): What is a candidate key?
4. (2 pts): What is a primary key?
5. Consider the following incomplete schema:

Video(video id: int, title: str, filesize: int, length: float, num upvotes: int,num downvotes: int, mp4 path: str)

Account(account id: int, account name: str, num followers: int)

Published(account id: int, video id: int)

This schema is incomplete because we wish to allow Accounts to subscribe to other Accounts.

(a) (4 pts): Would we add this information as a new Relation or by modifying existing Relation(s)?

(b) (8 pts): Please add a Subscription Relation to this schema. It should contain the account being

subscribed to as well as the account doing the subscription.

### Relational Algebra (20 pts)  编程作业辅导

Given the schema from the previous question (before any modifications that you made in the previous

question), please express the following queries in Relational Algebra:

1. (5 pts): Find the IDs of accounts with the name “RDCWorld”
2. (5 pts): Find all the video IDs of videos published by an account with the name “RDCWorld”
3. (5 pts): Find all the video IDS published by all accounts except for accounts named “Andrew Wood”
4. (5 pts): Find the video IDS for all videos published by an account named “Linus Tech Tips”

### SQL (20 pts)

Please write the queries from the previous problem in SQL instead of Relational Algebra.