Tuesday, May 22, 2012

DBMS- Normalization

Functional Dependency

Consider a relation R defined over a set of attributes (A1,A2,…..An)  and let  X and Y  be  subset or equal to  (A1,A2,……...An), then
            X  --->  Y
Y is functionally dependent on X if and only ,whenever two tuples in R agree on their X value ,they also agree on their Y value . i.e if each X value in (A1,A2,…..An) has associated with it  one Y value  in (A1,A2,……..An)

A functional dependency of the form
                  X   --->     Y
where Y  subset or equal to X is said to be trivial .

Candidate Key

Consider a relation R on set of n-attributes, then a candidate key K is a set of one or more fields if and only if it satisfies following :

Uniqueness : K uniquely identifies each tuple, i.e. no two tuples can have  same value of K

Non - redundancy : K is non - redundant, i.e. no proper  subset of K has the uniqueness property

There is no subset of the key which has above above properties and in general more than one candidate key may exist.

Example:

STUDENT( name, father-name, course, enroll-number, grade)
Candidate keys assuming they give an unique identification  : {name,father-name} 
{enroll-number}

 Non Candidate Key :
 {name, enroll-number} violates property 2.
 { course} violates property 1. 

 Prime/ Non Prime
 Prime attribute : Attribute participates in a candidate key.

 Non Prime attribute: Attribute does not participate in any candidate key

 Example:

 STUDENT( name, father-name, course, enroll-number, grade)
 Where key be enroll-number, then
 Prime attribute : enroll-number.
 Non Prime attribute : name, father-name, course, grade

 Primary Key

 A designated candidate key is a primary key. Primary key must be fully defined  i.e no unknown values or NULL values are permitted.

Example:

 Let candidate key of STUDENT be rollno, the
 Every student must have a rollno.
 rollno is a PRIME attribute
 name, fname, course, grade are NON PRIME attributes.

Super Key

A  collection of attributes which is a unique identifier, may be non minimal.


Axioms
Reflexivity rule
If  A  is a set of attributes and B subset or equal to A
            =>A ---->  B

 Augmentation rule
 If  A ---->B holds  and  C is a set of attributes                                                 
           =>CA---> CB

Transitivity rule
If  A ----> B holds and B ----> C holds
           =>A ----> C

These axioms are sound and complete as they generate all other functional dependencies for a given set F of functional dependencies.

 This collection of rules is known as Armstrong’s axioms

Additional Rules

Union rule
 If  A---->B holds and A---->C holds
          => A----> BC

 Decomposition rule
 If A---->BC holds
           =A---->B and A----->C
 pseudo transitivity rule
 If A---->B holds and CB----->D holds
            => AC----->D

Normalization

Two broad approaches to normalization :
 1. Decomposition approach
 2. Synthesis approach

Decomposition approach:

Treat all the attributes as defining the properties of one entity
Determine the functional/multi-valued dependencies.
Decompose the global entity into its components.  Repeatedly decompose each entity thus obtained till no further decomposition is possible.

Synthesis approach:

Identify all the functional / multi-valued dependencies.
Group together into entities all those attributes which exhibit these dependencies.

Definition of Decomposition:

Let r be a relation on relation scheme R and let ri=Ri(r) for
i=1,2,…. then
r   subset or equal to r1  join  r2 ………..join rn        

The Decomposition of the relational scheme R={A1,A2,A3…An} in its replacement by a set of relation schemes {R1,R2,R3….Rn} such that R1 join R2 join R3…..Rn = R.

Decomposition can be Lossless-Join Decomposition : All the original information can be recovered by joining

Decomposition can be Non-Lossless-Join or Lossy Decomposition : Only partial information can be recovered

Lossless-Join Decomposition

R a relation and F a set of FDs
Decompose R into R1 and R2
Decomposition is lossless if either
R1 ∩ R2 → R1 or
R1 ∩ R2 → R2 is in F+

