8.6

Lecture 30: How long does it take?

This assignment is due on Tuesday, December 6 at 11:59pm. Submit it using Handin as assignment lecture30. You only need to submit the first 3 exercises.

Exercise 1. Using the function add-to-end from Lecture 25: Accumulators:
  • Calculate step-by-step
      (add-to-end "man" (list "dog" "bites"))
    = ...
    = ...
    = (list "dog" "bites" "man")

  • Calculate step-by-step
      (add-to-end "mail" (list "dog" "bites" "man"))
    = ...
    = ...
    = ...
    = (list "dog" "bites" "man" "mail")

  • Calculate step-by-step
      (add-to-end "area" (list "dog" "bites" "man" "mail"))
    = ...
    = ...
    = ...
    = ...
    = (list "dog" "bites" "man" "mail" "area")

Because our purpose here is to count steps, make sure to follow the steps in the video above. Careful use of find-and-replace can speed up your work. Do not put these calculations in comments.

Exercise 2. Using the function add-to-end from Lecture 25: Accumulators:
  • How many servings of steps does it take to add to the end of a 2-element list? Define this number as a constant named add-to-end-2

  • How many servings of steps does it take to add to the end of a 3-element list? Define this number as a constant named add-to-end-3

  • How many servings of steps does it take to add to the end of a 4-element list? Define this number as a constant named add-to-end-4

Exercise 3. Using the function rev from Lecture 25: Accumulators:
  • How many servings of steps does it take to reverse a 3-element list? Define this number as a constant named rev-3

  • How many servings of steps does it take to reverse a 4-element list? Define this number as a constant named rev-4

  • How many servings of steps does it take to reverse a 5-element list? Define this number as a constant named rev-5

For the rest of this page, you don’t need to submit anything, but do watch the videos and try the exercises anyway. We’ll work through the material together in class.

The code written in the video above is available for your reference. To download it, don’t use “Save Page As” or “Save As”; use “Save Link As” or “Download Linked File” in your Web browser. If you can’t find the command, try right-clicking or two-finger-tapping or long-pressing.

Exercise 4. Start with the function quick-sort developed in Lecture 23: Quick sort. Fuse its two stages build-pivot-tree and flatten, to get rid of the intermediate PivotTree.

Exercise 5. Any advice for future students? Think back to 3 months ago when you were just starting the course. What would have helped you then? Please share your wisdom as comments, and we will pass it on to the next generation.

know the design recipe but never use it

Optional: Read Intermezzo 5 of the textbook.