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

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

More Set Definitions and Proofs 1.6, 1.7. Ordered n-tuple The ordered n-tuple (a1,a2,…an) is the ordered collection that has a1 as its first element,
Comp 122, Spring 2004 Greedy Algorithms. greedy - 2 Lin / Devi Comp 122, Fall 2003 Overview  Like dynamic programming, used to solve optimization problems.
Greedy Algorithms Greed is good. (Some of the time)
Greed is good. (Some of the time)
Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
Instructor: Hayk Melikya
Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
Week 21 Basic Set Theory A set is a collection of elements. Use capital letters, A, B, C to denotes sets and small letters a 1, a 2, … to denote the elements.
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
SET.   A set is a collection of elements.   Sets are usually denoted by capital letters A, B, Ω, etc.   Elements are usually denoted by lower case.
Sets 1.
Sets 1.
Costas Busch - RPI1 Mathematical Preliminaries. Costas Busch - RPI2 Mathematical Preliminaries Sets Functions Relations Graphs Proof Techniques.
Courtesy Costas Busch - RPI1 Mathematical Preliminaries.
Minimum Spanning Trees. Subgraph A graph G is a subgraph of graph H if –The vertices of G are a subset of the vertices of H, and –The edges of G are a.
SETS A set B is a collection of objects such that for every object X in the universe the statement: “X is a member of B” Is a proposition.
Mathematics.
Discrete Maths Objective to re-introduce basic set ideas, set operations, set identities , Semester 2, Set Basics 1.
TECH Computer Science Graph Optimization Problems and Greedy Algorithms Greedy Algorithms  // Make the best choice now! Optimization Problems  Minimizing.
Set theory Sets: Powerful tool in computer science to solve real world problems. A set is a collection of distinct objects called elements. Traditionally,
2.1 – Sets. Examples: Set-Builder Notation Using Set-Builder Notation to Make Domains Explicit Examples.
Analysis of Algorithms
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Set, Combinatorics, Probability & Number Theory Mathematical Structures for Computer Science Chapter 3 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Set,
Sets Defined A set is an object defined as a collection of other distinct objects, known as elements of the set The elements of a set can be anything:
Mathematical Preliminaries. Sets Functions Relations Graphs Proof Techniques.
CS 103 Discrete Structures Lecture 10 Basic Structures: Sets (1)
Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Copyright  The McGraw-Hill Companies, Inc. Permission required for reproduction.
1.4 Sets Definition 1. A set is a group of objects . The objects in a set are called the elements, or members, of the set. Example 2 The set of positive.
Lecture 19 Greedy Algorithms Minimum Spanning Tree Problem.
Discrete Structure Sets. 2 Set Theory Set: Collection of objects (“elements”) a  A “a is an element of A” “a is a member of A” a  A “a is not an element.
CS201: Data Structures and Discrete Mathematics I
Chapter 2: Basic Structures: Sets, Functions, Sequences, and Sums (1)
CompSci 102 Discrete Math for Computer Science
ELEMENTARY SET THEORY.
Chapter SETS DEFINITION OF SET METHODS FOR SPECIFYING SET SUBSETS VENN DIAGRAM SET IDENTITIES SET OPERATIONS.
Fall 2008/2009 I. Arwa Linjawi & I. Asma’a Ashenkity 11 Basic Structure : Sets, Functions, Sequences, and Sums Sets Operations.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Sets.
Chapter 2 With Question/Answer Animations. Section 2.1.
Introduction to Set theory. Ways of Describing Sets.
Discrete Mathematics SETS. What is a set? ^A set is a unordered collection of “objects”  People in a class: {A yşe, B arış, C anan }  Cities in Turkey.
Discrete Mathematics Set.
1 Mathematical Preliminaries. 2 Sets Functions Relations Graphs Proof Techniques.
Lecture 19 Minimal Spanning Trees CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
Module #3 - Sets 3/2/2016(c) , Michael P. Frank 2. Sets and Set Operations.
Fr: Discrete Mathematics by Washburn, Marlowe, and Ryan.
Discrete Mathematics CS 2610 August 31, Agenda Set Theory Set Builder Notation Universal Set Power Set and Cardinality Set Operations Set Identities.
Theory of Computing Topics Formal languages automata computability and related matters Purposes To know the foundations and principles of computer science.
Theory of Computing Topics Formal languages automata computability and related matters Purposes To know the foundations and principles of computer science.
Thinking Mathematically Venn Diagrams and Set Operations.
Chapter 2 1. Chapter Summary Sets (This Slide) The Language of Sets - Sec 2.1 – Lecture 8 Set Operations and Set Identities - Sec 2.2 – Lecture 9 Functions.
Introduction to Set Theory (§1.6) A set is a new type of structure, representing an unordered collection (group, plurality) of zero or more distinct (different)
CPCS 222 Discrete Structures I
Section 6.1 Set and Set Operations. Set: A set is a collection of objects/elements. Ex. A = {w, a, r, d} Sets are often named with capital letters. Order.
Sets, Permutations, and Combinations. Lecture 4-1: Sets Sets: Powerful tool in computer science to solve real world problems. A set is a collection of.
CHAPTER 3 SETS, BOOLEAN ALGEBRA & LOGIC CIRCUITS
CSNB 143 Discrete Mathematical Structures
Greedy function greedy { S <- S0 //Initialization
Set, Combinatorics, Probability & Number Theory
Sets Section 2.1.
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 2 Sets Slides are adopted from “Discrete.
Exercises Show that (P  Q)  (P)  (Q)
CS100: Discrete structures
Set Operations Section 2.2.
Autumn 2015 Lecture 11 Minimum Spanning Trees (Part II)
Discrete Mathematics CS 2610
Discrete Mathematics R. Johnsonbaugh
CSC102 - Discrete Structures (Discrete Mathematics) Set Operations
Presentation transcript:

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

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

Notation and Terms –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

Notation and Terms –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)

