ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 6 – September 6 th, 2001.

Slides:



Advertisements
Similar presentations
Sets and its element A set is a collection of well-defined and well-distinguished objects. The objects that make up a set are called the members or elements.
Advertisements

Lecture 2 Introduction To Sets CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
Linear System of Equations MGT 4850 Spring 2008 University of Lethbridge.
Analytical Methods in CS (CIS 505)
Set Notation.
This section will discuss the symbolism and concepts of set theory
Set Theory. What is a set?  Sets are used to define the concepts of relations and functions. The study of geometry, sequences, probability, etc. requires.
ICOM 4035 – Data Structures Lecture 5 – List ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 – Relational Model.
Set, Combinatorics, Probability & Number Theory Mathematical Structures for Computer Science Chapter 3 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Set,
Sets --- A set is a collection of objects. Sets are denoted by A, B, C, … --- The objects in the set are called the elements of the set. The elements are.
SET THEORY. BASIC CONCEPTS IN SET THEORY Definition: A set is a collection of well-defined objects, called elements Examples: The following are examples.
CS 103 Discrete Structures Lecture 10 Basic Structures: Sets (1)
Chapter 7 Logic, Sets, and Counting Section 2 Sets.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 4 – August 30, 2001.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 9 – September 18, 2001.
ICOM 4035 – Data Structures Lecture 3 – Bag ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel.
CS201: Data Structures and Discrete Mathematics I
ICOM 4035 – Data Structures Lecture 7 – Linked Lists Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez.
CompSci 102 Discrete Math for Computer Science
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 3 – August 28, 2001.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com ICOM 5016 – Introduction.
Section 2.1. Section Summary Definition of sets Describing Sets Roster Method Set-Builder Notation Some Important Sets in Mathematics Empty Set and Universal.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 10 – September 20, 2001.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department.
Sets Digital Lesson. Copyright © by Houghton Mifflin Company, Inc. All rights reserved. 2 Definition of Set A set is a collection of objects called elements.
ELEMENTARY SET THEORY.
Set theory Neha Barve Lecturer Bioinformatics
Module Code MA1032N: Logic Lecture for Week Autumn.
SAT MATH Lesson 10.
Sets 2/10/121. What is a Set? Informally, a collection of objects, determined by its members, treated as a single mathematical object Not a real definition:
ICOM 4035 – Data Structures Lecture 4 – Set ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel.
Chapter 2 With Question/Answer Animations. Section 2.1.
Rosen 1.6, 1.7. Basic Definitions Set - Collection of objects, usually denoted by capital letter Member, element - Object in a set, usually denoted by.
(CSC 102) Lecture 13 Discrete Structures. Previous Lectures Summary  Direct Proof  Indirect Proof  Proof by Contradiction  Proof by Contra positive.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 5 – September 4 th,
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com ICOM 5016 – Introduction.
Basic Definitions of Set Theory Lecture 23 Section 5.1 Wed, Mar 8, 2006.
Unit :1 Set Theory Prof. A.J. SHAKADWIPI. Sets and Subsets A well-defined collection of objects. finite sets, infinite sets, subset A={1,3,5,7,9} B={x|x.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department.
1 Section 1.2 Sets A set is a collection of things. If S is a set and x is a member or element of S we write x  S. Othewise we write x  S. The set with.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 5 – September 4 th, 2001.
Basic Definitions of Set Theory Lecture 23 Section 5.1 Mon, Feb 21, 2005.
Module #3 - Sets 3/2/2016(c) , Michael P. Frank 2. Sets and Set Operations.
Notions & Notations (2) - 1ICOM 4075 (Spring 2010) UPRM Department of Electrical and Computer Engineering University of Puerto Rico at Mayagüez Spring.
MATH 2311 Section 2.2. Sets and Venn Diagrams A set is a collection of objects. Two sets are equal if they contain the same elements. Set A is a subset.
Chapter 7 Sets and Probability Section 7.1 Sets What is a Set? A set is a well-defined collection of objects in which it is possible to determine whether.
Discrete Mathematics CS 2610 August 31, Agenda Set Theory Set Builder Notation Universal Set Power Set and Cardinality Set Operations Set Identities.
Section 2.1. Sets A set is an unordered collection of objects. the students in this class the chairs in this room The objects in a set are called the.
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.
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.
Sets Page 746.
Set Definition: A set is unordered collection of objects.
Lecture 04 Set Theory Profs. Koike and Yukita
Set, Combinatorics, Probability & Number Theory
Sets Section 2.1.
CS100: Discrete structures
Algebra 1 Section 1.1.
Session – 2 SETS & Operations of SETS
Set-Builder Notation.
Discrete Mathematics CS 2610
The aim of education is to teach students how to think rather than what to think. Sets The set is the fundamental discrete structure on which all other.
Chapter 7 Logic, Sets, and Counting
ICOM 5016 – Introduction to Database Systems
Lecture Sets 2.2 Set Operations.
ICOM 5016 – Introduction to Database Systems
Terminology and Symbols
Presentation transcript:

ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 6 – September 6 th, 2001

ICOM 4035Dr. Manuel Rodriguez Martinez2 Readings Read Handout about Container Classes –Available from Engineering Reproduction Center as ICOM-4035-Manual # 2

ICOM 4035Dr. Manuel Rodriguez Martinez3 Bag Class Container Bag (Multi-set) is data structure used to store elements with the following semantics: –Copies of the same element can stored in the bag B. –A find operation is supported to determine if an element x is present in the bag B. –A count operation is supported to determine the number of instances of element x in the bag B. –An erase operation is supported to erase an instance of an element x in the bag B. –An erase all operation is supported to erase all instances of an element x in the bag B –A union operation is supported to concatenate the contents of two bags. Bags are used to keep track of things in which copies are allowed –Movies in a video store, letters in a name, names is class room

ICOM 4035Dr. Manuel Rodriguez Martinez4 Bag Class Conceptual Example Bag of integers Unused part Operation: B.count(8) = 1 B.count(5) = 2 B.count(7) = 0 Next free position is bag size

ICOM 4035Dr. Manuel Rodriguez Martinez5 Using the Bag bag b1(10) b.insert(10); 10 b1.insert(4); … … … 4 10 …4 b1.find(2) returns false 10 … b1.erase(4) 10 … b1.count(10) returns 1

ICOM 4035Dr. Manuel Rodriguez Martinez6 Bag Class Design … bag_size bag_capacity bag_elemsBag class Wait a minute!!! We can use vector for this! add more semantics to implement: find() count() insert() erase()

ICOM 4035Dr. Manuel Rodriguez Martinez7 Bag Class Methods Constructor –Make an empty bag –Make a bag from another bag (copy constructor) Accessor –Get current size –Get current capacity –Find an element –Get the count of an element Mutators –Insert a new element –Erase one instance of element x –Erase all instances of element x Non-member –Addend all elements from two bags to create a new one.

ICOM 4035Dr. Manuel Rodriguez Martinez8 Constructors and copy methods Constructors initialize the vector stored in the bag Constructor with integer allocates a vector of size N Copy constructor and copy assignment simply call copy assignment operator on local vector using the vector of the argument bag. –Make an independent (deep) copy of the vectors b1 b b1 b2 copy … … …

ICOM 4035Dr. Manuel Rodriguez Martinez9 Simple ones … Methods that are quite trivial –size() – simply calls size method on vector –capacity() – simply class capacity method on vector –Operator << - prints the elements of the bag in the form: { } Methods that are simple but tricky –insert – push back a new element into the vector b.insert(9) … …

ICOM 4035Dr. Manuel Rodriguez Martinez10 Find and count Find simply traverse the vector associated with the bag until it either –Find the element and returns true –Reaches the end of section in use (position size – 1) and returns false Ex: b.find(9) returns true Count traverses the array and counts the number of times it sees the element in question B.count(3) returns … …

ICOM 4035Dr. Manuel Rodriguez Martinez11 More complex operators –Operator += - make a push back of all elements in the vector of the argument bag –Erase replaces the target element with the element at last used position and shrinks the vector size by … b2 … … b1b1+=b2; … 33 9 … b1 b1.erase(2)

ICOM 4035Dr. Manuel Rodriguez Martinez12 Final ones Erase All simply calls erase until all copies of the element are delete Operator + is declared as non-meber. It creates a new bag with all elements of the two argument bags. –Implemented using copy constructor and += operator … b2 … … b1 b3 = b1+ b2;

ICOM 4035Dr. Manuel Rodriguez Martinez13 Set Class Container Set is data structure used to store elements with the following semantics: –Only one copy of an element can be stored in the set S. –A find operation is supported to determine if an element x is present in the set S. –An erase operation is supported to erase an element x from the set S. –The following set operations are supported: Union – elements that appear in at least one of two sets Intersection – elements that are common to two sets Difference – elements that appear in the first set but no in the second one. Sub-set – determines is a set A is a subset of another set B. Sets are used in application in which copies are not allowed: –Clients in a video store, holydays in a month, social security #

ICOM 4035Dr. Manuel Rodriguez Martinez14 On the Theory of Sets A set S is a collection of objects, where there are no duplicates –Examples A = {a, b, c} B = {0, 2, 4, 6, 8} C = {Jose, Pedro, Ana, Luis} The objects that are part of a set S are called the elements of the set. –Notation: 0 is an element of set B is written as 0  B. 3 is not an element of set B is written as 3  B.

ICOM 4035Dr. Manuel Rodriguez Martinez15 Cardinality of Sets Sets might have –0 elements – called the empty set . –1 elements – called a singleton –N elements – a set of N elements (called a finite set) Ex: S = {car, plane, bike} –  elements – an infinite number of elements (called infinite set) Integers, Real, Even numbers: E = {0, 2, 4, 6, 8, 10, …} –Dot notation means infinite number of elements The cardinality of a set is its number of elements –Notation: cardinality of S is denoted by |S| –Could be an integer number or infinity symbol .

ICOM 4035Dr. Manuel Rodriguez Martinez16 Cardinality of Sets (cont.) Some examples: –A = {a,b,c} |A| = 3 –R – set of real numbers |R| =  –E = {0, 2, 3, 4, 6, 8, 10, …} |E| =  –  the empty set |  | = 0

ICOM 4035Dr. Manuel Rodriguez Martinez17 Set notations and equality of Sets Enumeration of elements of set S –A = {a,b c} –E = {0, 2, 4, 6, 8, 10, …} Enumeration of the properties of the elements in S –E = {x : x is an even integer} –E = {x: x  I and x/2=0, where I is the set of integers.} Two sets are said to be equal if and if only they both have the same elements –A = {a, b, c}, B = {a, b, c}, then A = B –if C = {a, b, c, d}, then A  C Because d  A

ICOM 4035Dr. Manuel Rodriguez Martinez18 Sets and Subsets Let A and B be two sets. B is said to be a subsets of A if and only if every member x of B is also a member of A –Notation: B  A –Examples: A = {1, 2, 3, 4, 5, 6}, B = {1, 2}, then B  A D = {a, e, i, o, u}, F = {a, e, i, o, u}, then F  D –If B is a subset of A, and B  A, then we call B a proper subset Notation: B  A A = {1, 2, 3, 4, 5, 6}, B = {1, 2}, then B  A –The empty set  is a subset of every set, including itself   A, for every set A –If B is not a subset of A, then we write B  A

ICOM 4035Dr. Manuel Rodriguez Martinez19 Set Union Let A and B be two sets. Then, the union of A and B, denoted by A  B is the set of all elements x such that either x  A or x  B. –A  B = {x: x  A or x  B} Examples: –A = {10, 20, 30, 40, 100}, B = {1,2, 10, 20} then A  B = {1, 2, 10, 20, 30, 40, 100} –C = {Tom, Bob, Pete}, then C   = C –For every set A, A  A = A

ICOM 4035Dr. Manuel Rodriguez Martinez20 Set Intersection Let A and B be two sets. Then, the intersection of A and B, denoted by A  B is the set of all elements x such that x  A and x  B. –A  B = {x: x  A and x  B} Examples: –A = {10, 20, 30, 40, 100}, B = {1,2, 10, 20} then A  B = {10, 20} –Y = {red, blue, green, black}, X = {black, white}, then Y  X = {black} –E = {1, 2, 3}, M={a, b} then, E  M =  –C = {Tom, Bob, Pete}, then C   =  For every set A, A  A = A Sets A and B disjoint if and only if A  B =  –They have nothing in common

ICOM 4035Dr. Manuel Rodriguez Martinez21 Set Difference Let A and B be two sets. Then, the difference between A and B, denoted by A - B is the set of all elements x such that x  A and x  B. –A - B = {x: x  A and x  B} Examples: –A = {10, 20, 30, 40, 100}, B = {1,2, 10, 20} then A - B = {30, 40, 100} –Y = {red, blue, green, black}, X = {black, white}, then Y - X = {red, blue, green} –E = {1, 2, 3}, M={a, b} then, E - M = E –C = {Tom, Bob, Pete}, then C -  = C –For every set A, A - A = 