Presentation is loading. Please wait.

Presentation is loading. Please wait.

MCS680: Foundations Of Computer Science

Similar presentations


Presentation on theme: "MCS680: Foundations Of Computer Science"— Presentation transcript:

1 MCS680: Foundations Of Computer Science
int MSTWeight(int graph[][], int size) { int i,j; int weight = 0; for(i=0; i<size; i++) for(j=0; j<size; j++) weight+= graph[i][j]; return weight; } 1 n O(1) O(n) Running Time = 2O(1) + O(n2) = O(n2) Algorithms and Analysis of Sets Brian Mitchell - Drexel University MCS680-FCS

2 Introduction The set is one of the most fundamental data model in Mathematics and Computer Science Many problems can be reduced to a set representation Many efficient algorithms exist for processing sets Goals Review set definition and basic operations that can be performed on sets Examine and analyze some set algorithms Investigate how some “ordinary” Computer Science problems can be reduced to sets They can then be solved using standard set algorithms Brian Mitchell - Drexel University MCS680-FCS

3 Sets and Set Membership
When S is a set and x is a piece of quantifiable data We need to be able to determine Is x a member of set S Is x not a member of set S Generally all members of a set are related in some way Set Notation The expression x  S means that the element x is a member of set S If x1, x2, ... xn are all members of the set S then we refer to set S as: S = { x1, x2, ... xn } The empty set is denoted as  The empty set is a set with no members Thus for all x, x   is always false Brian Mitchell - Drexel University MCS680-FCS

4 Definition of Sets by Abstraction
Enumerating all of the elements in a given set is not the only way we may define sets The number of elements in the set may be large The elements in the set may be related by some common property Notation for abstraction: {x | x  S and P(x)} This means that all elements x are in the set S if they satisfy property P(x) Examples {x | x  S and x is odd} {A | A  T and A is a set} {x | x  N and x is prime} Common infinite sets N is the set of non-negative integers, Z is the set of all integers, R is the set of real numbers, C is the set of complex numbers Brian Mitchell - Drexel University MCS680-FCS

5 Set Operations Union, Intersection and Difference
Union: S  T A set containing the elements in S or T, or both Intersection: S  T A set containing the the elements that are in both S and T The intersection of two sets includes the elements common to both sets Difference: S - T A set containing those elements that are in S but not in T The set contains the distinct elements that are in S with respect to T Example: Let S = {1, 2, 3}, T = {3, 4, 5} Union: S  T = {1, 2, 3, 4, 5} Intersection: S  T = {3} Difference: S - T = {1, 2} Brian Mitchell - Drexel University MCS680-FCS

6 Venn Diagrams Region 1 Region 2 Region 3 Region 4 S T Venn diagrams are useful for visualizing set operations Region 1 represents those elements that are in neither S or T Region 2 represents S - T Region 3 represents S T Region 4 represents T - S Regions 2, 3 and 4 combined represents S  T Brian Mitchell - Drexel University MCS680-FCS

7 Algebraic Laws For Union, Intersection and Difference
Build up complex expressions using Union, Intersection and Difference Example: R  (( S  T) - U) Need to be able to determine if two expressions are equivalent Important algebraic laws Let the symbol  represent equivalence Commutative Law of Union (S  T)  (T  S) Rationale: The element x is in S  T, if x is in X or if x is in T, or both. That is also the condition where x is in T  S. Associative Law of Union (S  (T  R))  ((S  T)  R) This can be shown by the same argument used to show the commutative law Brian Mitchell - Drexel University MCS680-FCS

8 Algebraic Laws For Union, Intersection and Difference
Commutative Law of Intersection (S  T)  (T  S) Rationale: The element x is in sets S  T and T  S under exactly the same circumstances. Associative Law of Intersection (S  (T  R))  ((S  T)  R) Rationale: The element x must be in all three sets - S, T, and R. However it does not matter if we examine (T  R) or (S  T) first. Distributive law of intersection over union ((T  R)  S)  ((S  T)  (R  S)) Rationale: The element x must be in S and also in at least one of T or R Distributive law of union over intersection ((T  R)  S)  ((S  T)  (R  S)) Brian Mitchell - Drexel University MCS680-FCS

9 Algebraic Laws For Union, Intersection and Difference
Associative Law of Union and Difference (S - (T  R) )  ((S - T) - R) Rationale: Both sides contain an element x when x is in S but in neither T nor R. Associative Law of Intersection ((S  T) - R )  ((S - R)  (T - R)) Rationale: An element x is in either set when it is not in R, but is in either S or T, or both. Empty Set Identity (S  )  S and (  S)  S Rationale: The element x can only be in S, because it can not be in  Idempotence: When an operator is applied to the same value, the result is the same Union: (S  S)  S Intersection: (S  S)  S Brian Mitchell - Drexel University MCS680-FCS

