Set data structure

T
Set data structure
Introduction
• A set is a collection of objects need not to be
  in any particular order.
• It is just applying the mathematical concept in
  computer.
• Rules:
   Elements should not be repeated.
   Each element should have a reason to be in the
    set.
Set example :
   Assume we are going to store Indian
      cricketers in a set.
      * The names should not be repeated, as
  well the name who is not in a team can’t be
  inserted.
      * This is the restriction we found in a set.
NULL SET(EMPTY SET)
• The set with no element is called null set or
  empty set.
For example:
A={x | x is a prime number, where 24<x<29}
      This set can’t contain a element. We don’t
  have any prime number within the limit 24
  and 29.
A={ }
Basic Operations

o set union(set1,set2)
o set intersection(set1,set2)
o set difference(set1,set2)
o int subset(set1,set2)
UNION
• Combine two or more sets(here two sets),
  without violating the rules for set.
INTERSECTION
• Gathering common elements in both the sets
  together as a single set.
DIFFERENCE
• Forming a set with elements which are in first
  set and not in second set.




• A-B= {x| for all x belongs to A but not in B}
SUBSET
• int subset(set1 , set2)
• Returns 1 if the set1 is the subset of the set2.,
  otherwise 0 if not.
• Here, A c B(A contained in B)
Types




Immutable           Mutable

(Static)            (Dynamic)
Operations on Mutable
•   void* create(n)
•   add(set , element);
•   delete(set , element);
•   int capacity(set);
CREATE
• void* create(int n)
  – It simply create the set that can be used to store
    ‘n’ elements and return the starting address of the
    set in memory.

  int *set=create(30);
ADD
• add(set set_name , type value)
  – This function add one element into the set
    specified in the function argument.
  – The set_name argument is to mention the set
    which is going to be updated.
  – value argument is the value to be inserted into
    the set that passed to the function.
DELETE
• delete (set set_name , type value)
  – This function delete one element from the set
    specified in the function argument.
  – The set_name argument is to mention the set
    which is going to be updated.
  – value argument is the value to be deleted from
    the set that passed to the function.
CAPACITY
• int capacity(set set_name)
  – This function is used to find the maximum number
    of elements can be stored into the set that passed
    to the function.
  – Find the count and return the integer value.
Operations on Immutable
•   int elementof(x , S)
•   int empty(S)
•   int size(S)
•   void* build(x1 , x2 , … , xn)
ELEMENTOF
• int elementof(type x , set set_name)
  – This function check for the element ‘x’ in the
    passed set.
  – Returns the value whether 0 or 1.
  – If the X is there in the set, return 1 otherwise 0.
EMPTY
• int empty(set set_name)
  – This function checks for the emptiness of the set
    that passed to the function.
  – If the set is empty, return 1 else 0.
SIZE
• int size(set set_name)
  – Returns the number of elements in set.
BUILD
• void* build(set_elements)
  – This function create the set with the given
    elements and return the address of the first
    element.
  – Return the void* , we can assign that pointer to
    the type* which type we declared the set.
Set data structure
• intersection()
Here, function for set with the type int.
int* intersection(int set1[100],int set2[100])
{
int inter[100],k=0;
for(i=0;i<size(set1);i++)
   for(j=0;j<size(set2);j++)
        if(set1[i]==set2[j])
        {
                inter[k]=set[i];
                k++;
        }
return inter;
}
• union()
int* union(int set1[100],int set2[100])
{
   int uin[100];
   for(i=0;i<size(set1);i++)
   {
         uin[i]=set1[i];
   }
   for(j=0;j<size(set2);j++)
   {
         if(!find(uin,set2[j]))
         {
                  uin[i]=set2[j];
                  i++;
         }
   }
return uin;
}
• elementof()
int elementof(int set[100],int x)
{
  for(i=0;i<size(set1);i++)
  {
      if(set[i]==x)
             return 1;
  }
return 0;
}
Dynamic memory allocation
    Header file for this is <alloc.h>
void* malloc(int size_of_block)
void* calloc(int number_of_blocks, int size_of_each_block)
void free(void* ptr)
realloc(void* ptr, int size)
Set data structure
HASH FUNCTION
• Before entering into an application of set data
  structure, we need to discuss about hash function.
• Hash function is a function that generate an integer
  number with a particular logic.
• This function is like a one way entry. We can’t reverse
  this function. But by doing the process with the same
  number we may get an answer.
• Sometimes the same value may be generated
  for the different values. In that case, we need
  to check for the data in that location.
• In some cases, same values will generate the
  different output. Both are possible.
• We have to select a hash function which is not
  repeating the values generated.
Spelling checker
• Here, is a simple example for spelling checker.
• This concept applied by using the hash table
  data structure.
• The two files are provided to us for process.
  One is “dictionary file”, which is the collection
  of meaningful words, and another one is
  “input file”, that contains the word to be
  validated for spell.
• Initially the words from the dictionary file and
  also from input file be inserted into the hash
  tables separately.
• And the intersection operation will be done
  between the two hash tables.
• If the set with one element is the result of the
  intersection, then the word is in dictionary.
  Spell is perfect. If, null set returned form the
  intersection, then the spell is wrong.
The set data structure is indirectly
implemented using such as trees, tries, hash
tables, arrays, by restricting ourself while
storing data. This is widely used data structure
when we need no repetition as well a
collection.
Set data structure
1 von 32

Recomendados

Set data structure 2 von
Set data structure 2Set data structure 2
Set data structure 2Tech_MX
7K views54 Folien
Python list von
Python listPython list
Python listArchanaBhumkar
1.1K views15 Folien
Python tuple von
Python   tuplePython   tuple
Python tupleMohammed Sikander
12.6K views13 Folien
Queue ppt von
Queue pptQueue ppt
Queue pptSouravKumar328
20.5K views16 Folien
linked list in data structure von
linked list in data structure linked list in data structure
linked list in data structure shameen khan
39.3K views63 Folien
Linked lists von
Linked listsLinked lists
Linked listsSARITHA REDDY
20.8K views37 Folien

Más contenido relacionado

Was ist angesagt?

Circular queue von
Circular queueCircular queue
Circular queueLovely Professional University
9.8K views26 Folien
Binary Search Tree in Data Structure von
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data StructureDharita Chokshi
35.9K views126 Folien
Linear search-and-binary-search von
Linear search-and-binary-searchLinear search-and-binary-search
Linear search-and-binary-searchInternational Islamic University
14.9K views19 Folien
Binary Search von
Binary SearchBinary Search
Binary Searchkunj desai
26.6K views13 Folien
Linked List von
Linked ListLinked List
Linked ListAshim Lamichhane
14.2K views59 Folien
Insertion Sorting von
Insertion SortingInsertion Sorting
Insertion SortingFarihaHabib123
20.3K views89 Folien

Was ist angesagt?(20)

Binary Search Tree in Data Structure von Dharita Chokshi
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
Dharita Chokshi35.9K views
Binary Search von kunj desai
Binary SearchBinary Search
Binary Search
kunj desai26.6K views
Binary search in data structure von Meherul1234
Binary search in data structureBinary search in data structure
Binary search in data structure
Meherul1234758 views
Bubble sort von Manek Ar
Bubble sortBubble sort
Bubble sort
Manek Ar17.5K views
Binary Search Tree in Data Structure von Meghaj Mallick
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
Meghaj Mallick118 views
1.1 binary tree von Krish_ver2
1.1 binary tree1.1 binary tree
1.1 binary tree
Krish_ver218.5K views

Similar a Set data structure

JavaScript.pptx von
JavaScript.pptxJavaScript.pptx
JavaScript.pptxpramod599939
3 views13 Folien
Aj unit2 notesjavadatastructures von
Aj unit2 notesjavadatastructuresAj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructuresArthik Daniel
413 views16 Folien
sets and maps von
 sets and maps sets and maps
sets and mapsRajkattamuri
873 views23 Folien
Java von
JavaJava
JavaAbdulImrankhan7
602 views23 Folien
Python programming -Tuple and Set Data type von
Python programming -Tuple and Set Data typePython programming -Tuple and Set Data type
Python programming -Tuple and Set Data typeMegha V
180 views24 Folien
Required to augment the authors Binary Search Tree (BST) code to .docx von
Required to augment the authors Binary Search Tree (BST) code to .docxRequired to augment the authors Binary Search Tree (BST) code to .docx
Required to augment the authors Binary Search Tree (BST) code to .docxdebishakespeare
3 views20 Folien

Similar a Set data structure (20)

Aj unit2 notesjavadatastructures von Arthik Daniel
Aj unit2 notesjavadatastructuresAj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructures
Arthik Daniel413 views
Python programming -Tuple and Set Data type von Megha V
Python programming -Tuple and Set Data typePython programming -Tuple and Set Data type
Python programming -Tuple and Set Data type
Megha V180 views
Required to augment the authors Binary Search Tree (BST) code to .docx von debishakespeare
Required to augment the authors Binary Search Tree (BST) code to .docxRequired to augment the authors Binary Search Tree (BST) code to .docx
Required to augment the authors Binary Search Tree (BST) code to .docx
debishakespeare3 views
Brixton Library Technology Initiative von Basil Bibi
Brixton Library Technology InitiativeBrixton Library Technology Initiative
Brixton Library Technology Initiative
Basil Bibi238 views
Whiteboarding Coding Challenges in Python von Andrew Ferlitsch
Whiteboarding Coding Challenges in PythonWhiteboarding Coding Challenges in Python
Whiteboarding Coding Challenges in Python
Andrew Ferlitsch1.6K views
C++ STL (quickest way to learn, even for absolute beginners).pptx von GauravPandey43518
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
ArrayList class and useful methods.pptx von Abid523408
ArrayList class and useful methods.pptxArrayList class and useful methods.pptx
ArrayList class and useful methods.pptx
Abid5234087 views
data structures and algorithms Unit 3 von infanciaj
data structures and algorithms Unit 3data structures and algorithms Unit 3
data structures and algorithms Unit 3
infanciaj128 views
Basic data structures in python von Lifna C.S
Basic data structures in pythonBasic data structures in python
Basic data structures in python
Lifna C.S419 views
Python_Sets(1).pptx von rishiabes
Python_Sets(1).pptxPython_Sets(1).pptx
Python_Sets(1).pptx
rishiabes28 views
Java Presentation von mdfkhan625
Java PresentationJava Presentation
Java Presentation
mdfkhan625317 views

Más de Tech_MX

Virtual base class von
Virtual base classVirtual base class
Virtual base classTech_MX
11.8K views13 Folien
Uid von
UidUid
UidTech_MX
10.4K views33 Folien
Theory of estimation von
Theory of estimationTheory of estimation
Theory of estimationTech_MX
45.2K views30 Folien
Templates in C++ von
Templates in C++Templates in C++
Templates in C++Tech_MX
18.2K views21 Folien
String & its application von
String & its applicationString & its application
String & its applicationTech_MX
5.5K views28 Folien
Statistical quality__control_2 von
Statistical  quality__control_2Statistical  quality__control_2
Statistical quality__control_2Tech_MX
2.6K views34 Folien

Más de Tech_MX(20)

Virtual base class von Tech_MX
Virtual base classVirtual base class
Virtual base class
Tech_MX11.8K views
Uid von Tech_MX
UidUid
Uid
Tech_MX10.4K views
Theory of estimation von Tech_MX
Theory of estimationTheory of estimation
Theory of estimation
Tech_MX45.2K views
Templates in C++ von Tech_MX
Templates in C++Templates in C++
Templates in C++
Tech_MX18.2K views
String & its application von Tech_MX
String & its applicationString & its application
String & its application
Tech_MX5.5K views
Statistical quality__control_2 von Tech_MX
Statistical  quality__control_2Statistical  quality__control_2
Statistical quality__control_2
Tech_MX2.6K views
Stack data structure von Tech_MX
Stack data structureStack data structure
Stack data structure
Tech_MX22.7K views
Stack Data Structure & It's Application von Tech_MX
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application
Tech_MX31.1K views
Spss von Tech_MX
SpssSpss
Spss
Tech_MX121.2K views
Spanning trees & applications von Tech_MX
Spanning trees & applicationsSpanning trees & applications
Spanning trees & applications
Tech_MX24.6K views
Real time Operating System von Tech_MX
Real time Operating SystemReal time Operating System
Real time Operating System
Tech_MX106.6K views
Parsing von Tech_MX
ParsingParsing
Parsing
Tech_MX3.7K views
Mouse interrupts (Assembly Language & C) von Tech_MX
Mouse interrupts (Assembly Language & C)Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)
Tech_MX17.3K views
Motherboard of a pc von Tech_MX
Motherboard of a pcMotherboard of a pc
Motherboard of a pc
Tech_MX6.1K views
More on Lex von Tech_MX
More on LexMore on Lex
More on Lex
Tech_MX8K views
MultiMedia dbms von Tech_MX
MultiMedia dbmsMultiMedia dbms
MultiMedia dbms
Tech_MX8.5K views
Merging files (Data Structure) von Tech_MX
Merging files (Data Structure)Merging files (Data Structure)
Merging files (Data Structure)
Tech_MX11.1K views
Memory dbms von Tech_MX
Memory dbmsMemory dbms
Memory dbms
Tech_MX967 views
Linkers von Tech_MX
LinkersLinkers
Linkers
Tech_MX33.2K views
Linear regression von Tech_MX
Linear regressionLinear regression
Linear regression
Tech_MX57.3K views

Último

BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE... von
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...Nguyen Thanh Tu Collection
106 views91 Folien
12.5.23 Poverty and Precarity.pptx von
12.5.23 Poverty and Precarity.pptx12.5.23 Poverty and Precarity.pptx
12.5.23 Poverty and Precarity.pptxmary850239
559 views30 Folien
Gross Anatomy of the Liver von
Gross Anatomy of the LiverGross Anatomy of the Liver
Gross Anatomy of the Liverobaje godwin sunday
100 views12 Folien
Volf work.pdf von
Volf work.pdfVolf work.pdf
Volf work.pdfMariaKenney3
91 views43 Folien
A Guide to Applying for the Wells Mountain Initiative Scholarship 2023 von
A Guide to Applying for the Wells Mountain Initiative Scholarship 2023A Guide to Applying for the Wells Mountain Initiative Scholarship 2023
A Guide to Applying for the Wells Mountain Initiative Scholarship 2023Excellence Foundation for South Sudan
89 views26 Folien
ICS3211_lecture 09_2023.pdf von
ICS3211_lecture 09_2023.pdfICS3211_lecture 09_2023.pdf
ICS3211_lecture 09_2023.pdfVanessa Camilleri
150 views10 Folien

Último(20)

BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE... von Nguyen Thanh Tu Collection
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...
12.5.23 Poverty and Precarity.pptx von mary850239
12.5.23 Poverty and Precarity.pptx12.5.23 Poverty and Precarity.pptx
12.5.23 Poverty and Precarity.pptx
mary850239559 views
The Future of Micro-credentials: Is Small Really Beautiful? von Mark Brown
The Future of Micro-credentials:  Is Small Really Beautiful?The Future of Micro-credentials:  Is Small Really Beautiful?
The Future of Micro-credentials: Is Small Really Beautiful?
Mark Brown121 views
Guess Papers ADC 1, Karachi University von Khalid Aziz
Guess Papers ADC 1, Karachi UniversityGuess Papers ADC 1, Karachi University
Guess Papers ADC 1, Karachi University
Khalid Aziz109 views
ANGULARJS.pdf von ArthyR3
ANGULARJS.pdfANGULARJS.pdf
ANGULARJS.pdf
ArthyR354 views
Career Building in AI - Technologies, Trends and Opportunities von WebStackAcademy
Career Building in AI - Technologies, Trends and OpportunitiesCareer Building in AI - Technologies, Trends and Opportunities
Career Building in AI - Technologies, Trends and Opportunities
WebStackAcademy51 views
Pharmaceutical Analysis PPT (BP 102T) von yakshpharmacy009
Pharmaceutical Analysis PPT (BP 102T) Pharmaceutical Analysis PPT (BP 102T)
Pharmaceutical Analysis PPT (BP 102T)
yakshpharmacy009118 views
Presentation_NC_Future now 2006.pdf von Lora
Presentation_NC_Future now 2006.pdfPresentation_NC_Future now 2006.pdf
Presentation_NC_Future now 2006.pdf
Lora 38 views
GSoC 2024 .pdf von ShabNaz2
GSoC 2024 .pdfGSoC 2024 .pdf
GSoC 2024 .pdf
ShabNaz245 views
11.30.23A Poverty and Inequality in America.pptx von mary850239
11.30.23A Poverty and Inequality in America.pptx11.30.23A Poverty and Inequality in America.pptx
11.30.23A Poverty and Inequality in America.pptx
mary850239228 views

Set data structure

  • 2. Introduction • A set is a collection of objects need not to be in any particular order. • It is just applying the mathematical concept in computer. • Rules:  Elements should not be repeated.  Each element should have a reason to be in the set.
  • 3. Set example :  Assume we are going to store Indian cricketers in a set. * The names should not be repeated, as well the name who is not in a team can’t be inserted. * This is the restriction we found in a set.
  • 4. NULL SET(EMPTY SET) • The set with no element is called null set or empty set. For example: A={x | x is a prime number, where 24<x<29} This set can’t contain a element. We don’t have any prime number within the limit 24 and 29. A={ }
  • 5. Basic Operations o set union(set1,set2) o set intersection(set1,set2) o set difference(set1,set2) o int subset(set1,set2)
  • 6. UNION • Combine two or more sets(here two sets), without violating the rules for set.
  • 7. INTERSECTION • Gathering common elements in both the sets together as a single set.
  • 8. DIFFERENCE • Forming a set with elements which are in first set and not in second set. • A-B= {x| for all x belongs to A but not in B}
  • 9. SUBSET • int subset(set1 , set2) • Returns 1 if the set1 is the subset of the set2., otherwise 0 if not. • Here, A c B(A contained in B)
  • 10. Types Immutable Mutable (Static) (Dynamic)
  • 11. Operations on Mutable • void* create(n) • add(set , element); • delete(set , element); • int capacity(set);
  • 12. CREATE • void* create(int n) – It simply create the set that can be used to store ‘n’ elements and return the starting address of the set in memory. int *set=create(30);
  • 13. ADD • add(set set_name , type value) – This function add one element into the set specified in the function argument. – The set_name argument is to mention the set which is going to be updated. – value argument is the value to be inserted into the set that passed to the function.
  • 14. DELETE • delete (set set_name , type value) – This function delete one element from the set specified in the function argument. – The set_name argument is to mention the set which is going to be updated. – value argument is the value to be deleted from the set that passed to the function.
  • 15. CAPACITY • int capacity(set set_name) – This function is used to find the maximum number of elements can be stored into the set that passed to the function. – Find the count and return the integer value.
  • 16. Operations on Immutable • int elementof(x , S) • int empty(S) • int size(S) • void* build(x1 , x2 , … , xn)
  • 17. ELEMENTOF • int elementof(type x , set set_name) – This function check for the element ‘x’ in the passed set. – Returns the value whether 0 or 1. – If the X is there in the set, return 1 otherwise 0.
  • 18. EMPTY • int empty(set set_name) – This function checks for the emptiness of the set that passed to the function. – If the set is empty, return 1 else 0.
  • 19. SIZE • int size(set set_name) – Returns the number of elements in set.
  • 20. BUILD • void* build(set_elements) – This function create the set with the given elements and return the address of the first element. – Return the void* , we can assign that pointer to the type* which type we declared the set.
  • 22. • intersection() Here, function for set with the type int. int* intersection(int set1[100],int set2[100]) { int inter[100],k=0; for(i=0;i<size(set1);i++) for(j=0;j<size(set2);j++) if(set1[i]==set2[j]) { inter[k]=set[i]; k++; } return inter; }
  • 23. • union() int* union(int set1[100],int set2[100]) { int uin[100]; for(i=0;i<size(set1);i++) { uin[i]=set1[i]; } for(j=0;j<size(set2);j++) { if(!find(uin,set2[j])) { uin[i]=set2[j]; i++; } } return uin; }
  • 24. • elementof() int elementof(int set[100],int x) { for(i=0;i<size(set1);i++) { if(set[i]==x) return 1; } return 0; }
  • 25. Dynamic memory allocation  Header file for this is <alloc.h> void* malloc(int size_of_block) void* calloc(int number_of_blocks, int size_of_each_block) void free(void* ptr) realloc(void* ptr, int size)
  • 27. HASH FUNCTION • Before entering into an application of set data structure, we need to discuss about hash function. • Hash function is a function that generate an integer number with a particular logic. • This function is like a one way entry. We can’t reverse this function. But by doing the process with the same number we may get an answer.
  • 28. • Sometimes the same value may be generated for the different values. In that case, we need to check for the data in that location. • In some cases, same values will generate the different output. Both are possible. • We have to select a hash function which is not repeating the values generated.
  • 29. Spelling checker • Here, is a simple example for spelling checker. • This concept applied by using the hash table data structure. • The two files are provided to us for process. One is “dictionary file”, which is the collection of meaningful words, and another one is “input file”, that contains the word to be validated for spell.
  • 30. • Initially the words from the dictionary file and also from input file be inserted into the hash tables separately. • And the intersection operation will be done between the two hash tables. • If the set with one element is the result of the intersection, then the word is in dictionary. Spell is perfect. If, null set returned form the intersection, then the spell is wrong.
  • 31. The set data structure is indirectly implemented using such as trees, tries, hash tables, arrays, by restricting ourself while storing data. This is widely used data structure when we need no repetition as well a collection.