3. A set is a collection of elements SETS We write 1 is a member (or element) of set A ship is not a member (or element) of set B Membership of a given set
14. Powersets A powerset is a set of subsets Powerset of S = the set of all the subsets of S S = { a, b, c } 2 S = { , {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c} } Observation: | 2 S | = 2 |S| ( 8 = 2 3 )
15. Cartesian Product A = { 2, 4 } B = { 2, 3, 5 } A X B = { (2, 2), (2, 3), (2, 5), ( 4, 2), (4, 3), (4, 5) } A X B is an ordered set, i.e. A X B ≠ B X A |A X B| = |A|·|B| Generalizes to more than two sets A X B X … X Z
16.
17. FUNCTIONS domain 1 2 3 a b c range f : A -> B A B If A = domain then f is a total function otherwise f is a partial function f(1) = a 4 5 In general, we mean this.
20. Walk Walk is a sequence of adjacent edges (e, d), (d, c), (c, a) is a walk from e to a of length 3 (or denoted as e-d-c-a ) Length = # of edges a b c d e
21. Path a b c d e Path is a walk where no edge is repeated Simple path : no node is repeated
22. Path a b c d e Path is a walk where no edge is repeated Simple path : no node is repeated (e, b), (b, e), (e, d), (d, c), (c, a) is a path from e to a but it is not a simple path.
23. Cycle a b c d e 1 2 3 Cycle : a walk from a node (base) to itself without repeated edges Simple cycle : only the base node is repeated Loop: an edge from a node to itself base
24. Find All Simple Paths starting from c a b c d e origin The longest simple path has at most length 4. Since every vertex can only be visited at most once, and there are 4 other vertices.
25. (c, a) (c, e) Step 1 a b c d e origin Starting from vertex c, list all outgoing edges as long as they do not lead to any vertex already used in the path. At this point, we have all paths of length one starting at c . For all vertices a , e reached by c , we list all outgoing edges originating at a or e according the same way we did before.
26. (c, a) (c, a), (a, b) (c, e) (c, e), (e, b) (c, e), (e, d) Step 2 a b c d e origin
27. Step 3 a b c d e origin (c, a) (c, a), (a, b) (c, a), (a, b), (b, e) (c, e) (c, e), (e, b) (c, e), (e, d)
28. Step 4 a b c d e origin (c, a) (c, a), (a, b) (c, a), (a, b), (b, e) (c, a), (a, b), (b, e), (e,d) (c, e) (c, e), (e, b) (c, e), (e, d)
29. Trees are connected directed graphs without cycles such that there is a special vertex called “root” having exactly one path to every other vertices. root leaf parent child
30. root leaf Level 0 Level 1 Level 2 Level 3 Height 3 The level associated with each vertex is the number of edges in the path form the root to the vertex. The height of the tree is the largest level number of any vertex.
31. Binary Trees A binary tree is a tree in which no parent can have more than two children. A binary tree is a tree in which no parent can have more than two children. (p.10) Example 1.5. Prove that a binary tree of height n has at most 2 n leaves.
32.
33.
34.
35. Example Theorem: A binary tree of height n has at most 2 n leaves. (p.10) We want to show: L(n) ≦ 2 n for n = 0, 1, 2,…. Proof by induction: let L(i) be the maximum number of leaves of any subtree at height i
36.
37. Induction Step From Inductive hypothesis: height k k+1 Let’s assume L(i) ≦ 2 i for all i = 0, 1, …, k need to show that L(k + 1) ≦ 2 k+1 0 … L(k) ≦ 2 k
38. L(k) ≦ 2 k L(k+1) ≦ 2 · L(k) ≦ 2· 2 k = 2 k+1 Induction Step height k k+1 (we add at most two nodes for every leaf of level k) … need to show that L(k + 1) ≦ 2 k+1 To get a binary tree of height k+1 from one of height k , we can create at most 2 leaves in place of each previous one
39.
40.
41.
42. = n/m 2 m 2 = n 2 Therefore, n 2 is even n is even n = 2 k 2 m 2 = 4k 2 m 2 = 2k 2 m is even m = 2 p Thus, m and n have a common factor 2 Contradiction!