MidTerm2F08MW-Sol - 1/7 EE 322C Fall 2008 Second Mid-Term...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1/7 EE 322C Fall 2008 Second Mid-Term Solution Dr. Ramesh Yerraballi MW Class Full Name : Solver King Duration : 75 minutes Note: To earn partial credit you have to provide your work and not just give the final answer 1. [ 25 points ] Answer the following i. [ 10 points ] For the typical algorithms that you use to perform calculations by hand, determine the time complexity (big-O) to: [One-line answers will suffice if you are correct] a. [ 3 points ] Add two N-digit integers [Note: 1234 + 2341 is addition of two 4-digit numbers (N=4); You may assume that adding two digits takes a constant time] O(N) : Adding two N-digit numbers involves adding each digit in turn with a possible carry in and carry out. N additions of constant time (c) each gives cN, which is O(N) b. [ 4 points ] Multiply two N-digit integers O(N 2 ) Multiplying two N-digit numbers (A x B say) is the same as successively adding the multiplicand (A) a multiplier (B) number of times. This involves N additions of N-bit numbers, which makes it N 2 total additions. Of course you could use the more common technique for multiplication by hand which is: multiply A by the first digit in B and add it to the result from multiplying A by the second digit in B and shifting the result one position and repeating this process for the third, fourth and N’th digit. This also takes O(N 2 ). The reasoning is as follows: Each multiplication is a maximum of 9 N-digit additions ( O(9*N) = O(N)) and the shift is a O(N) operation, so the cost of this step is O(N); There are N such steps which gives us a total complexity of O(N 2 ). c. [ 3 points ] Determine whether an N-digit integer is odd or even O(1) : Constant time because all you need to look at is the least significant digit and divide it by 2 to see if the remainder is 0 or 1. None of the steps depend on N.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2/7 ii. [15 points] Consider an array A of length N , where each element of the array is a 0 or a 1 . Describe in pseudo-code (or java if you prefer) a linear-time algorithm to find the Longest Contiguous Sequence of 1 ’s in the array. If there are no 1 ’s in the array then the Longest Contiguous Sequence is zero. [Note: If A=[011000100110
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/26/2009 for the course EE 322C taught by Professor Nettles during the Spring '08 term at University of Texas at Austin.

Page1 / 7

MidTerm2F08MW-Sol - 1/7 EE 322C Fall 2008 Second Mid-Term...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online