EmpDept ( empno, empname, job, deptno, dname, dloc)
F = { deptno → dname    deptno → dloc      empno → empname
          empno → deptno    empno → job  }

Decompose EmpDept into two relations
    Emp ( empno, empname, job, deptno )
    Dept( deptno, dname, dloc)

Decomposition is lossless-join

deptno → dname      deptno → dloc
deptno → dname, dloc (union)
deptno → dname, dloc, deptno ( augmentation)
Emp ∩ Dept = { deptno } → Dept

Decompose EmpDept into two relations
    Emp ( empno, empname, job)
    Ejob( deptno, dname, dloc, job)

Emp ∩ Dept = { job } !→ Emp or Ejob
Decomposition is non-lossless-join


Dependency Preserving

A relation R with  a set of functional dependencies  F be decomposed into the relations R1, R2, ……., Rn .
The restriction of F to Ri = Fi = {FDs in F+ which include attributes only of Ri }
 F| = F1 U F2 U … U Fn
Decomposition is dependency preserving if F| = F or F|+ = F+

EmpDept ( empno, empname, job, deptno, dname, dloc)
F = { deptno → dname    deptno → dloc      empno → empname
          empno → deptno    empno → job  }

Decompose EmpDept into two relations

    Emp ( empno, empname, job, deptno )
        Femp =     {empno → empname,     empno → deptno, empno → job  }
    Dept( deptno, dname, dloc)
        Fdept = {deptno → dname,    deptno → dloc }

F| = Femp U Femp = F hence dependency preserving

Notion of Normalization

Normalization refers to the procedure of successive decomposition of a given relation into smaller relations. Normalization should be  information preserving.












1st Normal Form

A relation R defined (A1, A2, ……., An) is said to be in 1 NF if : Values in the domain of each attribute of the relation are atomic . i.e the value is not a set of values or a list of values. Relational model expects relations to be in 1 NF.

Example:

 STUDENT(name, fname, roll-no, course,grade)
 Every attribute takes on a simple value.Thus it is in 1 NF.

 EMPLOYEE(name, address, child)
 child has attributes like child-name,age,sex.It is not atomic, thus is not in 1NF
PRODUCT(product-no, price, qty)
It is in 1 NF as every attribute has as atomic value

Enforcing the 1 NF

Replacement method: Systematically replaces all complex attributes by their constituents

Example: 

For EMPLOYEE (name, address, child) define as 
EMPLOYEE(name,address, child-name, cage, csex)

Decomposition method: Split the relation into two components, each of which are in 1 NF.

Example:

For EMPLOYEE define
EMPLOYEE(ename, address) and CHILD(cname, cage, asex)

Notion Of Anomaly

Knowledge of the relation that is required to perform an operation on relation without creating any data inconsistencies.
Three anomalies are:

INSERT: One can not insert the fact that a particular supplier is located in a particular city until that supplier supplies at least one part
DELETE: If one deletes a tuple for a particular supplier, the information about the supplier’s City is also lost.

UPDATE: The city value for a given supplier appears many times.This redundancy causes problems.For eg is a supplier S1 moves from LONDON to AMSTERDAM, then there is a problem either to find every tuple connecting S1 and LONDON or to produce an inconsistence result.


Partial functional Dependency

An attribute is partially functionally dependent upon another when it is functionally dependent upon it and also upon a proper subset of it.

Example:

 A , B------>C
 A ----->C
 It leads to redundancy

2nd Normal Form

A relation is said to be in 2 NF if and only if it is in 1 NF and every non-key attribute is irreducibly dependent on the primary key.

It is concerned with the elimination of redundancy due to partial functional dependencies.

Redundancy causes inconsistent modifications :

Update Anomaly : In supplier if X shifts business from Delhi to Bangalore then time dependent behavior on the number of parts being  supplied at that time.Number of updates performed may be less than required

