Colorado State University

CS160: Foundations in Programming: Spring 2015


Recitation R4 - Math: Sets and Functions


The purpose of this lab is to learn sets and functions:

1. Online Math Tutorials

Your TA will show you the interactive tutorial pages on our course website. These are optional, but useful for learning the discrete math in this course.

2. Problems Involving Sets

Solve the following problems in a text file called R4.txt, using an editor such as gedit. Your TA will go over them when everyone has completed the problems.

Given that:

  1. For each of these pairs of sets, determine whether the first is a subset of the second, the second a subset of the first, or neither is a subset of the other.
    1. The set of students in this class, and the set of students who are majoring in Computer Science in this class.
    2. the set of mammals, the set of land mammals.
    3. the set of students studying computer science, the set of students studying mathematics

  2. For each of the following sets, identify the cardinality of the set.
    1. {1,3,5,7,2,4,6,7,8,10}
    2. x ∈ N | 0 ≤ x ≤ 64
    3. x ∈ Z | -10 < x < 10 and x is even
    4. x ∈ Z+ | x ≤ 6
    5. the set of primary colors
    6. the set of months in the year
    7. the set of midterms in this class

  3. List the members of these sets
    1. (x | x is a real number such that x2 = 1)
    2. (x | x is a positive integer less than 7)
    3. (x | x is a squared integer and x < 99)
    4. (x | x is an integer such that x2 = 3)

  4. For the following sets: A = {4, 6, 8, 10}, B = {3, 4, 5, 6, 7, 9, 11};
    1. What is the cardinality of A and B?
    2. What is the union of A and B?
    3. What is the intersection of A and B?
    4. What is the complement of A, if the universal set is N?
    5. What is A minus B?
    6. What is B minus A?
    7. Does A minus B = B minus A?
    8. The TA will draw a Venn diagram that shows why.

3. Problems Involving Functions

For each of the functions shown below, decide whether it is one-to-one (injective), then note whether it is (strictly) increasing, (strictly) decreasing, or neither.
  1. f(x) = Math.sqrt(x), where x and f(x) are defined as doubles and x ≥ 0.



  2. f(x) = Math.floor(x), where x is defined as a double and f(x) as an integer.



  3. f(x) = x + 5, where x and f(x) are integers.



  4. f(x) = x3, where x is an integer.



  5. f(x) = x2 - 6x + 8, where x is an integer.



  6. f(x) = x % 16, where x is a positive integer.



  7. f(x) = x.length(), where x is a Java string with 4-8 characters, and f(x) is an integer.



  8. f(x) = x.substring(1, 6), where x is a Java string with exactly 8 characters.




The TA will check off your answers, also please submit your R4.txt to RamCT to verify your attendance.

© 2015 CS160 Colorado State University. All Rights Reserved.