SlideShare a Scribd company logo
SET ADT
Jun Y. Ercia
The Set ADT
Learning Outcomes
At the end of this lesson, students should be able to
• discuss set processing
• define a set abstract data type
• compare set implementations
• demonstrate how a set can be used to solve problems
• write codes for various set implementations
The Set ADT
 a collection of elements.
Properties
1. Elements are drawn from a single universe
2. Each element is either a member of the set or not.
3. Elements may be a set in itself or a primitive
4. No duplicate elements
5. No particular ordering of elements
Examples
o Set of first 5 natural numbers: {1,2,3,4,5}
o {x | x is a positive integer and x < 100}
o {x | x is a driver with > 10 years of driving experience and 0 accidents in the last 3 years}
Operations on a Set
Examples
1. Sets: Articles in Yahoo Science (A), Technology (B), and Sports (C)
o Find all articles on Wright brothers.
o Find all articles dealing with sports medicine
2. Sets: Students in CS10 (A), CS20 (B), and CS40 (C)
o Find all students enrolled in these courses
o Find students registered for CS10 only
o Find students registered for both CS10 and CS20
Uses of Sets in Computing
• Many applications deal with sets
1. Compilers have symbol tables (set of keywords, classes, etc.)
2. Dictionary is a set of words.
3. Routers have sets of forwarding rules.
4. Web servers have set of clients, etc
Implementation of Set ADT
1. Bit-Vector implementation of set
▪ The set is represented by a bit-vector (i.e., an array containing 0’s and 1’s or, equivalently,
true or false) in which the ith bit (cell) is true if i is a member of the set.
▪ Suitable for applications in which the set to be represented is a subset of a small finite
universal set.
0 1 2 3 4 5 6 7 8 9 10
Code for inserting new element into a set
Code for deleting an element from a set
Code for determining whether the set is empty
Code for determining whether the element is a
member of a set
Code for making the set empty
Code for union of two sets
Code for intersection of two sets
Code for difference of two sets
Implementation of Queue ADT
▪ Linked List implementation of Set [SLL]
▪ The entire set is represented by a linked list of nodes.
▪ Suitable for applications in which the set to be
represented does not necessarily have to be a subset of
some finite universal set.
Code for inserting new element into a set
Code for deleting an element from a set
Code for determining whether the set is empty
Code for determining whether the element is a
member of a set
Code for making the set empty
Code for union of two sets
Code for intersection of two sets
Code for difference of two sets
Set Implementation Issue
• Are the elements of the set belongs to a universal set or a subset of some universal set?

More Related Content

Similar to Lesson 5 - Set ADT.pdf

datastructure concepts ppt-190327174340.pptx
datastructure concepts ppt-190327174340.pptxdatastructure concepts ppt-190327174340.pptx
datastructure concepts ppt-190327174340.pptx
JeevaMCSEKIOT
 
Discrete mathematic
Discrete mathematicDiscrete mathematic
Discrete mathematic
Naralaswapna
 
javaarray
javaarrayjavaarray
javaarray
Arjun Shanka
 
Core java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaCore java by a introduction sandesh sharma
Core java by a introduction sandesh sharma
Sandesh Sharma
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
Mohammed Khan
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pd
Nimmi Weeraddana
 
ch11.ppt
ch11.pptch11.ppt
ch11.ppt
kavitamittal18
 
3.ppt
3.ppt3.ppt
3.ppt
3.ppt3.ppt
02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt
Yonas D. Ebren
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
Abhishek Tirkey
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
GauravPandey43518
 
Set Theory, Relations,Functions (Discrete Structures)
Set Theory, Relations,Functions (Discrete Structures)Set Theory, Relations,Functions (Discrete Structures)
Set Theory, Relations,Functions (Discrete Structures)
kimdokja738
 
COMPLEX AND USER DEFINED TYPESPlease note that the material on t.docx
COMPLEX AND USER DEFINED TYPESPlease note that the material on t.docxCOMPLEX AND USER DEFINED TYPESPlease note that the material on t.docx
COMPLEX AND USER DEFINED TYPESPlease note that the material on t.docx
donnajames55
 
Coding Component (50)Weve provided you with an implementation .docx
Coding Component (50)Weve provided you with an implementation .docxCoding Component (50)Weve provided you with an implementation .docx
Coding Component (50)Weve provided you with an implementation .docx
mary772
 