Notation and Terms –Power Set (  (S) ) |  (S)| = _________ where n = |S| Note: the empty set is a subset of every set –Venn Diagrams

Set Operations –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

Set Operations What can you conclude about the sets A & B if… 1.A – B = B – A 2.A  B = A 3.A  S =  4.A  B = A 5.(A  B) = B

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

Practice Problems Mathematical Structures for Computer Science Pg. 202 # 10, 12, 18, 19, 20, 23, 30, 38, 39, 40, 50, 51, 55, 58, 62, 66, 69

Application: Minimal Spanning Trees 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

Application: Minimal Spanning Trees AB CD E AB CD E AB CD E

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

Application: Minimal Spanning Trees AB CD E AB CD E AB CD E AB CD E AB CD E

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 AB CD E AB CD E AB CD E AB CD E AB CD E AB CD E AB CD E

AB CD EF

Greedy Algorithms Arrives at a solution by making a sequence of choices, each of which looks the best at the moment Hope that globally optimal solution will be obtained from locally optimal choices Prim’s & Kruskal’s Algorithms –Always pick the minimal weight edge to add to the set of edges Ncoins problem –Always pick the largest coin available –Does this always work?

Greedy Algorithms Not every greedy algorithm produces optimal solution Must prove that a greedy algorithm produces optimal solution to a problem in order to use it Proof for Prim’s algorithm see pg 149.

Greedy Algorithms Basic approach to greedy algorithms: –Start with { } –Add items to the set in sequence as follows: Selection: choose the next item according to a greedy criterion Feasibility: determine if the new set is feasible – can it lead to a solution? Solution: is the new set a solution? –Stop when the set represents a solution

Greedy Algorithms – more practice Foundations of Algorithms Chapter 4 Practice Problems: Pg. 181 # 1, 2, 5, 6, 9, 43, 44

Application: Set Representation –How can we effectively represent sets in a computer? –Solution I : Store as a collection of distinct items Tends to be 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