Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

(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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

More Books

Students also viewed these Databases questions