LMU ☀️ CMSI 2120
DATA STRUCTURES
HOMEWORK #4 Due: 2022-11-03

Learning Objectives

With this assignment you will demonstrate:

Readings and Videos

Please:

Instructions

Work in teams of 1 to 2 students.

For this assignment you will be working out the answers to various problems. Submit, to BrightSpace, a PDF document with your solutions. Make sure it is beautiful. Because taking pride in one’s work is valued, poorly crafted submissions will necessarily be docked.

Your PDF submission should be generated from a source document written in some nice document preparation system such as LaTeX, Pages, or Word. Place your document source in the GitHub repository you have been using for this course. Submit only one submission per team.

Structure your repository, for now, as follows:

  .
  ├── README.md
  ├── .gitignore
  ├── homework1/
  │   └── (existing files from previous assignments)
  ├── homework2/
  │   └── (existing files from previous assignments)
  ├── homework3/
  │   └── (existing files from previous assignments)
  └── homework4/
      └── (source code for your document, e.g. .tex, .docx, .pages, ...)

The Problems

  1. Write $\mathscr{P}(\{a, b, c\})$ in a form in which all elements are listed.
  2. How many partitions are there of $\{x \in \mathbb{N} \mid 1 \leq x \wedge x \leq 10\}$?
  3. Let $A$ be a set and $m$ and $n$ be positive integers. Would you say that $A^{m+n} = A^m \times A^n$? Give arguments for or against accepting this equality as fact. (Hint: you may want to consider the sets $A \times A^2$ and $A^2 \times A$.)
  4. Express, in lambda notation, the function which when passed two functions $f$ and $g$, returns the composition of $f$ and $g$. (Don't use the predefined $\circ$ symbol for composition. Actually define the meaning of composition in your answer.
  5. Let $f = \lambda x. 4x-3x^2$.
    1. What is $f^{0}(0.01)$?
    2. What is $f^{1}(0.01)$?
    3. What is $f^{2}(0.01)$?
    4. What is $f^{5}(0.01)$?
    5. What is $f^{30}(0.01)$?
    6. What is $f^{50}(0.01)$, according to Java?
    7. What is $f^{50}(0.01)$, according to your handheld calculator?
    8. Explain why we can never write out the exact value, as a decimal number, of $f^{75}(0.01)$ in 10 point Times New Roman on printer paper that is produced on Earth.
    9. Do you think it will possible in our lifetime whether we will ever know the first digit of the decimal expansion of $f^{100}(0.01)$. Why or why not?
  6. What is the time complexity of this code fragment? (Use $\Theta$-notation)
    var x = 1;
    for (var i = 0; i < n; i++) {
        for (var j = 1; j <= x; j++) {
            System.out.println("*");
        }
        x = x + x;
    }
    
  7. What is the time complexity of this code fragment? (Use $\Theta$-notation)
    for (var i = 0; i < n; i++) {
        for (var j = 0; j < i; i *= 2) {
            System.out.println("*");
        }
    }
    
  8. What is the time complexity of this code fragment? (Use $\Theta$-notation)
    for (var i = 1; i * i <= n; i++) {
        for (var j = 1; j <= n; j += j) {
            System.out.println("*");
        }
    }
    
  9. What is the time complexity of this code fragment? (Use $\Theta$-notation)
    for (var i = 1; i <= n; i *= 2)
        for (var j = 1; j <= i; j++)
            System.out.println("*");
        }
    }
    
  10. What is the time complexity of this code fragment? (Use $\Theta$-notation)
    for (var i = 1; i <= n * n; i++) {
        for (var j = 1; j <= n; j *= 2) {
            System.out.println("*");
        }
    }
    
  11. What is the time complexity of this code fragment? (Use $\Theta$-notation)
    for (var i = 1; i <= n; i++) {
        for (var j = 1; j <= i; j *= 2) {
            System.out.println("*");
        }
    }
    
  12. What is the time complexity of this code fragment? (Use $\Theta$-notation)
    for (var i = n; n >= 1; n /= 4) {
        for (var j = 0; j < i; j++) {
            System.out.println("*");
        }
    }
    
  13. Give both the best-case and worst-case time complexities of this code fragment. (Use $\Theta$-notation)
    // Assume some global variable t is defined out here
    for (var i = n; i >= 1; i /= 2) {
        if (Instant.now() > t) {
            for (var j = 0; j < i; j++) {
                System.out.print("*");
            }
        }
    }
    
  14. Give both the best-case and worst-case time complexities of this function. (Use $\Theta$-notation)
        public static long power(int x, int n) {
            return n == 0 ? 1
                : n % 2 == 0 ? power(x * x, n / 2)
                : x * power(x * x, n / 2)
        }
    
  15. What is the time complexity (in $\Theta$-notation) of a procedure to print out the exact value of $2^n$, where $n$ is a nonnegative (big) integer? The procedure described is supposed to print a result no matter how large the result may be.
  16. An algorithm with time complexity $T(n) = n^3$ can process a 100-element list on our PC in 10 seconds.
    1. How long would it take to process a 200-element list?
    2. If we ran the algorithm on a machine that was 10 times faster than our PC, how large of a list could we process in 30 seconds?
    3. How much faster than our PC would a computer have to be in order to process a 1000000000-element list in a time span of 1 hour?
  17. An algorithm with complexity function $T(n) = n \log{n}$ processes a 64-element list in three minutes and 12 seconds on our PC.
    1. How long does it take to process a 128-element list?
    2. How large of a list could a computer that is 8 times faster than our PC process in 10 seconds?
    3. How much faster would a computer have to be than our PC to process a list of size 10 in a second?
  18. An algorithm with time complexity function $T(n) = 2n \log n$ can process a 32 element list in 2 minutes and 40 seconds on our PC.
    1. How long would it take to process a 64 element list?
    2. If we ran the algorithm on a machine that was 4 times faster than our PC, how large of a list could we process in 16 seconds?
  19. We have seen that there is little hope of solving problems of size 100 or so with algorithms of complexity $\lambda n. 2^n$ even when billions of operations can be carried out per second. But what about algorithms of complexity $\lambda n. 1.1^n$? How do these algorithms compete with quadratic algorithms? In particular, if a billion operations can be performed in one second, up to what problem size will the $\lambda n. 1.1^n$ be faster than a $\lambda n. n^2$ algorithm?
  20. Rank each of the following functions by growth rate: $\lambda n.n$, $\lambda n.n^2$, $\lambda n.n^{1.5}$, $\lambda n.\sqrt{n}$, $\lambda n.n \log n$, $\lambda n.n \log \log n$, $\lambda n.n^2 \log n$, $\lambda n.n \log n^2$, $\lambda n.n (\log n)^2$, $\lambda n.2$, $\lambda n.n^3$, $\lambda n.\frac{2}{n}$, $\lambda n.2 \log n$, $\lambda n.2^n$, $\lambda n.2^{\log n}$, $\lambda n.2^{n \cdot n}$, $\lambda n.2^{n \div 2}$, $\lambda n.n!$, $\lambda n.n^n$, $\lambda n.(\log n)^n$, $\lambda n.\log n^n$, $\lambda n.\log(\sqrt{n})$.

Grading

You will be graded both on having reasonable (and in some cases correct) solutions to the problems, as well as how beautifully and consistently formatted your submitted document is presented.