Module 6: Sets

CMPS 260: Data Structures


Sets can be used to store elements just like arrays, with the difference that each element can occur only once and the elements are not ordered. This is quite similar to the mathematical concept of a set. It is possible to add and remove elements, as well as checking whether an element exists in the set. It is also possible to iterate through all elements in the set. An example of a set would be all the students in a class. We will also look at set operations: union, intersection, difference, and subset. For example, to find out which students take both CMPS 162 and CMPS 163 at the same time we can take the intersection of the two sets that represent the students in each individual class.

Module Objectives

  • Describe the set data structure
  • Implement creating and using a set
  • Implement and use the set operations

Learning Resources

  • Module 6 Readings: Chapter 6 (skip ECMAScript sections)
  • Module 6 Slides: Chapter 6

Learning Activities

  • Module 6 Assignment

For Further Study

  • Read more about sets on Wikipedia

Leave A Reply

Your email address will not be published. Required fields are marked *