CSC 600 Procedural programming

CSC 600 Procedural programming

1. Plateau program (max sequence length) (a combinatorial algorithm)
The array a(1..n) contains sorted integers. Write a function maxlen(a,n) that returns the
length of the longest sequence of identical numbers (for example, if
a=(1,1,1,2,3,3,5,6,6,6,6,7,9) then maxlen returns 4 because the longest sequence 6,6,6,6
contains 4 numbers. Write a demo main program for testing the work of maxlen. Explain
your solution, and insert comments in your program. The solution should have the time
complexity O(n).
2. Integer plot function (find a smart way to code big integers)
Write a program BigInt(n) that displays an arbitrary positive integer n using big
characters of size 7×7, as in the following example for BigInt(170):

Write a demo main program that illustrates the work of BigInt(n) and prints the following
sequence of big numbers 1, 12, 123, 1234, …, 1234567890, one below the other.
3. Array processing (elimination of three largest values) (one of many array reduction
problems)

The array a(1..n) contains arbitrary integers. Write a function reduce(a,n) that reduces
the array a(1..n) by eliminating from it all values that are equal to three largest different
integers. For example, if a=(9,1,1,6,7,1,2,3,3,5,6,6,6,6,7,9) then three largest different
integers are 6,7,9 and after reduction the reduced array will be a=(1,1,1,2,3,3,5), n=7. The
solution should have the time complexity O(n).
4. Iteration versus recursion (an opportunity for performance measurement)
Make a sorted integer array a[i]=i, i=0,…,n-1. Let bs(a,n,x) be a binary search
program that returns the index i of array a[0..n-1] where a[i]=x. Obviously, the result is
bs(a,n,x)=x, and the binary search function can be tested using the loop

DETAILED ASSIGNMENT

20200928074516hw_procedural_programming.4

Powered by WordPress