Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Sets.

Similar presentations


Presentation on theme: "Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Sets."— Presentation transcript:

1 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Sets

2 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction –Sets are an important mathematical data structure Naturally occurring Theoretically described Powerful notation –Definition An unordered collection of distinct objects that share one or more common property –Unordered means no inherent order –Distinct means there are no duplicate member  x[(x  S  P(x))  (P(x)  x  S)] Element of

3 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Notation and Terms (1) –Sets are denoted with capital letters –Curley brackets are also used {a,b,c} –Empty Set denoted by  or {} not the same as {  } –Finite sets can be defined by enumerating the elements of the set –Infinite sets require definition of defining property { x | P(x) } Example: { x | x  n  x  10 } Such that set of all nonnegative integers

4 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Notation and Terms (2) –Other Commonly Used Sets Z : set of all integers Q : set of all rational numbers R : set of all real numbers C : set of all complex numbers Z + : set of all positive integers –Subset (A  B)  x (x  A  x  B) A  B proper subset –  x (x  A  x  B)   x(x  B  x  A) –Equal Sets (A = B)  x [(x  A  x  B)  (x  B  x  A)] (A  B)  (B  A)

5 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Notation and Terms (3) –Power Set (  (S) ) |  (S)| = 2 n where n = |S| Note: the empty set is a subset of every set –Venn Diagrams

6 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Set Operations (1) –Union (A  B) {x | x  A  x  B} –Intersection (A  B) {x | x  A  x  B} –Complement (A) For a set A   (S), A is {x | x  S  x  A} –Set Difference (A – B) { x | x  A  x  B } –Cartesian Product (A  B) {(x,y) | x  A  y  B} Ordered pair

7 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Set Identities IdentityName A   = A A  U = A Identity Laws A  U = U A   =  Domination Laws A  A = A A  A = A Idempotent Laws (A) = A Complementation Laws A  B = B  A A  B = B  A Commutative Laws A  (B  C) = (A  B)  C A  (B  C) = (A  B)  C Associative Laws A  (B  C) = (A  B)  (A  C) A  (B  C) = (A  B)  (A  C) Distributive Laws (A  B) = A  B (A  B) = A  B De Morgan’s Laws A  (A  B) = A A  (A  B) = A Absorption Laws A  A = U A  A =  Complement Laws

8 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Application: Minimal Spanning Trees (1) A tree is nothing more than an undirected graph without cycles A spanning tree is a tree that contains all the vertices in the graph There can be many such spanning trees and we usually want to find the optimal (minimal) weighted one –Thus, this is an optimization problem

9 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Application: Minimal Spanning Trees (2) MST AB CD E AB CD E AB CD E

10 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Application: Minimal Spanning Trees (3) PRIM’s Algorithm Given a set of vertices, V, and a set of edges, E Start with an empty set of edges, F, and a set of vertices, Y, initialized to contain an arbitrary vertex, say ‘a’ At each step find the minimum weight edge, where one end is from (V-Y) and the other from Y –Add this edge to F –Add the vertex from the edge not in Y to the set Y The problem is solved when Y = V

11 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Application: Minimal Spanning Trees (4) AB CD E AB CD E AB CD E AB CD E AB CD E

12 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. KRUSKAL’s Algorithm Given a set of vertices, V, and a set of edges, E Start by creating disjoint subsets of V, one for each vertex, containing only that vertex Look at each edge in turn, from minimal weight to maximum weight If the edge connects two vertices in disjoint subsets then the edge is added to the MST and the two disjoint subsets are merged Otherwise we throw away the edge and leave the subsets alone Stop when we only have 1 disjoint subset or we run out of edges to consider Application: Minimal Spanning Trees (5)

13 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Application: Minimal Spanning Trees (6) AB CD E AB CD E AB CD E AB CD E AB CD E AB CD E AB CD E

14 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Application: Market Basket Analysis (1) –Who cares? –Sets are a natural and powerful way to describe the algorithmic solution to many problems –Market Basket Analysis: the use of association techniques to find groups of items that tend to occur together in transactions frequent item sets –sets of items that occur above some minimum threshold (called the minimum support) –example: {a,b,c,d} occurs 12 times (min. support == 10) association rules –a,b,c  d iff support({a,b,c,d}) / support({a,b,c})  r (called minimum confidence) –a,b  c,d iff support({a,b}) / support({c,d})  r –how many such rules are there? –Suggestive Sell When the client selects the antecedent items suggest that they select the consequent items

15 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Application: Market Basket Analysis (2) –Apriori Algorithm (Agrawal et al., 1993) Let I = {a,b,c,…} be a set of all items in the domain Let T = { S | S  I } be a bag of all transaction records of item sets Let support(S) =  {A | A  T  S  A} | Let L 1 = { {a} | a  I  support({a})  minSupport }  k (k > 1  L k-1   ) Let L k = { S i  S j | (S i  L k-1 )  (S j  L k-1 )  ( |S i – S j | = 1 )  ( |S j – S i | = 1)  (  S[ ((S  S i  S j )  (|S| = k-1))  S  L k-1 ] )  ( support(S i  S j )  minSupport ) Then, the set of all frequent item sets is given by L = L k and the set of all association rules is given by R = { A  C | A   (L k )  (C = L k – A)  (A   )  (C   ) support(L k ) / support(A)  minConfidence } Filter

16 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Application: Market Basket Analysis (3) –Example: minSupport = 2 I= {Table Saw, Router, Kreg Jig, Sander, Drill Press} T= {{Table Saw, Router, Drill Press}, { Router, Sander }, { Router, Kreg Jig }, {Table Saw, Router,, Sander }, {Table Saw,, Kreg Jig }, { Router, Kreg Jig }, {Table Saw,, Kreg Jig }, {Table Saw, Router, Kreg Jig,, Drill Press}, {Table Saw, Router, Kreg Jig }} L 1 = { {T}, {R}, {K}, {S}, {D} } L 2 = { {R,T}, {K,T}, {D,T}, {K,R}, {R,S}, {D,R} } L 3 = { {K,R,T}, {D,R,T} } L 4 =  Rules = ???? Each item set has unique “id”

17 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Application: Set Representation –How can we effectively represent sets in a computer? –Solution I : Store as a collection of distinct items Inefficient since set operations will then require massive amounts of searching –Solution II: Store in some arbitrary but well defined order Let U be the universal set (assume finite & reasonable size) Order U, for instance, a 1, a 2, …, a 3 Represent A  U as a bit string of length n where the ith bit in the string is 1 if a i  A and 0 if a i  A. Intersection reduces to  Union reduces to  Compliment reduces to  Inefficient in terms of subset repetition –Solution III: Left to CS 265


Download ppt "Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Sets."

Similar presentations


Ads by Google