CSc 2510, Theoretical Foundations of Computer Science
Fall 2007
Final Practice Problems Solutions

Additional 4.1 Problems:
    1. Symmetric
    2. Anti-symmetric, Transitive
    3. Reflexive, Anti-symmetric, Transitive
    4. Reflexive, Symmetric, Transitive
    5. Reflexive, Anti-symmetric, Transitive
    6. Symmetric
    7. Symmetric
  1. Consider the set S = {a, b, c, d}.
    1. R = {(a,a),(b,b),(c,c),(d,d),(a,b),(b,a),(b,c),(c,b)} is reflexive, symmetric, and not transitive.
    2. R = {(a,a),(b,b),(c,c),(d,d),(a,b)} is reflexive, not symmetric, and transitive.
    3. R = {(b,b),(c,c),(d,d),(a,b)} is not reflexive, not symmetric, and transitive.
    4. R = {(a,a),(b,b),(c,c),(d,d),(a,b),(b,c)} is reflexive, not symmetric, and not transitive.
  2. Solution shown below images:
    1. R = { (a,a), (b,b), (c,c), (d,d), (e,e), (f,f), (a,d), (b,e), (c,f) }
    2. R = { (1,1), (2,2), (3,3), (4,4), (5,5), (1,2), (2,4), (4,5), (1,4), (2,5), (1,5), (1,3), (3,4), (3,5) }

Write queries using Relational Algebra to answer the following requests of the enrollDB database:
  1. Get the names of students enrolled in three or more courses.
    project[NAME](
    student join select[C1 <> C2 and C2 <> C3 and C1 <> C3](
        rename[SID,C1,G1](enroll) join
        rename[SID,C2,G2](enroll) join
        rename[SID,C3,G3](enroll)
      )
    );
    
  2. Get the names of students who have received at least two "F" grades.
    project[NAME](
    student join select[C1 <> C2](
    rename[SID,C1,G1](select[Grade='F'](enroll)) join
    rename[SID,C2,G3](select[Grade='F'](enroll))
    )
    );
    
  3. Get the names of students who have enrolled in the "Theory" and "Database" courses.
    project[NAME](
    student join 
    rename[SID,C1,G1](enroll) join
    rename[C1,T1](select[TITLE='Theory'](course)) join
    rename[SID,C2,G2](enroll) join
    rename[C2,T2](select[TITLE='Database'](course))
    );
    
  4. Get the course number and titles of courses which have at least three students enrolled in them.
    project[CNO,TITLE](
    course join select[S1 <> S2 and S2 <> S3 and S1 <> S3](
        rename[S1,CNO,G1](enroll) join
        rename[S2,CNO,G2](enroll) join
        rename[S3,CNO,G3](enroll)
      )
    );
    
  5. Get the course number and titles of courses in which at least two students have received "A" grades.
    project[CNO,TITLE](
    course join select[S1 <> S2](
        rename[S1,CNO,G1](select[Grade='A'](enroll)) join
        rename[S2,CNO,G2](select[Grade='A'](enroll))
      )
    );
    

Page Maintained by raj@cs.gsu.edu