Set and Dictionaries

  • A set is an unorder collection of distinct items called elements of the set
  • A specific set is defined either by an explicit listing of its elements S={2,3,5,7}

​Set Operations

  • Checking membership of a given item- Whether a given item is among the elements of the set
  • Finding union of two sets- whcih comprises all the elements that belong to either of the two sets or to both of them
  • Iterations- which comprises all the element that belong to both sets

Implementation 

  • Set considers only sets that are subsets of some large set U , called the universal set . If set U has n elements then any subset of U can be represented by a bit string n called a bit vector in which the ith element is 1 iff the ith element of Uis included in s 

example

U = {1,2,3,4,5,6,7,8,9}

 S={2,3,5,7}

bit string= 011010100

  • Use list's structure to indicate set's element

Dictionary

  • A data structure that implements operations on  set or a multiset like serching for an given item , adding a new item , deleting an item from the collection .
Posted on by