This
** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*
**Unformatted text preview: **Assignment #2 CS4/531 Due Date: Mon. Oct. 3, 2011 UNSUPPORTED SOLUTIONS RECEIVE NO CREDIT. Total points: 53 • You MUST turn in your HW by 2:10pm on Oct 3. After that, I will NOT accept your HW. This rule will be STRICTLY ENFORCED. • Please PRINT YOUR LAST NAME, FIRST NAME and UB number on the first page. • Write solution of each problem on a separate sheet. Staple them in the order of problem numbers. • If your homework solution deviates significantly from these guidelines, TA may deduct up to 20% of the points. 1. (5 pts) Let a be a real number and n a positive integer. We want to compute a n . This, of course, can be done using n- 1 multiplications. Describe an algorithm that computes a n using O (log n ) basic arithmetic operations. Note: A basic arithmetic operation is one of the following: x + y , x- y , x × y , x/y (which returns the integer part of x divided by y ); and ( x mod y ) (which returns the remainder of x divided by y ). But, x y is NOT a basic arithmetic operation. Although most programming languages allow this operation, x y is calculated by a subroutine, not by a CPU instruction. 2 (8 pts). We discussed the Fibonacci numbers in class. To calculate Fib( n ), the recursive function (using the recursive definition) takes exponential time. The simple for loop functionfunction (using the recursive definition) takes exponential time....

View
Full
Document