Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started