Deletion Anomaly : In supplier if X stops supplying parts 1, 2 and 3 then all three rows are deleted. And thus information  about city of X is lost.

Insertion Anomaly : A new supplier C starts operating from Calcutta then, one can not insert since it will cause an undefined value in  the primary key

If partial functional dependency does not involve the primary key  then time dependent behavior is shown

Assume (S, P#) is not the primary key then, INSERTION is okay but  when first P#  is defined then an UPDATE has to be performed and  for subsequent P# insertion has to be done.

Again inconsistent modifications are possible.


Eliminating Redundancy due to Partial Dependency

Eliminate partial functional dependency by having only full functional dependencies.
This is known as the 2NF norm.
An entity is in 2 NF if it is in 1 NF and if each non-prime field is fully dependent upon each candidate key

Represent the offending partial functional dependency as as separate entity.Thus split the original relation into two. 


Transitive Dependency

Let A, B, C be three distinct collections of attributes of an entity and following functional dependencies hold :
A →  B,   B !→  A, B → C
Then we say that     A → C  transitively or that C is transitively functionally dependent upon A

Transitive functional dependencies give rise to redundancies and thus inconsistencies.


3rd Normal Form

Codd’s Definition
A relation is in 3NF if it satisfies 2NF and no non prime attribute of R is transitively dependent on the primary key

Equivalently,

A relation is in 3 NF if for every functional dependency of the form X---->A, one of the following statements is true:
1. it is a trivial FD
2. X is a super key
3. A is a prime attribute

Example:

Consider a relation Stdinf (Name, Phoneno, Course, Major, Prof. ,Grade ,Major-Elective) with following FD’s






The key of the relation is {Name Course}

The partial dependencies are caused by Name → Phoneno
Name → Major and Course → Prof. as Name, Course is the key
The only transitive dependency is 
Name → Major, Major →  Major-Elective.

2NF Decomposition:
R1  {Name, Phoneno, Major, Major-Elective}
R2   {Course,Prof..}
R3    {Name,Course,Grade}

3NF Decomposition:
R1-1{Name,Phoneno,Major}
R1-2{Major,Major-Elective}
R2   {Course,Prof.}
R3    {Name,Course,Grade}

Preserves all the Functional Dependencies existing in the original relation








BC Normal Form

Need For BCNF arises when X → A and A → B where B is a subset of X

A relation is in BCNF if whenever a functional dependency
X → A holds then, either    
i) X is a super key of R, or
ii) X  →  A is trivial (A  is subset of X)

Lossless BCNF Decomposition:
If A-->B in R violates BCNF  then create
R1(A,B ),  R2 (R - B)

Case where BCNF is Lossless and Dependency Preserving:

Consider Relation Shipping(Ship,Capacity,Date,Cargo,Value) with following FD’s
 Ship-->Capacity
 Ship,Date-->Cargo
 Cargo,Capacity-->Value
In this case first and third FD’s are nontrivial and also determinant is not super key so it is not in BCNF

(Ship,Capacity,Date,Cargo,Value)
(Capacity,Cargo,Value)
With FD(Cargo,Capacity)---->Value
(Ship,Capacity)
With FD Ship---->Capacity
(Ship,Date,Cargo)
With FD Ship ,Date---->Cargo



Entity Relationship Model

Based on a perception that a real world consists of a set of basic objects, called Entities, and Relationships among these objects.

Entity - Thing which has existence distinguishable from other objects (things)

Entity Properties
  1.  independent existence
  2. can be concrete or abstract
  3. described by its attributes (set of properties)
  4. determined by particular value of its attributes

Attributes - Descriptive Property  of entity and  Takes values from a permitted set - Domain or value set

Information about an entity or relationship can be expressed by a set of (attribute,value) pairs

Person entity with attributes name, age
    { (name, Hari),(age,20) }


Types of Attributes

Simple vs Composite

Is a function which maps from one entity set or relationship set into a value set or a Cartesian product of value sets.

simple attribute
    Ai : E or R -----> Vi    
    name : Person ---> string

composite attribute
    Ai : E  or R -----> Vi1 X Vi2 X……..Vin











Single vs Multivalued

Single valued - one value for an entity. Attribute name has one value Hari
Multivalued - a set of values for an entity. Attribute tel-number has more than one telephone number

Stored vs. Derived attribute

Stored – value stored in the database
Derived - value derived from other related attributes
Stored: Individual mark of a student, date-of-birth
Derived: Overall grade in a class, age

Entity Set

An entity set is a set of entities of the same type; entities that share the same properties.

Entity sets : Employee, Project, Department

Relationship and Relationship set

A relationship is an association among several entities.
A relationship set is a set of relationships of the same type

Let E1, E2, ... En be a set of entity sets.
E1, E2, ... En participate in the relationship R
is a relationship
R is a subset of E1 x E2 x ... x En
= { where ei is an element of Ei }


Roles

Entities participating in relationships play the respective roles in them.
Role is the function performed by the entity in the relationship.

Example:   
Ownership is a relationship between Person and House
The entities play the role of owner and owned respectively.

Notation


rectangle: entity Set


ellipse: attribute

diamond: relationship

line: link attributes to entity sets and entity sets to relationship sets

double ellipse:multivalued attributes

dashed ellipse:derived attributes





Relationship Attribute

An attribute can also be a property of a relationship set

Degree of relationship set

Refers to the number of entity sets that participate in a relationship set.
Relationships that involve two entity sets are called binary

Cardinality

Express the number of entities to which another entity can be
associated via a relationship set

-one to one
-one to many
-many to one
-many to many


















Participation

The participation of an entity set E in a relationship R is total if every entity in E participates in at least one relationship in R. partial otherwise









Weak Entity

Entities that are distinguished by their relationship to another entity. Weak entity has partial key or discriminator – Identify entities related to the same strong entity.

The primary key =  primary key of the strong entity set + discriminator.

Aggregation

expressing relationship with a relationship

Generalization - Specialization

Abstracting the common properties of two or more entities into a “higher-level” entity.













Specialization = top-down design
Generalization= bottom-up design







Introduction to DBMS

A DBMS is a software package for managing a database. A database is a collection of related data.
Example DBMSs: Oracle, DB2, Informix, Ingres, ….

Position Of a DBMS


A DBMS interacts with the Operating System and System resources: memory, processor, IO, File System, Security subsystem.

A DBMS interacts with Users. Users may be Database Administrators (DBA): designers, implementers, maintainers, Database End-users: Casual or professional

Three level Architecture (ANSI/SPARC)

Differences between Three Levels

Internal Schema

Struct Staff {   
                      int Staff_No, Branch_No;
                      char Fname[15];
                      char Lname[15];
                      struct date Date_of_Birth;
                      float Salary;
                  };
                      index Staff_No;

Data Independence

Logical Data Independence: Capacity to change the conceptual schema without having to change external schema's or application programs
Physical Data Independence: Capacity to change the internal schema without having to change conceptual or external schema's

Database Views

Kinds of Databases


Monday, May 21, 2012

GNU/LINUX Install Mannual

GNU/Linux for Physically Challenged: Install from Live CD/DVD

First download GNU/Linux From http://cdacmumbai.in/accessibility

Note: Before you start, please note down carefully the partitions on your hard disk, their sizes and the operating systems residing on them. You will need at least 6-8 GB disk space to install the new OS. If it is not there, you will have to delete or resize an existing partition to free the required disk space. So decide in advance which partitions you could delete or resize if required.

1.Insert the CD/ DVD and restart the computer. Keep looking at the screen. A message indicating the button for entering boot options menu will be displayed at the top or bottom. The button may vary from system to system. It may be Delete or F2 or F9 or F12. Keep pressing the appropriate button while the system is starting. This will bring up the boot options menu. Select the option to boot from CD/ DVD and press Enter. If your computer is already configured to boot from CD/ DVD when one is loaded, this step is not required. When the computer boots from the live CD/ DVD, the following screen appears. Just press Enter to continue.