Arrays C#
Arrays C#Arrays C#
Set operations in python (Dutch national flag and count &say problem).pptx
Set operations in python (Dutch national flag and count &say problem).pptxSet operations in python (Dutch national flag and count &say problem).pptx
Set operations in python (Dutch national flag and count &say problem).pptx
murasolimathavi
 
Cso gaddis java_chapter8
Cso gaddis java_chapter8Cso gaddis java_chapter8
Cso gaddis java_chapter8
mlrbrown
 
Computer programming 2 Lesson 13
Computer programming 2  Lesson 13Computer programming 2  Lesson 13
Computer programming 2 Lesson 13
MLG College of Learning, Inc
 
0-Slot18-19-20-ContiguousStorage.pdf
0-Slot18-19-20-ContiguousStorage.pdf0-Slot18-19-20-ContiguousStorage.pdf
0-Slot18-19-20-ContiguousStorage.pdf
ssusere19c741
 

Similar to Lesson 5 - Set ADT.pdf (20)

datastructure concepts ppt-190327174340.pptx
datastructure concepts ppt-190327174340.pptxdatastructure concepts ppt-190327174340.pptx
datastructure concepts ppt-190327174340.pptx
 
Discrete mathematic
Discrete mathematicDiscrete mathematic
Discrete mathematic
 
javaarray
javaarrayjavaarray
javaarray
 
Core java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaCore java by a introduction sandesh sharma
Core java by a introduction sandesh sharma
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pd
 
ch11.ppt
ch11.pptch11.ppt
ch11.ppt
 
3.ppt
3.ppt3.ppt
3.ppt
 
3.ppt
3.ppt3.ppt
3.ppt
 
02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
 
Set Theory, Relations,Functions (Discrete Structures)
Set Theory, Relations,Functions (Discrete Structures)Set Theory, Relations,Functions (Discrete Structures)
Set Theory, Relations,Functions (Discrete Structures)
 
COMPLEX AND USER DEFINED TYPESPlease note that the material on t.docx
COMPLEX AND USER DEFINED TYPESPlease note that the material on t.docxCOMPLEX AND USER DEFINED TYPESPlease note that the material on t.docx
COMPLEX AND USER DEFINED TYPESPlease note that the material on t.docx
 
Coding Component (50)Weve provided you with an implementation .docx
Coding Component (50)Weve provided you with an implementation .docxCoding Component (50)Weve provided you with an implementation .docx
Coding Component (50)Weve provided you with an implementation .docx
 
Arrays C#
Arrays C#Arrays C#
Arrays C#
 
Set operations in python (Dutch national flag and count &say problem).pptx
Set operations in python (Dutch national flag and count &say problem).pptxSet operations in python (Dutch national flag and count &say problem).pptx
Set operations in python (Dutch national flag and count &say problem).pptx
 
Cso gaddis java_chapter8
Cso gaddis java_chapter8Cso gaddis java_chapter8
Cso gaddis java_chapter8
 
Computer programming 2 Lesson 13
Computer programming 2  Lesson 13Computer programming 2  Lesson 13
Computer programming 2 Lesson 13
 
0-Slot18-19-20-ContiguousStorage.pdf
0-Slot18-19-20-ContiguousStorage.pdf0-Slot18-19-20-ContiguousStorage.pdf
0-Slot18-19-20-ContiguousStorage.pdf
 

Recently uploaded

A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptxA Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
OH TEIK BIN
 
Bossa N’ Roll Records by Ismael Vazquez.
Bossa N’ Roll Records by Ismael Vazquez.Bossa N’ Roll Records by Ismael Vazquez.
Bossa N’ Roll Records by Ismael Vazquez.
IsmaelVazquez38
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
deepaannamalai16
 
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
Payaamvohra1
 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
zuzanka
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
RidwanHassanYusuf
 
MDP on air pollution of class 8 year 2024-2025
MDP on air pollution of class 8 year 2024-2025MDP on air pollution of class 8 year 2024-2025
MDP on air pollution of class 8 year 2024-2025
khuleseema60
 
Educational Technology in the Health Sciences
Educational Technology in the Health SciencesEducational Technology in the Health Sciences
Educational Technology in the Health Sciences
Iris Thiele Isip-Tan
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
deepaannamalai16
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
Data Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsxData Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsx
Prof. Dr. K. Adisesha
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
Krassimira Luka
 
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
indexPub
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
Accounting for Restricted Grants When and How To Record Properly
Accounting for Restricted Grants  When and How To Record ProperlyAccounting for Restricted Grants  When and How To Record Properly
Accounting for Restricted Grants When and How To Record Properly
TechSoup
 
220711130088 Sumi Basak Virtual University EPC 3.pptx
220711130088 Sumi Basak Virtual University EPC 3.pptx220711130088 Sumi Basak Virtual University EPC 3.pptx
220711130088 Sumi Basak Virtual University EPC 3.pptx
Kalna College
 
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptxCapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapitolTechU
 
Observational Learning
Observational Learning Observational Learning
Observational Learning
sanamushtaq922
 
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxxSimple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
RandolphRadicy
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
zuzanka
 

Recently uploaded (20)

A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptxA Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
 
Bossa N’ Roll Records by Ismael Vazquez.
Bossa N’ Roll Records by Ismael Vazquez.Bossa N’ Roll Records by Ismael Vazquez.
Bossa N’ Roll Records by Ismael Vazquez.
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
 
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
 
MDP on air pollution of class 8 year 2024-2025
MDP on air pollution of class 8 year 2024-2025MDP on air pollution of class 8 year 2024-2025
MDP on air pollution of class 8 year 2024-2025
 
Educational Technology in the Health Sciences
Educational Technology in the Health SciencesEducational Technology in the Health Sciences
Educational Technology in the Health Sciences
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
Data Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsxData Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsx
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
 
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
Accounting for Restricted Grants When and How To Record Properly
Accounting for Restricted Grants  When and How To Record ProperlyAccounting for Restricted Grants  When and How To Record Properly
Accounting for Restricted Grants When and How To Record Properly
 
220711130088 Sumi Basak Virtual University EPC 3.pptx
220711130088 Sumi Basak Virtual University EPC 3.pptx220711130088 Sumi Basak Virtual University EPC 3.pptx
220711130088 Sumi Basak Virtual University EPC 3.pptx
 
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptxCapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
 
Observational Learning
Observational Learning Observational Learning
Observational Learning
 
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxxSimple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
 

Lesson 5 - Set ADT.pdf

  • 2. The Set ADT Learning Outcomes At the end of this lesson, students should be able to • discuss set processing • define a set abstract data type • compare set implementations • demonstrate how a set can be used to solve problems • write codes for various set implementations
  • 3. The Set ADT  a collection of elements. Properties 1. Elements are drawn from a single universe 2. Each element is either a member of the set or not. 3. Elements may be a set in itself or a primitive 4. No duplicate elements 5. No particular ordering of elements Examples o Set of first 5 natural numbers: {1,2,3,4,5} o {x | x is a positive integer and x < 100} o {x | x is a driver with > 10 years of driving experience and 0 accidents in the last 3 years}
  • 5. Examples 1. Sets: Articles in Yahoo Science (A), Technology (B), and Sports (C) o Find all articles on Wright brothers. o Find all articles dealing with sports medicine 2. Sets: Students in CS10 (A), CS20 (B), and CS40 (C) o Find all students enrolled in these courses o Find students registered for CS10 only o Find students registered for both CS10 and CS20
  • 6. Uses of Sets in Computing • Many applications deal with sets 1. Compilers have symbol tables (set of keywords, classes, etc.) 2. Dictionary is a set of words. 3. Routers have sets of forwarding rules. 4. Web servers have set of clients, etc
  • 7. Implementation of Set ADT 1. Bit-Vector implementation of set ▪ The set is represented by a bit-vector (i.e., an array containing 0’s and 1’s or, equivalently, true or false) in which the ith bit (cell) is true if i is a member of the set. ▪ Suitable for applications in which the set to be represented is a subset of a small finite universal set. 0 1 2 3 4 5 6 7 8 9 10
  • 8. Code for inserting new element into a set
  • 9. Code for deleting an element from a set
  • 10. Code for determining whether the set is empty
  • 11. Code for determining whether the element is a member of a set
  • 12. Code for making the set empty
  • 13. Code for union of two sets
  • 14. Code for intersection of two sets
  • 15. Code for difference of two sets
  • 16. Implementation of Queue ADT ▪ Linked List implementation of Set [SLL] ▪ The entire set is represented by a linked list of nodes. ▪ Suitable for applications in which the set to be represented does not necessarily have to be a subset of some finite universal set.
  • 17. Code for inserting new element into a set
  • 18. Code for deleting an element from a set
  • 19. Code for determining whether the set is empty
  • 20. Code for determining whether the element is a member of a set
  • 21. Code for making the set empty
  • 22. Code for union of two sets
  • 23. Code for intersection of two sets
  • 24. Code for difference of two sets
  • 25. Set Implementation Issue • Are the elements of the set belongs to a universal set or a subset of some universal set?