Download as pdf or txt
Download as pdf or txt
You are on page 1of 35

Database Systems

& Concepts

CIS3530
L02
Topics to be covered
 Outline
 Intro to dBs – Mathematical Background
 Data Modeling Using ER-Mod
 Constraints
 Relational Algebra & Relational Calculus
 Structured Query Language
 Optimization
 Concurrency Control and Recovery
 Object & Object-Relational Databases
 Database Security, Adv. Modeling & Distribution
2
Outline
 Set Theory
– Set Operations
 Functions & Relations
 Propositional Logic
– Atoms & Formulas
– Interpretation of Formulas
– Normal Forms
 First-Order Logic
 Graph Theory
– Undirected & Directed Graphs
3
Set Theory
 Definition: Well-defined collection of distinct
objects
 Members (or Elements): part of the collection.
 Roster Method: Description of a set by listing the
elements, enclosed with braces.
– Examples:
• Vowels = {a,e,i,o,u}
• Primary colors = {red, blue, yellow}
 Membership examples
– “a belongs to the set of Vowels” is written as:
a ∈ Vowels
– “j does not belong to the set of Vowels: j ∉ Vowels

4
Sets
 Set-builder method
– A = {x|x ∈ S, P(x)} ˅ A = {x ∈ S| P(x) }
• A is the set of all elements x of S, such
that x satisfies the property P
• Example:
– If X = {2,4,6,8,10}, then in set-builder
notation, X can be described as
– X = {n ∈ N | n is even and n ≤ 10}
5
Sets
 Standard Symbols which denote sets of numbers
– N : The set of all natural numbers (i.e.,all positive integers)
– Z : The set of all integers
– Z* : The set of all nonzero integers
– E : The set of all even integers
– Q : The set of all rational numbers
– Q* : The set of all nonzero rational numbers
– Q+ : The set of all positive rational numbers
– R : The set of all real numbers
– R* : The set of all nonzero real numbers
– R+ : The set of all positive real numbers
– C : The set of all complex numbers
6
– C* : The set of all nonzero complex numbers
Sets
 Subsets
– “X is a subset of Y” is written as X ⊆ Y
– “X is not a subset of Y” is written as X ⊆ Y
– Example:
• X = {a,e,i,o,u}, Y = {a, i, u}
and Z = {b,c,d,f,g}
– Y ⊆ X, since every element of Y is an element of X
– Y ⊆ Z, since a ∈ Y, but a ∉ Z

7
Sets
 Set Equality
– X and Y are sets. They are said to be equal if every
element of X is an element of Y and every element of
Y is an element of X, i.e. X ⊆ Y and Y ⊆ X
– Examples:
• {1,2,3} = {2,3,1}
• Let X = {red, blue, yellow} and Y = {c | c is a primary color}
Then X=Y
 Empty (Null) Set
– A Set is Empty (Null) if it contains no elements.
– The Empty Set is written as ∅
– The Empty Set is a subset of every set

8
Sets
 Cardinality of Sets
– Let S be a finite set with n distinct elements, where n ≥ 0.
Then |S| = n , where the cardinality (number of elements)
of S is n
– Example:
• If P = {red, blue, yellow}, then |P| = 3
 Power Set
– For any set X ,the power set of X ,written P(X),is the
set of all subsets of X
– Example:
• If X = {1,2}, then P(X) = { ∅ , {1}, {2}, {1,2}}

9
Set Operations
 Union of Sets

Example:
If X = {1,2,3,4,5} and Y = {5,6,7,8,9}, then
X∪Y = {1,2,3,4,5,6,7,8,9}
Set Operations
 Intersection of Sets

Example:
If X = {1,2,3,4,5} and Y = {5,6,7,8,9}, then X ∩ Y = {5}
Set Operations
 Difference

• Example:
Let X = {a, b, c, d} and
Y = {c, d, e, f},
then X – Y = {a,b}
and Y – X = {e,f}
Set Operations
 Ordered Pair
– X and Y are sets. If x ∈ X and y ∈ Y, then an ordered pair
is written (x,y)
– Order of elements is important. (x,y) is not necessarily
equal to (y,x)
 Cartesian Product