2.The next screen shows three options. The live option will run the new OS from the CD/DVD, without making any changes to your hard disk. This is an excellent way to try out the new OS. The install option starts installing the new OS on your hard disk. The hd option skips the new OS and boots your computer in the usual fashion. Select install Option press Enter key.



3.This is the first screen in the installation process. Choose the language (default is English) and click on the Forward button.


4.Choose your location and time zone (default is India time). Click on Forward button.


5.Choose the appropriate keyboard layout for your computer (default is USA) and click Forward button.



6.This is the most important step in the installation process. The following screen shows the existing partitions on the hard disk and the operating systems residing on them. Here you decide where on your hard disk the new OS is going to be installed. WARNING: NEVER CHOOSE THE SECOND OPTION viz. ERASE AND USE THE ENTIRE DISK. THIS WILL ERASE ALL EXISTING OPERATING SYSTEMS, APPLICATIONS AND DATA FROM YOUR HARD DISK, CREATE A SINGLE PARTITION OCCUPYING THE WHOLE DISK AND INSTALL THE NEW OS THEREIN. To retain the existing operating systems, applications and data, and to have enough control on the installation process, choose the last option viz. Specify partitions manually (advanced) and click Forward button.



7.The following screen shows the existing partitions and provides options to modify them. In the example shown, we want to delete partition sda10, because it doesn't contain anything useful. We highlight the partition and click on Delete.



8.The following screen shows that partition sda10 has been deleted and its space has been added to the available free space. Now we need to create new partitions to install the new OS. We need two partitions, a swap partition and a root partition.



9.To create the root partition, highlight the free space entry and click the Add button. Create a new partition dialog appears. Set characteristics of the new partition as shown. Note that the partition type is set to Logical. The size is fixed at 10000 MB (10GB). The partition is located at the beginning of free space. The file system is Ext4 (Ext4 and Ext3 are standard for Linux). The mount point is set to / (slash). This means that the new partition will be mapped to the / (root) folder of the Linux file system. Now click the OK button.



10.The new partition sda10 is seen in the screen below. We have to make one change to this new partition. Highlight the new partition entry and check the check-box in the Format column. This means that the new partition will be formatted before the installation begins.




11.The next step is to create a swap partition. Repeat the procedure that we followed to create the root partition, but some settings would be different. Set the partition type to Logical. Fix the size to double the size of system RAM. For example, if you have 2GB RAM, fix the swap partition size to 4GB. Locate the partition at the beginning of free space. Set the file system to swap area. There is no need to specify the mount point for a swap partition. Finally click the OK button. Note that the partition list in the previous screen already shows a swap partition sda5. In such a case you don't need to create another swap partition, so skip this step.


12.In the next screen type in your name as 'physical' and password as 'physical' and click Forward button.



13.The installer searches the existing operating systems for documents and settings corresponding to different user accounts. If it detects any, it allows you to import the user accounts to the new operating system being installed. Mark the accounts you want to import and click on the Forward button.



14.The installer summarizes all inputs which you have entered in the earlier steps and displays them for review. Confirm that all inputs given by you are correct and click the Install button. If you want to change any input, click on the Back button.



15.The installation is in progress. Wait untill the installation is complete and then restart the System.

16.When you reboot your computer, you see the GRUB menu showing different operating systems. The new operating system which was just now installed is at the top. Previous operating systems which existed before this installation are listed below it. If you find that any of the previous operating systems are missing, don't panic. Login to the new operating system and start the Grub Customizer utility (System -> Administration -> Grub Customizer). Suppose you find that the Windows operating system is missing. Look at the Grub Customizer window shown below. Find the entry corresponding to the missing OS (here it is - Microsoft Windows XP Professional (on /dev/sda2)) in the 'name' column and check the checkbox on its left in the 'is active' column. Also check the checkbox on the left of the heading (here it is - os-prober (custom)) under which the entry appears. If you want to move an entry upwards or downwards in the menu, highlight the entry and move it to the desired location by clicking on the orange coloured Up/ Down buttons in the toolbar. Finally click the File->Install to MBR option in the toolbar to save your changes. Close the Grub Customizer and reboot your system. You will find that the Grub menu now shows all the operating systems, previous and the latest.