10 The Subset Relationship
If S and T are sets, then we can say that S  T is every member of S that is also a member of T S is a subset of T T is a superset of S S is contained in T T contains S If S and T are sets, then we can say that S  T, if S  T and there is at least one element in S that is not in T S is a proper subset of T T is a proper superset of S S is a properly contained in T T properly contains S Brian Mitchell - Drexel University MCS680-FCS

11 The Power Set of a Set The power set of S, is the set of subsets of S
Notation: Let P(S) represent the power set of S 2S is also used Size of a power set A power set, P(S) has 2n members Example: Let S = {1,2,3} P(S) is: {,{1},{2},{3},{1,2},{1,3},{2,3},{1,2,3}} |P(S)| = 8 = 23 Brian Mitchell - Drexel University MCS680-FCS

12 Cartesian Product Let A and B be two sets
The product of A and B, denoted A x B is defined as the set of pairs in which the first component is chosen from A and the second component from B A x B = {(a,b) | a  A and b  B} This product is known as the Cartesian Product Example: Let A = {1,2} and B = {a,b,c} Thus A x B = {(1,a), (1,b), (1,c), (2,a), (2,b), (2,c)} Size of the Cartesian Product |A x B| = |A| * |B| If A = {1,2} and B = {a,b,c} Then |A| = 2, |B| = 3 and |A x B| = 6 Brian Mitchell - Drexel University MCS680-FCS

13 Binary Relations and Functions
A binary relation R is a set of pairs that is a subset of the product of two sets If a relation R is a subset of A x B, then we say that R is from A to B Remember that A x B  B x A A is the domain of the relation B is the range of the relation Notation: Given a binary relation R on sets A and B where a  A and b  B, we can show this relation as aRb Functions Partial Function: Relation R has the property that for every a  A there is at most one element b B such that satisfies aRb Total Function: Relation R has the property that for every a  A there is at exactly one element b B such that satisfies aRb Brian Mitchell - Drexel University MCS680-FCS

14 Special Properties of Binary Relations
Transitivity Let R be a binary relation. R is transitive whenever aRb and bRc are true, and aRc is also true Reflexivity Let R be a binary relation that for every element a in the domain aRa is true Symmetric Let R be a binary relation. R is symmetric if whenever aRb, we also have bRa Asymmetric Let R be a binary relation. R is asymmetric if whenever aRb, we only have bRa when a=b a a b a never b a Brian Mitchell - Drexel University MCS680-FCS

15 Special Properties of Binary Relations - Examples
Transitivity Consider the relation ‘<‘ on Z, the set of integers. If a < b, and b < c, then it follows that a < c. Consider the relation ‘’ on Z, the set of integers. If a  b, and b  c, then we can not say that a  c. This relation is not transitive Reflexivity The relation ‘’ is reflexive on the set of integers. For all integers a, a  a. Symmetric The relation ‘’ is symmetric on the set of integers. For all integers if a  b, then b  a must be true Asymmetric The relation ‘’ is asymmetric on the set of integers. If a  b, and b  a, then a = b Brian Mitchell - Drexel University MCS680-FCS

16 Partial and Total Orders
Partial Order A partial order is a transitive and antisymmetric binary relation Total Order A total order is a transitive, reflexive and antisymmetric binary relation where every pair of elements in the domain are comparable If R is a total order and if a and b are any two elements in its domain, then either aRb, or bRa is true All total orders must be reflexive because we might allow a and b to be the same element. Example: Partial Orders and Total Orders The relations ‘<‘ and ‘>’ are partial orders but not total orders. They are transitive and asymmetric, but not reflexive (a < a is false). The relations ‘’ and ‘’ are total orders. They are transitive, asymmetric, and reflexive Brian Mitchell - Drexel University MCS680-FCS

17 Closure of a Binary Relation
Closures of binary relations Take a relation that does not have a desired property Transitivity Reflexive Symmetric Asymmetric Add as few pairs as possible to crate a relation that does have the desired property The resultant relation is called the closure (for the desired property) of the original relation Closures are usually used to infer or discover missing information from the relation Brian Mitchell - Drexel University MCS680-FCS


Download ppt "MCS680: Foundations Of Computer Science"

Similar presentations


Ads by Google