8.2

Collections

  • Types of Collections

    • Set

      • Elements cannot be repeated

      • Elements are unordered

    • Multi-set

      • Elements can be repeated

      • Elements are unordered

    • List

      • Elements can be repeated

      • Elements are ordered

    • Array

      • An indexed list of elements

      • Each element can be accessed using a numeric index

Enumerated Types (Enum) & Set Values

  • Base Type

    • Consists of character strings

    • Each Enum value must contain exactly one element

    • Each SET value may contain zero, one, or many elements

  • Example of a Set:

    • SET(apple, banana, orange)

  • Characteristics of SET:

    • Can represent an empty set (no elements)

    • Not the same as a null value

    • Represented as a series of bits, where each bit corresponds to a specific element

      • If a bit is 1, the corresponding element is included

      • If a bit is 0, the corresponding element is excluded

    • A base type can have at most 1 enumeration

Memory Representation

  • A SET value can require a maximum of 64 bits (elements) of storage

    • Each bit represents inclusion/exclusion of elements

Array Types

  • An array is defined using brackets to indicate size

    • Example: INTEGER [4] means an array consisting of 4 integers

  • Integer Arrays

    • Defined as INTEGER ARRAY [4]

  • Array values can be initialized using braces:

    • Example: {2, 5, 11.63} represents individual array values

  • Accessing Array Elements

    • Array elements can be accessed by index (e.g., array[2] selects the 2nd element)

  • Multi-dimensional Arrays

    • Specified using nested braces

    • Example: {{2, 5}, {6, 45}} represents a 2x2 multi-dimensional array

Additional Concepts

  • Use of commas to separate values within braces

  • Brackets may also specify multidimensionality by using multiple pairs of brackets

  • Array notation is crucial for data structure representation and manipulation in programming.