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

Slides:



Advertisements
Similar presentations
Learning Objectives for Section 7.2 Sets
Advertisements

Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
2.1 Sets. DEFINITION 1 A set is an unordered collection of objects. DEFINITION 2 The objects in a set are called the elements, or members, of the set.
Reviews for Exam 1 Chapter 1-4 CSc 212 Data Structures, Sec FG CCNY, Fall 2010.
Linear System of Equations MGT 4850 Spring 2008 University of Lethbridge.
Denoting the beginning
1 Section 1.7 Set Operations. 2 Union The union of 2 sets A and B is the set containing elements found either in A, or in B, or in both The denotation.
Analytical Methods in CS (CIS 505)
Reviews for Exam 1 Chapter 1-4 CS 211 Data Structures MHC, 2007.
Sets 1.
Sets 1.
1 Learning Objectives for Section 7.2 Sets After today’s lesson, you should be able to Identify and use set properties and set notation. Perform set operations.
Set Notation.
Review for Midterm Chapter 1-9 CSc 212 Data Structures.
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 Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 6 – September 6 th, 2001.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 – Relational Model.
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.
CS 103 Discrete Structures Lecture 10 Basic Structures: Sets (1)
ICOM 4035 – Data Structures Lecture 1 - Introduction Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez.
Chapter 7 Logic, Sets, and Counting Section 2 Sets.
Copyright © 2014 Curt Hill Sets Introduction to Set Theory.
Chapter 2: Basic Structures: Sets, Functions, Sequences, and Sums (1)
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.
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.
INFIINITE SETS CSC 172 SPRING 2002 LECTURE 23. Cardinality and Counting The cardinality of a set is the number of elements in the set Two sets are equipotent.
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:
COMP 103 Bitsets. 2 Sets, and more Sets!  Unsorted Array  Sorted ArrayO(n) for at least one of  Linked Listcontains, add, remove  Binary Search TreeO(log.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 11 – September 25, 2001.
ICOM 4035 – Data Structures Lecture 4 – Set ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel.
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.
Sets.
1 Chapter Two Basic Concepts of Set Theory –Symbols and Terminology –Venn Diagrams and Subsets.
(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.
Lecture 3 Fuzzy sets. 1.1 Sets Elements of sets An universal set X is defined in the universe of discourse and it includes all possible elements.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 – August 23, 2001.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 5 – September 4 th, 2001.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 7 – Buffer Management.
Basic Definitions of Set Theory Lecture 23 Section 5.1 Mon, Feb 21, 2005.
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.
Discrete Mathematics CS 2610 August 31, Agenda Set Theory Set Builder Notation Universal Set Power Set and Cardinality Set Operations Set Identities.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 10 – September 18,
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.
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.
Set Definition: A set is unordered collection of objects.
CHAPTER 3 SETS, BOOLEAN ALGEBRA & LOGIC CIRCUITS
CSNB 143 Discrete Mathematical Structures
Chapter 1 Logic and Proofs Homework 2 Given the statement “A valid password is necessary for you to log on to the campus server.” Express the statement.
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 2 Sets Slides are adopted from “Discrete.
Algebra 1 Section 1.1.
Session – 2 SETS & Operations of SETS
2.1 Sets Dr. Halimah Alshehri.
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
Terms Set S Set membership x  S Cardinality | S |
ICOM 5016 – Introduction to Database Systems
Lecture Sets 2.2 Set Operations.
ICOM 5016 – Introduction to Database Systems
Presentation transcript:

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

ICOM 4035Dr. Manuel Rodriguez Martinez2 Agenda Project 1 is out: Algebra and Calculus on Polynomials. –Get the source code from class web page. –Due Date: 12:00 PM October 4 Exam1 Date: 3:00PM-4:30PM, September 27, 2001 –Topics: Arrays, structures, pointers, objects, operator overloading, constructor, copy constructors, destructors, copy assignment, vector class, bag class, set class, bitset class, Big-Oh notation. –Coming soon: practice problems & solutions.

ICOM 4035Dr. Manuel Rodriguez Martinez3 Review of bags Trace the execution of the following operations on bag b: bag b(3); b.insert(10); b.insert(-2); b.insert(3); b.find(10); b.find(-1); b.erase(20); b.insert(3); b.erase(-2);

ICOM 4035Dr. Manuel Rodriguez Martinez4 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 Martinez5 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 Martinez6 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 Martinez7 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 Martinez8 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 Martinez9 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 Martinez10 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 Martinez11 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 Martinez12 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 = 

ICOM 4035Dr. Manuel Rodriguez Martinez13 Sample Application with sets Program to keep track of students in courses –Example: ICOM 4035 and ICOM –Operations Add a student to a course Remove a student from a course Report all students in all courses Report all students taking both courses Report students taking one course but not the other. –Use sets to implement object that represent the students in each class. –Use set operations to answer each of these questions

ICOM 4035Dr. Manuel Rodriguez Martinez14 Alternative implementation of sets Allows for faster, constant time search and delete operation on the set. –Implementation for array require looking up all array. Alternative is called bit vector Use an array of unsigned char or unsigned int to represent sets of integers. –Each bit represents a number. –The bit at position k represents integer k. –If k is in the set, then the bit is set to 1, otherwise it is set to 0. Names, places and other objects to which we can assign a number can also be represented this way.

ICOM 4035Dr. Manuel Rodriguez Martinez15 Example: Suppose we have array of size 2 of unsigned char Rightmost position is 0, numbers increase to left –Represents set {2,3,4,8,9,14} –Storage requirements: 2 bytes –Previous implementation would have required at 5 bytes. –In fact, with 2 bytes we can represent up to 16 numbers. Each byte is a segment of the bit vector. To find an element we need to know segment number and its position within segment to locate it –Segment is given by: element / segment size –Position is given by: element % segment size

ICOM 4035Dr. Manuel Rodriguez Martinez16 Example Given 2 byte bit-vector Where is element 1 located? –Segment 0, position 1 Where is element 4 located? –Segment 0, position 4 Where is element 8 located? –Segment 1, position 0 Where is element 10 located? –Segment 1, position 2 Where is element 19 located? –Cannot be represented due to lack of space. –Bit vector n bytes can only represent (n * 8) – 1 elements

ICOM 4035Dr. Manuel Rodriguez Martinez17 Boolean Algebra Needed to inspect bits in the bit vector. Supported operations: AND, OR, XOR Also need bit-wise shift operators that are used to move bits from a position to another. Left shift – move all bits n spots to the left, discarding elements that reach and pass last position. –0101 << 1 = 1010 (shift one) –0101 << 3 = 1000 (shit three) Right shift – move all bits n spots to the right, discarding element that reach and pass first position. –0101 >> 1 = 0010 (shift one) –0101 >> 3 = 0001 (shift three)

ICOM 4035Dr. Manuel Rodriguez Martinez18 AND Operator Expression in C++: A & B Truth Table: Example: & AND A B

ICOM 4035Dr. Manuel Rodriguez Martinez19 OR Operator Expression in C++: A | B Truth Table: Example: | OR A B

ICOM 4035Dr. Manuel Rodriguez Martinez20 XOR Operator Expression A ^ B Truth Table: Example: ^ XOR A B