Question: (4) ( 8pts) Given a positive integer n that is a perfect square (i.e. its square root is an integer: for example, n=25), present an

 (4) ( 8pts) Given a positive integer n that is a

(4) ( 8pts) Given a positive integer n that is a perfect square (i.e. its square root is an integer: for example, n=25), present an algorithm to output square root of n. Your algorithm needs to run in O(logn) time. Obviously, you cannot invoke any predefined function to compute the square root. Hint: You want to search for n in 12(n1)n. A note on style The following is the pseudo-code I will write for the problem of finding the number of even integers in A[p] through A[r]. You may use this as guideline. Number-of-Even (A, p, r) \{ count =0; // scan the entries and find how many are even for i=p to r if ( A[i] is even) count = count +1;// or, count++; return count; \} The above is only to give you an idea of suggested style. In reality, in the future, the following is acceptable so long as you claim a complexity of O(r p+1). count = number of even entries in A[p]A[r]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!