GNU/Linux distributions for differently-abled people

CDAC Mumbai released three specially designed GNU/Linux distributions for specially enable people.

To Download below mentioned all ISO files please Click Here.

GNU/Linux For Visually Challenged:

This is a GNU/Linux distribution created specially for visually challenged users. It is based on Ubuntu 10.04; and uses Orca 3.1.3 pre-xdesktop screen reader. Visually challenged users can use it out of the box because accessibility settings required by them are already enabled.  


GNU/Linux For Physically Challenged:

'GNU/Linux for Physically Challenged-Beta-0.1.1' is a special distribution for physically challenged people, so that they can easily access FOSS desktops. This Distribution provides friendly and smooth environment for physically challenged people. This distribution is an outcome of 'Enhancing accessibility of FOSS desktop' project at CDAC Mumbai.


GNU/Linux For Cognitively Challenged:
 
This linux distribution has been developed to provide an accessible desktop environment to the cognitively challenged users. Cognitive disability is one of the most challenging disabilities to address and people suffering from cognitive disability face problems like memory loss – short-term or long-term, learning disability, forgetfulness, reading disability, attention problems, etc.

Drawing With Mouse in Xwindow

Here i am giving a code block which takes two points and draw the line between those two points. Where point is a structure

struct Point {
                      double x;
                      double y;
                    };

/ * Function Start */ 

void Draw_Gesture(Point p, Point q)
{
                 Drawable d = w;
                 XGCValues values;
                 values.line_width = prefs.trace_width.get();
                 values.line_style = LineSolid;
                 GC gc = XCreateGC(dpy, d, GCLineWidth, &values);
                 XDrawLine(dpy, w, gc, p.x, p.y, q.x, q.y);
                return;
}

/ * Function End */ 

Now to draw line, as long as Moving the mouse, we have to write a function to Listen mouse events. From that event variable we will get x and y coordinates of current mouse locations. We assign these x and y coordinates to x and y of Point structure. Then we will send these Point Structure variables to Draw_Gesture functions. Now Draw_Gesture  function Draws the line as long as mouse moves in window w.

Drawing with Mouse
Drawing With Mouse

Set Operations in Haskell

In this topic we are going to concentrate on following things

1. Introduction to implementation of sets and Set Operations
2. Functions related to construction of sets
3. Show tree functions on sets
4. Splitting functions of sets
5. Min / Max functions on sets
6. Conversion functions on sets
7. Query functions on sets
8. Combine functions on sets

Introduction to implementation of sets and set Operations

1. The implementation of Set is based on size balanced binary trees like AVL trees.
2. To implement set operations we must know corresponding algorithm Ex: for Union, Hedge union Algorithm
3. Must know the advanced concepts of Haskell like Tip, Bin, foldr, monoid, Foldable and many more concepts.
4. All set operations already implemented. Available in “Data.Set” Container of Haskell.

Functions related to construction of sets

Syntax: fromList :: [a] -> set a
Description: Creates a set from a list of elements.

Syntax: singleton :: a -> Set a
Description: Creates a singleton set with element ‘a’.

Syntax: insert :: a -> Set a -> Set a
Description: Insert an element in a set. If the set already contains an element equal to the given value, it is replaced with the new value.

Syntax: delete :: a -> Set a -> Set a
Description: Delete an element from a set.

Exercise-1: Construct a set S = {a, b, d, c, e} and delete ‘b’ from that set and add ‘f’ to set.

