Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Spring 2004
Instructions:
1. Write neatly and legibly 2. While grading, not only your final answer but also your approach to the problem will be evaluated 3. You have to attempt only TWO problems. If you attempt more than two problems, we will grade ANY two problems of OUR choice 4. Each problem carries 10 points 5. Total time for the exam is 50 minutes 6. You are not allowed to use a calculator for this exam I have read carefully, and have understood the above instructions. On my honor, I have neither given nor received unauthorized aid on this examination. Signature: _____________________________________ Date: ____ (MM) / ____ (DD) / ___________ (YYYY)
On-Campus Exam #1
Page 1 of 8
On-Campus Exam #1
Page 2 of 8
On-Campus Exam #1
Page 3 of 8
On-Campus Exam #1
Page 4 of 8
Question 2: We have an array of sorted distinct numbers that is infinitely long. The first n numbers are fractions that are greater than 0 but less than 1. All the remaining elements are 1s, and you are not given the value of n. You need to develop an algorithm to check if a user-given fraction F occurs in that array. Analyze the time complexity of your algorithm as a function of n. (An example for n=8) 1 0 2 3 0.23 0.3 4 0.4 5 0.5 6 0.6 7 0.9 8 1 9 1 10 1 11 1 12 1 .. 1 .. 1 .. 1
On-Campus Exam #1
Page 5 of 8
On-Campus Exam #1
Page 6 of 8
Question 3: You are the TA for a class with an enrollment of n students. You have their final scores (unsorted), and you must assign them one of the G available grades (A, B, C etc.). The constraints are (assuming n is a multiple of G): Exactly (n/G) students get each grade (for example, if n = 30, and G = {A,B,C}, then exactly 10 students get A, 10 get B, and 10 get C) A student with lower score doesnt get a higher grade than a student with a higher score (however, they may get the same grade) Assuming that each student received a different score, derive an efficient algorithm and give its complexity in terms of n and G. Any algorithm that first sorts the scores will receive zero credit.
On-Campus Exam #1
Page 7 of 8
On-Campus Exam #1
Page 8 of 8