Docsity

Programming Assignment 3: Measuring Program Efficiency and Improvement - Prof. Chung-Chih , Assignments of Information Technology

Toggle sidebar
bg1
ITK 179, Fall 2008 Programming Assignment 3, 30 points
Due: Oct. 6, Monday
In this assignment we will practice how to measure the efficiency of your programs and do your best to
improve your programs.
1. Let A[ ] and B[ ] be two arrays of integers, each has nelements, where n > 0. Consider the following
two tasks.
(a) i. Put nrandom values into Aso that A[0], A[1], . . . A[n−1] are ndistinct random integers
between 0 and n−1. (Note that all number in Amust be distinct.)
ii. Then, calculate Bsuch that for 0 ≤i < n, B[i] = A[0] + A[1] + · · · +A[i].
(b) i. Put nrandom values into Aso that A[0], A[1], . . . A[n−1] are nrandom integers between
0 and n−1 (Note that the numbers need not to be distinct.)
ii. Then, calculate Bsuch that for 0 ≤i < n, B[i] = A[0] + A[1] + · · · +A[A[i]].
Hint: Use Math.rondom() to get a random double between 0 and 1 (not including 1).
2. For each task, add a counter to count the number of times an array elements referred.
3. Use the following method to calculate the elapse (in milliseconds) for the completion of each task.
start = System.currentTimeMillis();
..... your task .....
end = System.currentTimeMillis();
elapse = end - start;
where start, end, and elapse are all long.
4. Write a loop to perform each task for n= 101,102, . . . 106. Compare the number obtained in the
counter, your analysis obtained by paper-and-pencil in terms of the array size n, and the actual time
elapse.
5. What is the complexity of your program for each task in terms of the big-O notation? Can you
improve your algorithms? If you think you can, how? If not, why not? Explain your reason in
details.
Extra 10 points:
As previous assignments, you are encouraged to implement this assignment on your Unix account. Put all
your works in the directory /ITK179/Asg3 under your home directory. (Note: Unix is case sensitive.) If
you decide to do so, you have to change the mode of the directory to readable for every one after the
due date, so I can grade your work. You still have to write up a report and submit a hard copy. However,
you don’t have to websubmit your programs. You have to keep your work in your account to the end of
the semester.
Note: Follow the instructions for submission. (No late work will be accepted)
Due: Oct. 6, Monday c
Chung-Chih Li P-1/1

Partial preview of the text

Download Programming Assignment 3: Measuring Program Efficiency and Improvement - Prof. Chung-Chih and more Assignments Information Technology in PDF only on Docsity!

ITK 179, Fall 2008 Programming Assignment 3, 30 points

Due: Oct. 6, Monday

In this assignment we will practice how to measure the efficiency of your programs and do your best to improve your programs.

  1. Let A[ ] and B[ ] be two arrays of integers, each has n elements, where n > 0. Consider the following two tasks.

(a) i. Put n random values into A so that A[0], A[1],... A[n − 1] are n distinct random integers between 0 and n − 1. (Note that all number in A must be distinct.) ii. Then, calculate B such that for 0 ≤ i < n, B[i] = A[0] + A[1] + · · · + A[i].

(b) i. Put n random values into A so that A[0], A[1],... A[n − 1] are n random integers between 0 and n − 1 (Note that the numbers need not to be distinct.) ii. Then, calculate B such that for 0 ≤ i < n, B[i] = A[0] + A[1] + · · · + A[A[i]].

Hint: Use Math.rondom() to get a random double between 0 and 1 (not including 1).

  1. For each task, add a counter to count the number of times an array elements referred.
  2. Use the following method to calculate the elapse (in milliseconds) for the completion of each task. start = System.currentTimeMillis(); ..... your task ..... end = System.currentTimeMillis(); elapse = end - start; where start, end, and elapse are all long.
  3. Write a loop to perform each task for n = 10^1 , 102 ,... 106. Compare the number obtained in the counter, your analysis obtained by paper-and-pencil in terms of the array size n, and the actual time elapse.
  4. What is the complexity of your program for each task in terms of the big-O notation? Can you improve your algorithms? If you think you can, how? If not, why not? Explain your reason in details.

Extra 10 points:

As previous assignments, you are encouraged to implement this assignment on your Unix account. Put all your works in the directory /ITK179/Asg3 under your home directory. (Note: Unix is case sensitive.) If you decide to do so, you have to change the mode of the directory to readable for every one after the due date, so I can grade your work. You still have to write up a report and submit a hard copy. However, you don’t have to websubmit your programs. You have to keep your work in your account to the end of the semester.

Note: Follow the instructions for submission. (No late work will be accepted)

Due: Oct. 6, Monday ©c Chung-Chih Li P-1/