Exercise-2: Construct singleton set S = {0.123}. Add 9.8 to that set and delete 0.98 from that set.

Showing Tree functions on sets

Syntax: showTree:: Set a -> String
Description: Shows the compressed tree that implements set.

Syntax: showTreeWith:: Bool -> Bool -> Set a -> String
Description: shows the tree that implements the set. If hang is true, a hanging tree is shown. If wide is true, an extra wide version of tree is shown.

Exercise-1: From set S = {a, b, e, d, c} generate a string from which we can draw corresponding balanced tree.
Note: Use putStrLn Function

Splitting functions on sets

Syntax: partition ::(a -> Bool) -> Set a -> (Set a, Set a)
Description: Partition the set into two sets, one with all elements that satisfy the predicate and one with all elements that don't satisfy the predicate.

Syntax: split :: a -> Set a -> (Set a, Set a)
Description: The expression (split x set) is a pair (set1,set2) where set1 comprises the elements of set less than x and set2 comprises the elements of set greater than x.

Syntax: splitMember :: a -> Set a -> (Set a, Bool, Set a)
Description: Performs a split but also returns whether the pivot element was found in the original set.

Exercise-1: Divide the set S = {f, h, k, l, o, a, p, r, t} into two sets S1 and S2. Set S1 with elements less than ‘m’ and set S2 with elements greater than ‘m’.

Min / Max functions on sets

Syntax: findMin :: Set a -> a
Description: Returns the minimal element of a set.

Syntax: findMax :: Set a -> a
Description: Returns the maximal element of a set.

Syntax: deleteMin :: Set a -> Set a
Description: Delete the minimal element from set.

Syntax: deleteMax :: Set a -> Set a
Description: Delete the maximal element from set.

Syntax: deleteFindMin :: Set a -> (a, Set a)
Description: Finds and deletes the minimal element of set.

Syntax: deleteFindMax :: Set a -> (a, Set a)
Description: Finds and deletes the minimal element of set.

Exercise-1: Express the deleteFindMin in terms of findMin and deleteMin and give one suitable example.

Exercise-2: Express the deleteFindMax in terms of findMax and deleteMax and give one suitable example.

Conversion functions on sets

Syntax: elems :: Set a -> [a]
Description: Convert the set to a list of elements.

Syntax: toList :: Set a -> [a]
Description: Convert the set to a list of elements.

Query functions on sets

Syntax: null :: Set a -> Bool
Description: checks for given set is null or not.

Syntax: size :: Set a -> Int
Description: Returns the number of elements in the set.

Syntax: member :: a -> Set a -> Bool
Description: Checks for the given element belongs to set or not.

Syntax: notMember :: a -> Set a -> Bool
Description: Checks given element doesn’t belongs to set or not

Syntax: isSubsetOf :: Set a -> Set a -> Bool
Description: Checks for given set is subset or not.

Syntax: isProperSubsetOf :: Set a -> Set a -> Bool
Description: Checks for given set is subset or not.

Exercise-1: Write instruction to check {0.32, 0.21, 0.10} is proper subset of {0.10, 0.32, 0.21}?

Combine functions on sets

Syntax: union :: Set a -> Set a -> Set a
Description: Performs union operation on given two sets.

Syntax: unions :: [Set a] -> Set a
Description: Performs union operation on set of sets.

Syntax: intersection :: Set a -> Set a -> Set a
Description: performs intersection operation on given two sets.

Syntax: difference :: Set a -> Set a -> Set
Description: Finds the difference of given two sets.

Exercise-1: let S = {1, 3, 4, 6, 7} and T = {2, 5, 8, 9, 0, 4, 6}.
Write instruction to find n (S U T).

Exercise-2: let P = {1, 3, 4, 6, 7}, Q = {2, 5, 8, 9, 0, 4, 6} and R
= {2, 5, 6, 1, 3}. Write instruction to find n (P U Q U R).