COSC 221 Homework Schedule

A1 (due 1/9 at 11:55 pm)

  1. Create a RPub account.
  2. Create an R Presentation containing four slides. The slides should be
  3. Send me an email containing the root URL of your RPub site.

A2 (due 1/13 at 11:55 pm)

  1. Write the formal specification for min(v), where v is a vector of integers. Function min returns the smallest element of the vector.
  2. Write the formal specification for function rotateRight(v), where v is a vector of integers. Function rotateRight moves each element in the vector one space to the right and moves the last element of the vector to the beginning of the vector.
  3. Write the formal specification for function largestLast(v), where v is a vector of integers. Function largestLast swaps the positions of the largest element in the vector and the last element in the vector.

A3 (due 1/24 at 11:55 pm)

Write the sort function that satisfies the following Hoare triple. Publish your code on RPubs. Include a paragraph that describes the efficiency of your function.

\( \{v = V \wedge v.size = N\} \)
\( v :=\,? \)
\( \{\mathrm{perm}(v,V) \wedge (\forall i | 0 \le i \lt N \wedge v[i] \,\mathrm{mod}\, 2 = 1 : (\forall j | 0 \le j \lt N \wedge v[j] \,\mathrm{mod}\, 2 = 0:i \lt j))\} \)

A4 (due 1/27 at 11:55 pm)

Publish the following RECURSIVE functions, one per slide, on RPubs. Publish only the functions. Do not publish main().

  1. Write the recursive function double max(double v[], int numItems) that returns the largest value in array v.
  2. Write the recursive function int pow2(int k) that returns the kth power of 2, assuming k is nonnegative. For example
  3. Write the recursive function int count(int v[], int x, int numItems) that returns the number of times x occurs in v.

A5 (due 1/30 at 11:55 pm)

Publish the following RECURSIVE functions, one per slide, on RPubs. Publish only the functions. Do not publish main().

  1. Write the recursive version of bool neighbor13(int v[], int numItems) that returns true if two adjacent elements in v add to 13, and false otherwise.
  2. Write the recursive version of void rotateRight(int v[], int numItems).