– The Cartesian product of two sets X and Y ,written X × Y,
is the set
– X × Y ={(x,y)|x ∈ X , y ∈ Y}
• For any set X, X × ∅ = ∅ = ∅ × X
– Example:
• X = {a,b}, Y = {c,d}
– X × Y = {(a,c), (a,d), (b,c), (b,d)}
– Y × X = {(c,a), (d,a), (c,b), (d,b)} 13
Hands On Exercises
1. Draw a Venn Diagram to illustrate the
following relation on sets: (A ∪ B )∩ (C − B )

14
Set Identity Laws

Name Identity
1. Idempotent (a) A∪A=A
(b) A∩A=A
2. Commutative (a) A∪B=B∪A
(b) A∩B=B∩A
3. Associative (a) (A ∪ B) ∪ C = A ∪ (B ∪ C)
(b) (A ∩ B) ∩ C = A ∩ (B ∩ C)
4. Distributive (a) A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)
(b) A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩C)
Set Identity Laws
Name Identity
5. Identity (a) A∪∅=A (c) A∩∅=∅
(b) A∩A=A (d) A∩A=A
6. Complement (a) A ∪ A' = ξ (c) ξ' = ∅
(b) A ∩ A' = ∅ (d) ∅' = ξ
7. DeMorgan’s (a) (A ∪ B)' = A' ∩ B'
(b) (A ∩ B)' = A' ∪ B'
8. Absorption (a) A ∪ (A ∩ B) = A
(b) A ∩ (A ∪ B) = A
9. Set Difference (a) A - B = A ∩ B'
Hands On Exercises
2. Use set Identities to simplify the expression:
((A ∪ B )∩ (A ∪ C ))∩ (A ∪ B )

17
Hands On Exercises
3. Use set Identities to simplify the expression:
( A ∪ B ) ∩ ( ( A ∩ B ) ∪ B' )

18
Hand On Exercises

a. element of 2S.
b. subset of 2S.
c. both element of and subset of 2S.
d. None of the above. 19
 Ex 1: In the ICT Dept at GCUC there are 40
students in the first year. The students in the school
take Discrete Math, S/W Engineering, and
Programming in C. These courses for simplicity
are called DM, SE, and C respectively. We have
been provided with the following information:
7 take none of the courses
16 take Software Engineering
10 take Programming in C
5 take Discrete Math and Software Engineering
4 take Discrete Math and Programming in C
3 take Software Engineering and Programming in C
2 take Discrete Math, Software Engineering, and
Programming in C.
Ass”For the expressions in Questions 10 to 12, use the
following Information:
In CIS Program at GCUC there are 40 students in the first year.
The students in the Program take Discrete Math, Software
Engineering, and Programming in C. We have been provided
with the following information:
5 take none of the courses
16 take Discrete Math
22 take Programming in C
10 take Discrete Math and Software Engineering
13 take Discrete Math and Programming in C
15 take Software Engineering and Programming in C
9 take Discrete Math, Software Engineering, and 21
Programming in C.
10. How many students take Software Engineering?
(a) 10 (b) 18 (c) 22 (d) 26
(e) None of the Above

11. How many students take Discrete Mathematics but not


Software Engineering?
(a) 2 (b) 4 (c) 6 (d) 10
(e) None of the Above

12. How many students take both Discrete Mathematics and


Software Engineering, but not Programming in C?
(a) 1 (b) 6 (c) 12 (d) 13
(e) None of the Above 22
Hands On Exercises
13.The statement Q(x, y) states “x shops at y” where x
is the universal discourse of the population of Accra
and y is all stores. Use logical notation to express the
following:
At least two Accra dwellers shop at Makola.
(a) ∀y∃xQ(x,
∀ ∃ Makola)
(b) ∃x∀yQ(x; y)
(c) ∃x1∃x2 Q(x1, Makola) ∧Q(x2, Makola) ∧ x1 ≠x2
(d) ∀x∀yQ(x, y)
(e) ∃x1∃x2Q(x1, Makola) ^ Q(x2, Makola)
23
Relations
Binary relation
– A binary relation on X and Y is a
subset of X ⋅ Y

n-ary relation
– An n-ary relation on X 1 , X 2 ,..., X nis
a subset of X 1 ⋅ X 2 ⋅...⋅ X n
24
Example: Scissors-Paper-Stone Game
SPS = {Scissors, Paper, Stone}

Beats Scissors Paper Stone

Scissors F T F

Paper F F T

Stone T F F

Beats = { [Scissors, Paper], [Paper, Stone],


[Stone, Scissors]}
Beats ⊆ SPS * SPS
25
Logic
 First we need to set up a precise language to
formulate these problems. (CIS1910):

1. ∀q∃p ∀x, y[p > q ∧ (x,y > 1→ xy ≠p)],

2. ∀a, b, c, n [a,b,c >0 ∧ n>2 → an+bn ≠ cn)],

3. ∀q∃p∀x, y[p > q ∧ (x,y > 1→ (xy ≠p∧xy ≠p+2))]

26
Propositional Logic
Σ = {∧, ∨, ¬, (, ), ∀, ∃, x, R1, …, Rk}
Ri – denotes relations.
 A formula is a well-formed string over Σ.
 A string of the form Ri(x1,…, xj) is an atomic formula. j is
the arity of the relation symbol Ri.
 Thus φ is formula if it
1. is an atomic formula.
2. has the form φ1 ∨ φ2, φ1 ∧ φ2 , ¬φ1, where φ1 and φ2
are formulas,
3. has the form ∃xj[φ1], or ∀xj[φ1], where φ1 is a formula.

27
Quantifiers
Two different roles for variables:
Recall from high-school algebra:
(x + y)(x - y) = x2 - y2 x2 -7x + 12 = 0
Universal statement: Existential statement:
(∀x,y)[(x + y)(x - y) = x2 - y2] (∃x)[x2 -7x + 12 = 0]

Universal quantifier: ∀: statement is true for all values of variable


Existential quantifier: ∃ : statement is true for some value of variable

In (∀x)[p(x) & q(y)] x is bound by the quantifier; y is not.


Both are in the scope of the quantifier.
We’ll only use variables that are bound by a quantifier.
The quantifier tells how the variable is being used.

Relation between A and E:


~(∀x) p(x) ⇔ (∃x)~p(x) Negation can be moved inside
(∀x) p(x) ⇔ (∀y) p(y) The variable doesn’t matter
(∀x)[p(x)] ∧ Q ⇔ (∀x)[p(x) & Q] No harm scoping over what
where no x in Q doesn’t involve the variable
28
Graphs
 A graph G is a pair of sets (V, E), where V is a
set of vertices and E is a set of edges, and a
relation R which defines a mapping between V
and E.
 If G is a nondirected graph then the elements
of E are unordered pairs of vertices.
 We say that an edge {u,v} joins the vertices u
and v.
 Order does not matter, so edge {u,v} is the same
as {v,u}.
29
Preamble
Undirected Graphs
 A simple graph (V,E) consists of a non-empty set vertices,
V, and a set edges, E, connecting distinct elements of V.
– no arrows
– no loops
– can't have multiple edges joining vertices

Example:
A B

D C
30
 Write the previous graph as a symmetric
binary matrix.
A B
A B C D
A
B D C
C
D

31
Directed Graphs
 Directed graph (V, E) - single directed edges between vertices
A B

D C

 Directed multigraph - multiple directed edges between vertices

32
Directed Graphs
 Directed graph (V, E) - single directed edges between vertices
A B
A B C D
A
B D C
C
D

33
 If G is a directed graph or digraph then the
elements of E are ordered pairs of vertices, i.e.
E is a subset of V × V .
 Therefore, the edge (u,v) is not the same as
(v,u) unless u = v.
 An edge is said to be from u to v.
 An edge that joins a vertex to itself is called a
self-loop or loop

34
Nondirected Graph Directed Graph
V = {v1, v2, v3, v4} V = {v1, v2, v3, v4}
E = { {v1, v2},{v1, v3}, E = {{v1, v3},{v3, v4},
{v2, v3},{v3, v4}} {v4, v3},{v4, v2}}

v1 v2 v1 v2

v3 v4

v4 v3

You might also like