Consider the following process to run on a positive integer n: if n is a multiple of 3, divide by 3. If n % 3 = 1, then multiply by 2 and add 1. If n % 3 = 2, then multiply by 2 and add 2. Find all possible loops, and prove that if you start with any integer n, you will end up in one of these loops.

2. Consider the following process to run on a positive integer n: if n is a multiple of 3, divide by 3. If n % 3 = 1, then multiply by 2 and add 1. If n % 3 = 2, then multiply by 2 and add 2. Find all possible loops, and prove that if you start with any integer n, you will end up in one of these loops.
3. Write pseudocode for a simple algorithm for addition of two n-digit numbers (one of them could be < n digits with 0's appended to the left) in base-10, as follows. Assume the digits are stored in arrays A and B, with A[1] and B[1] being the rightmost digits and A[n] and B[n] being the leftmost digits. Use a for loop to go from right to left adding the digits and keeping track of the carry. Now, here's the real task: write a loop invariant that is true each time the loop iterates, prove that it is indeed an invariant, and that the algorithm therefore accomplishes the goal. You may wish to read pp. 31-33 for an example for Merge Sort and pp. 18-19 for an example for Insertion Sort (or even Quicksort in Chapter 7). 4. Give pseudocode for a method to reduce the Maximum Subarray problem to the Stock Market problem. In other words, for any given Maximum Subarray (MSA) problem, find an equivalent Stock Market problem (SMP) such that any solution to the SMP problem gives a solution to the MSA problem, and any solution to the original MSA problem comes from a solution to the SMP problem.

Last Completed Projects

topic title academic level Writer delivered