1. Home
  2. Explore
  3. Computer Science
  4. Relational Algebra

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Relational Algebra

  • 87Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Foundations

What is relational algebra?

87 questions

  1. 1

    What is relational algebra?

    Model answer

    Relational algebra is a procedural data-manipulation language for the relational model.

    Explanation

    It specifies the operations needed to retrieve the desired data rather than only describing the desired result.

  2. 2

    Why is relational algebra called a procedural language?

    Model answer

    It is procedural because the user specifies how the expected data should be retrieved.

    Explanation

    The sequence and type of operations used to obtain the result are explicitly stated.

  3. 3

    What is the input and output of a relational algebra operation?

    Model answer

    An operation takes one or two relations as input and produces a new relation as its result.

    Explanation

    Unary operations use one relation, whereas binary operations use two.

  4. 4

    What forms a relational algebra expression?

    Model answer

    A relational algebra expression is formed by combining multiple relational algebra operations.

    Explanation

    The operations can be applied sequentially or nested to produce a final relation.

  5. 5

    What are the operands and operators in relational algebra?

    Model answer

    The operands are relations or variables representing relations, and the operators map relations to relations.

    Explanation

    Rules determine how operands and operators are combined and evaluated in an expression.

  6. 6

    What are the four categories of relational algebra operations?

    Model answer

    The four categories are set operations, unary operations, binary operations, and extended operations.

    Explanation

    These categories organize the different ways relations can be manipulated.

  7. 7

    Define a set in the context of relational algebra.

    Model answer

    A set is a collection of items of the same type, such as tuples or rows.

    Explanation

    Relational algebra treats relation contents according to set-based principles.

  8. 8

    What is a tuple?

    Model answer

    A tuple is an immutable, ordered sequence of values and is equivalent to a row in a relational database.

    Explanation

    Each tuple contains one value for each attribute of its relation.

  9. 9

    What is a relation and what is an attribute?

    Model answer

    A relation is a group of tuples, equivalent to a database table, while an attribute is a field or column in that relation.

    Explanation

    Attributes describe the kinds of values stored in each tuple.

  10. 10

    What is a domain?

    Model answer

    A domain is the data type of values permitted for a particular attribute.

    Explanation

    For example, an attribute may permit only integer, text, or date values.

  11. 11

    What does union compatibility require?

    Model answer

    Two relations are union-compatible when they have the same degree and corresponding attributes use the same domains.

    Explanation

    The relations must have compatible structures before union, intersection, or set difference can be performed.

  12. 12

    Why are set operations called binary operations?

    Model answer

    They are binary because each set operation operates on two relations.

    Explanation

    The two input relations are combined or compared to produce one result relation.

  13. 13

    What are the four set operations in relational algebra?

    Model answer

    The four set operations are union, intersection, set difference, and Cartesian product.

    Explanation

    The first three generally require union-compatible relations, while Cartesian product does not.

  14. 14

    What does the union of relations RRR and SSS return?

    Model answer

    It returns all tuples that occur in either RRR or SSS, eliminating duplicate tuples.

    Explanation

    The result contains the combined contents of both relations without repeated rows.

  15. 15

    What degree does the union R∪SR \cup SR∪S have?

    Model answer

    Its degree is the same as the degree of either input relation.

    Explanation

    Union-compatible relations have the same number of attributes, so the result retains that number.

  16. 16

    What conditions must hold before applying a union?

    Model answer

    The two relations must be union-compatible, meaning they have the same degree and corresponding attributes have the same domains.

    Explanation

    Without compatible structures, tuples from the two relations cannot be combined directly.

  17. 17

    What does the intersection of relations RRR and SSS return?

    Model answer

    It returns the tuples that occur in both RRR and SSS, with duplicates eliminated.

    Explanation

    A tuple appears in the result only when it is common to both input relations.

  18. 18

    What conditions must hold before applying intersection?

    Model answer

    The two relations must be union-compatible.

    Explanation

    Intersection compares tuples position by position, so the relation structures must match.

  19. 19

    If John Cena is the only tuple shared by relations writers and clients, what is their intersection?

    Model answer

    The intersection contains only the John Cena tuple.

    Explanation

    Intersection retains only tuples present in both relations.

  20. 20

    What does the set difference R−SR - SR−S return?

    Model answer

    It returns the tuples that belong to RRR but do not belong to SSS.

    Explanation

    The first relation supplies the candidate tuples, and tuples also found in the second relation are removed.

  21. 21

    Why does the order of operands matter in set difference?

    Model answer

    Because R−SR - SR−S removes tuples in SSS from RRR, whereas S−RS - RS−R removes tuples in RRR from SSS.

    Explanation

    Set difference is not commutative, so reversing the operands can change the result completely.

  22. 22

    What is the degree of a set-difference result?

    Model answer

    The result has the same degree as the input relations.

    Explanation

    Set difference preserves tuples from the first relation rather than combining their attributes.

  23. 23

    What does the Cartesian product R×SR \times SR×S do?

    Model answer

    It concatenates every tuple of RRR with every tuple of SSS.

    Explanation

    Each tuple from the first relation is paired with every tuple from the second relation.

  24. 24

    How is the degree of a Cartesian product determined?

    Model answer

    The degree equals the sum of the degrees of RRR and SSS.

    Explanation

    The attributes of both relations are included in each combined tuple.

  25. 25

    How many tuples can a Cartesian product contain?

    Model answer

    If RRR has mmm tuples and SSS has nnn tuples, the product has m×nm \times nm×n tuples.

    Explanation

    Each of the mmm tuples is paired with each of the nnn tuples.

  26. 26

    Does Cartesian product require union-compatible relations?

    Model answer

    No. Cartesian product does not require the two relations to be union-compatible.

    Explanation

    Unlike union, intersection, and difference, it concatenates attributes rather than comparing corresponding tuple structures.

  27. 27

    What is a unary operation?

    Model answer

    A unary operation takes one relation as input and produces one relation as output.

    Explanation

    Selection, projection, rename, and assignment are the unary operations discussed.

  28. 28

    What are the four unary operations discussed?

    Model answer

    They are selection, projection, rename, and assignment.

    Explanation

    These operations filter, reduce, rename, or organize relation expressions.

  29. 29

    What does the selection operation return?

    Model answer

    Selection returns the subset of tuples that satisfies a specified selection condition.

    Explanation

    Tuples failing the condition are discarded.

  30. 30

    Why is selection called a horizontal filter?

    Model answer

    Selection filters rows while retaining the relation's attributes.

    Explanation

    It chooses particular tuples rather than particular columns.

  31. 31

    What is the general notation for selection?

    Model answer

    Selection is written as σcondition(R)\sigma_{condition}(R)σcondition​(R), where the condition is applied to relation RRR.

    Explanation

    The sigma symbol identifies the operation, and its subscript specifies which tuples are retained.

  32. 32

    What kinds of conditions can be used in selection?

    Model answer

    Selection conditions can use comparison operators and logical operators such as AND, OR, and LIKE.

    Explanation

    These operators allow both simple and compound filtering conditions.

  33. 33

    How would you select movies released in 2003 with a rank greater than 7?

    Model answer

    Apply selection to movies using the condition year equals 2003 and rank greater than 7.

    Explanation

    Both conditions must be satisfied for a movie tuple to remain in the result.

  34. 34

    What does projection return?

    Model answer

    Projection returns tuples containing a selected subset of the attributes in the original relation.

    Explanation

    It removes unwanted columns while retaining the selected attributes.

  35. 35

    Why is projection called a vertical filter?

    Model answer

    Projection filters columns rather than rows.

    Explanation

    It selects attributes from each tuple, whereas selection selects tuples.

  36. 36

    What is the general notation for projection?

    Model answer

    Projection is written as πattribute list(R)\pi_{attribute\ list}(R)πattribute list​(R).

    Explanation

    The pi symbol is followed by the attributes to retain and the relation being projected.

  37. 37

    How would you retrieve only first names from the actors relation?

    Model answer

    Project the first_name attribute from actors.

    Explanation

    All other attributes are excluded from the resulting relation.

  38. 38

    How can you retrieve the first and last names of actors whose first name is Michael?

    Model answer

    First select actors whose first name is Michael, then project the first_name and last_name attributes.

    Explanation

    The selection identifies the rows, and the projection limits the output columns.

  39. 39

    What can the rename operation rename?

    Model answer

    Rename can change a relation name, attribute names, or both.

    Explanation

    Renaming changes identifiers without changing the underlying tuples.

  40. 40

    How is a relation name renamed conceptually?

    Model answer

    A new relation name is specified together with the relation whose name is being changed.

    Explanation

    For example, directors can be renamed to producers.

  41. 41

    How can multiple attributes be renamed?

    Model answer

    Specify a list of new attribute names corresponding to the original attributes.

    Explanation

    For example, id, first_name, and last_name can be renamed to director_id, f_name, and l_name.

  42. 42

    What is the purpose of assignment in relational algebra?

    Model answer

    Assignment provides a convenient way to express complex queries as a sequence of named intermediate results.

    Explanation

    Each temporary relation can be reused in later operations.

  43. 43

    What does an assignment statement contain?

    Model answer

    It assigns the result of a relational algebra expression to a temporary relation variable.

    Explanation

    A final expression can then use the temporary variables to produce the displayed result.

  44. 44

    How could assignment be used to find action movies associated with male actors?

    Model answer

    Assign male actors selected by gender to a temporary variable, combine the needed relations, assign that result to another variable, and select tuples whose genre is action.

    Explanation

    Sequential assignments break a complex query into manageable intermediate steps.

  45. 45

    What is a binary operation?

    Model answer

    A binary operation combines two input relations into one output relation.

    Explanation

    The four binary operations discussed are theta join, equi-join, natural join, and division.

  46. 46

    What are the four binary operations discussed?

    Model answer

    They are theta join, equi-join, natural join, and division.

    Explanation

    The join operations combine related tuples, while division identifies tuples associated with every tuple in another relation.

  47. 47

    What is a theta join?

    Model answer

    A theta join joins two relations using a specified comparison condition, such as less than or greater than.

    Explanation

    It is also called a conditional join and may use different comparison operators.

  48. 48

    How would a theta join identify PCs with more RAM than laptops?

    Model answer

    Join the PC and laptop relations using the condition that the PC RAM value is greater than the laptop RAM value.

    Explanation

    Only PC-laptop tuple pairs satisfying that comparison are included.

  49. 49

    What is an equi-join?

    Model answer

    An equi-join is a theta join that uses only an equality condition.

    Explanation

    The joined attributes must have equal values for tuples to be paired.

  50. 50

    How does an equi-join differ from a general theta join?

    Model answer

    A general theta join may use various comparison operators, while an equi-join is restricted to equality.

    Explanation

    Thus, every equi-join is a theta join, but not every theta join is an equi-join.

  51. 51

    What is required for a natural join?

    Model answer

    The two relations must share at least one attribute with the same name and domain.

    Explanation

    The common attributes provide the basis for matching tuples.

  52. 52

    How does a natural join match tuples?

    Model answer

    It matches tuples where the values of their common attributes are equal.

    Explanation

    It performs an equality-based join without explicitly using a comparison operator.

  53. 53

    What happens to duplicate common attributes in a natural join?

    Model answer

    Duplicate copies of common attributes are eliminated from the result.

    Explanation

    The shared attribute appears once in the natural-join output.

  54. 54

    How could a natural join be used to identify the maker of a laptop?

    Model answer

    Project the maker and model from product, then naturally join that result with laptop using their common model attribute.

    Explanation

    The common model value connects each laptop to its product maker.

  55. 55

    What does relational division return?

    Model answer

    Division returns tuples from one relation that are associated with every tuple in a second relation.

    Explanation

    It answers “for all” queries rather than merely finding one matching tuple.

  56. 56

    What happens to the attributes used for division?

    Model answer

    Attributes used in the division do not appear in the result.

    Explanation

    The result retains the attributes describing the tuples that satisfy the “every tuple” condition.

  57. 57

    What is generalized projection?

    Model answer

    Generalized projection extends projection by allowing arithmetic expressions in the projection list.

    Explanation

    It can compute new attribute values while selecting attributes from a relation.

  58. 58

    What role does the relation expression play in generalized projection?

    Model answer

    The relation expression supplies the tuples and attributes used by the arithmetic expressions.

    Explanation

    Generalized projection applies the specified expressions to the relation produced by that expression.

  59. 59

    How can generalized projection calculate credit consumed?

    Model answer

    Project the customer name and calculate credit consumed as credit limit minus credit balance.

    Explanation

    The arithmetic expression creates a derived value for each customer.

  60. 60

    What is an aggregate function?

    Model answer

    An aggregate function takes a collection of values as input and returns a single value.

    Explanation

    Aggregates summarize multiple tuples or values.

  61. 61

    What aggregate functions are discussed?

    Model answer

    The functions are SUM, AVERAGE, COUNT, MIN, and MAX.

    Explanation

    They calculate totals, means, counts, smallest values, and largest values.

  62. 62

    What is the purpose of grouping attributes in aggregation?

    Model answer

    Grouping attributes divide the input tuples into groups so that an aggregate value can be calculated for each group.

    Explanation

    For example, grouping by department produces one salary total per department.

  63. 63

    How would you calculate total salary for each department?

    Model answer

    Group the employee relation by department and apply SUM to the salary attribute.

    Explanation

    The result contains each department and its corresponding total salary.

  64. 64

    Can the grouping-attribute part of an aggregation be omitted?

    Model answer

    Yes. It can be omitted when the query requires one aggregate value over the entire relation rather than one value per group.

    Explanation

    Without grouping, all input values are treated as one collection.

  65. 65

    What is the main purpose of outer joins?

    Model answer

    Outer joins preserve tuples that do not have matching tuples in the other relation and fill missing values with nulls.

    Explanation

    This distinguishes outer joins from ordinary joins, which normally retain only matching combinations.

  66. 66

    What does a left outer join preserve?

    Model answer

    A left outer join preserves all tuples from the left relation and places nulls in the right-side attributes when no match exists.

    Explanation

    The left relation is complete in the result.

  67. 67

    What does a right outer join preserve?

    Model answer

    A right outer join preserves all tuples from the right relation and places nulls in the left-side attributes when no match exists.

    Explanation

    The right relation is complete in the result.

  68. 68

    What does a full outer join preserve?

    Model answer

    A full outer join preserves all tuples from both relations and uses nulls for attributes without matching data.

    Explanation

    It combines the preservation behavior of left and right outer joins.

  69. 69

    In a left outer join where relation A contains number 4 but relation B does not, what values appear for B?

    Model answer

    The tuple for number 4 is retained, and the attributes contributed by B contain null values.

    Explanation

    Left outer join preserves the unmatched tuple from the left relation.

  70. 70

    In a right outer join where relation B contains number 5 but relation A does not, what values appear for A?

    Model answer

    The tuple for number 5 is retained, and the attributes contributed by A contain null values.

    Explanation

    Right outer join preserves the unmatched tuple from the right relation.

  71. 71

    What do the bracket portions of outer-join symbols indicate?

    Model answer

    They indicate which relation's tuples must be preserved or completed in the result.

    Explanation

    The symbol distinguishes left, right, and full outer joins.

  72. 72

    What is an outer union?

    Model answer

    An outer union combines tuples from two relations while also handling common attributes that are not necessarily type-compatible.

    Explanation

    Non-existing attribute values are represented with null or appropriate default values.

  73. 73

    How is outer union related to full outer join?

    Model answer

    Outer union is equivalent to a full outer join on the common attributes.

    Explanation

    Both preserve tuples from both relations and align their shared attributes.

  74. 74

    How does outer union handle attributes found in only one relation?

    Model answer

    It includes the attribute in the result and places null or an appropriate default value for tuples from the relation lacking that attribute.

    Explanation

    This allows relations with different attribute sets to be combined.

  75. 75

    Why might an outer-union result contain zero instead of null for a missing attribute?

    Model answer

    A zero may be used as an appropriate default when the attribute has a numeric data type.

    Explanation

    The treatment of missing values can depend on the attribute's data type.

  76. 76

    How can union compatibility be created when two relations are not initially compatible?

    Model answer

    Use projection or another unary operation to select matching attributes with compatible domains before applying the set operation.

    Explanation

    For example, projecting matching attributes from actors can make it compatible with directors.

  77. 77

    Why might a direct union of actors and directors fail?

    Model answer

    It fails when the relations do not have the same degree and corresponding attributes do not have compatible domains.

    Explanation

    Union requires union compatibility.

  78. 78

    How would you obtain the first and last names of writers and administrators?

    Model answer

    Project the first and last name attributes from each relation and then take their union.

    Explanation

    Projection first makes the relations structurally compatible, and union combines their tuples.

  79. 79

    How would you find clients who are administrators?

    Model answer

    Apply intersection to the client relation and the administrator relation.

    Explanation

    Intersection retains only people appearing in both relations.

  80. 80

    How would you find administrators who are not writers?

    Model answer

    Subtract the writer relation from the administrator relation after making the relations union-compatible if necessary.

    Explanation

    The result contains administrators whose tuples do not occur among writers.

  81. 81

    How would you obtain the Cartesian product of riders, clients, and administrators?

    Model answer

    Apply Cartesian product successively to the three relations.

    Explanation

    Each tuple from one relation is paired with every tuple from the next relation.

  82. 82

    What is the purpose of using selection and projection before a set operation?

    Model answer

    They can filter tuples and choose compatible attributes so that the later set operation produces the intended result.

    Explanation

    Unary operations can prepare relations for union, intersection, difference, or other operations.

  83. 83

    How would you find actors whose names start with “Ch”?

    Model answer

    Apply selection to the actors relation using a condition that the name begins with “Ch.”

    Explanation

    The selection condition retains only actors whose names match that pattern.

  84. 84

    How would you retrieve the first and last names of actors whose first name is Stanley and rename the output attributes?

    Model answer

    Select actors whose first name is Stanley, project first and last names, and rename them to f_name and l_name.

    Explanation

    The query combines selection, projection, and rename.

  85. 85

    How can generalized projection find the total cost of each laptop after a delivery charge of 200 pesos?

    Model answer

    Project the laptop model and calculate total cost as the laptop price plus 200 pesos.

    Explanation

    The arithmetic expression adds the delivery charge to each laptop's price.

  86. 86

    How can an outer join retrieve all employees while identifying which are photographers?

    Model answer

    Use a left outer join from employees to photographers matching the employee person ID with the photographer employee ID.

    Explanation

    All employees remain in the result, while non-photographer employees receive null photographer attributes.

  87. 87

    How would you determine the number of movies directed by each director when the movies have rank at least 8 and were shown between 1960 and 2000?

    Model answer

    Select movies with rank at least 8 and release years from 1960 through 2000, join them with directors, group by director, and count the movies.

    Explanation

    The filtering occurs before grouping so that only qualifying movies contribute to each director's count.

1 of 87
Question 1 of 87

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent