SlideShare a Scribd company logo
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

More Related Content

PPTX
Searching
PPTX
Merge sort analysis and its real time applications
PPTX
Searching, Sorting and Hashing Techniques
PPTX
Unit 8 searching and hashing
PPTX
CLOSEST PAIR (Final)
PPTX
Merge sort and quick sort
PPTX
Hashing In Data Structure
PPTX
Data Structures - Lecture 8 [Sorting Algorithms]
Searching
Merge sort analysis and its real time applications
Searching, Sorting and Hashing Techniques
Unit 8 searching and hashing
CLOSEST PAIR (Final)
Merge sort and quick sort
Hashing In Data Structure
Data Structures - Lecture 8 [Sorting Algorithms]

What's hot (20)

PPTX
AVL Tree Data Structure
PPTX
Stacks IN DATA STRUCTURES
PPTX
Binary Tree in Data Structure
PPTX
trees in data structure
PPTX
Hashing
PPTX
AVL Tree in Data Structure
PPTX
Breadth First Search & Depth First Search
PPT
B trees in Data Structure
PPTX
Tree Traversal
PPTX
Queue in Data Structure
PPTX
Selection sorting
PPTX
Balanced Tree (AVL Tree & Red-Black Tree)
PDF
Expression trees
PPTX
Data structures and algorithms
PPTX
Static Data Members and Member Functions
PPTX
single linked list
PDF
Applications of stack
PPTX
Merge sort algorithm power point presentation
AVL Tree Data Structure
Stacks IN DATA STRUCTURES
Binary Tree in Data Structure
trees in data structure
Hashing
AVL Tree in Data Structure
Breadth First Search & Depth First Search
B trees in Data Structure
Tree Traversal
Queue in Data Structure
Selection sorting
Balanced Tree (AVL Tree & Red-Black Tree)
Expression trees
Data structures and algorithms
Static Data Members and Member Functions
single linked list
Applications of stack
Merge sort algorithm power point presentation
Ad

Similar to Set data structure (20)

PDF
Question In C Programming In mathematics, a set is a colle...Sav.pdf
PDF
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
PPTX
Set data structure 2
PPTX
hash
PPTX
cpp-2013 #8 STL Containers Part 2
PPTX
BCS304 Module 5 slides DSA notes 3rd sem
PDF
Acm aleppo cpc training sixth session
PDF
Acm aleppo cpc training seventh session
PPTX
Set operations in python (Dutch national flag and count &say problem).pptx
PPTX
project on data structures and algorithm
PDF
Python set
PPTX
Data structures and algorithms lab11
PPTX
Discrete Math Chapter 2: Basic Structures: Sets, Functions, Sequences, Sums, ...
PDF
Set methods in python
PDF
Algorithms notes tutorials duniya
PPT
Arrays and structures
PPTX
Dictionaries and Sets
PDF
Ds lab handouts
PPT
Unit iv(dsc++)
PPTX
Python - Data Structures
Question In C Programming In mathematics, a set is a colle...Sav.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
Set data structure 2
hash
cpp-2013 #8 STL Containers Part 2
BCS304 Module 5 slides DSA notes 3rd sem
Acm aleppo cpc training sixth session
Acm aleppo cpc training seventh session
Set operations in python (Dutch national flag and count &say problem).pptx
project on data structures and algorithm
Python set
Data structures and algorithms lab11
Discrete Math Chapter 2: Basic Structures: Sets, Functions, Sequences, Sums, ...
Set methods in python
Algorithms notes tutorials duniya
Arrays and structures
Dictionaries and Sets
Ds lab handouts
Unit iv(dsc++)
Python - Data Structures
Ad

More from Tech_MX (20)

PPTX
Virtual base class
PPTX
Uid
PPTX
Theory of estimation
PPTX
Templates in C++
PPT
String & its application
PPTX
Statistical quality__control_2
PPTX
Stack data structure
PPT
Stack Data Structure & It's Application
PPTX
Spss
PPTX
Spanning trees & applications
PPTX
Real time Operating System
PPTX
Parsing
PPTX
Mouse interrupts (Assembly Language & C)
PPT
Motherboard of a pc
PPTX
More on Lex
PPTX
MultiMedia dbms
PPTX
Merging files (Data Structure)
PPTX
Memory dbms
PPTX
Linkers
PPTX
Linear regression
Virtual base class
Uid
Theory of estimation
Templates in C++
String & its application
Statistical quality__control_2
Stack data structure
Stack Data Structure & It's Application
Spss
Spanning trees & applications
Real time Operating System
Parsing
Mouse interrupts (Assembly Language & C)
Motherboard of a pc
More on Lex
MultiMedia dbms
Merging files (Data Structure)
Memory dbms
Linkers
Linear regression

Recently uploaded (20)

PDF
O7-L3 Supply Chain Operations - ICLT Program
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Classroom Observation Tools for Teachers
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Cell Types and Its function , kingdom of life
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Cell Structure & Organelles in detailed.
PDF
Yogi Goddess Pres Conference Studio Updates
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
O7-L3 Supply Chain Operations - ICLT Program
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Microbial diseases, their pathogenesis and prophylaxis
Module 4: Burden of Disease Tutorial Slides S2 2025
Microbial disease of the cardiovascular and lymphatic systems
Classroom Observation Tools for Teachers
Supply Chain Operations Speaking Notes -ICLT Program
GDM (1) (1).pptx small presentation for students
Pharmacology of Heart Failure /Pharmacotherapy of CHF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Chinmaya Tiranga quiz Grand Finale.pdf
Cell Types and Its function , kingdom of life
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
O5-L3 Freight Transport Ops (International) V1.pdf
Weekly quiz Compilation Jan -July 25.pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Cell Structure & Organelles in detailed.
Yogi Goddess Pres Conference Studio Updates
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE

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.