HW 2

1 Theory

Do the following problems from the text:

  1. 1.13

    Yes, these are results of theorems we gave you. We want you to show us.

    Exercise 1.13 (e): For consistency with the definitions we only consider polynomials p that map the natural numbers onto the natural numbers, that is, you may assume that p is a function p:N->N.

  2. 1.16
  3. 1.18
  4. 2.9
  5. 2.11


2 Implementation

This is to be done on the CS machines (tux.cs.drexel.edu , or one of the lab machines in UCross 151), and submitted via Blackboard

In this section you will use the cell data structure provided, and write two additional (non-member) functions, to build lists: concat and concat_copy. You will time how long it takes to build lists of various sizes using these functions.

Note that the cell data structure is also a list with one element. To make a list with two elements, you will concatenate two such cells. And so forth.

Here are some files for your use:

For you to do:

  1. (Makefile target: problem1) Write a function called list_concat( A, B ) that takes two lists and returns a list that is the concatenation of both of them.

    Don't actually copy the data from the lists A and B.

  2. (Makefile target: problem2) Write a function called list_concat_copy( A, B ) that takes two lists and returns a list that is the concatenation of both of them, but without re-using the data. That is, make sure that future edits to A and B don't modify the concatenated list.
  3. (Makefile target: problem3) Run your concatenation functions on lists of lengths 1,000 through 15,000 (i.e., 1000, 2000, 3000, ..., 15,000) and measure how long it takes to run.

    See the example file for timing a function. Write your results in a table:

    100 9 11
    200 23 25
    300 32 21
    ... ... ...

    (Of course, this is made-up data. Your data won't look anything like this.) If you save your data in a file called data.out, you can plot it with gnuplot using the included plot script like this:

    gnuplot < plot-instructions

    You can view the plot that you make by typing display plot.png or by using any other image viewer (including a graphical web browser). You can also run gnuplot manually, and if you don't change the terminal type to png, the graph will display on your screen directly. You may find this helpful as you are developing your code.

    Feel free to modify the gnuplot script so that it works for you using the filename you choose and so forth.

  4. (Makefile target: view) Just display the source code containing your 2 functions, using the less pager.

Don't forget to provide a phony makefile target called run that depends on the above targets in order:

run: problem1 problem2 problem3 view

Files to Submit: