This condition is very ambiguous as assuming e much greater than x will result in x itself ( loop condition fails).

I understand , in exam most appropiate option is to be chosen

But what if, another option given as 'x'

?

The Gateway to Computer Science Excellence

+44 votes

Best answer

+1

The input value of X in expression 1 is different from th einput value of X in expression 2.

How can we substitute expression 2 in 1? we need to do vice varsa right? though both gives same answer

How can we substitute expression 2 in 1? we need to do vice varsa right? though both gives same answer

+1

Yes, the ans draw is **seeming** correct.

But i think @exam we cant rely and put ans like this.

**Reason1->>**In Ans they have not considered condition **While (x-y > ϵ)**

**Reason2->>**How can u put step2 in step1 without executing step1 cz Program runs sequentially.

0

>>>Yes, time complexity is O(loglogn) as the subproblem size is getting shrinked by √n

I think this statement is not correct. This is a numerical method of computing square root.

0

I think none of the answers is correct here ... assume m = 4 and epsilon = 8

(4-1=3) is not greater than 8

so print x which is 4

None of them matches right . ?

(4-1=3) is not greater than 8

so print x which is 4

None of them matches right . ?

+1

Since when do we consider the "=" operator as an equal to sign? Its a value assignment operator and by that logic statements like a= a+b would be completely absurd. We cannot make a quadratic equation out this even if it might be close to the answer.

0

Refer to @sakht launda answer and link (in the bottom most part) , that seems accurate enough to answer all queries and aspect related to code and complexity as well.

+16 votes

First of all this question is about approximation of value. So we can do 1 step more or less. That will not affect the answer.

Answer given by @gate_asp is somehow appropriate, but it doesn't answer some questions which are mentioned in comments.

So here is my ans.

loop will terminate in (Log Log n) iterations. at that time if x is a perfect square number then it x = y = $m^{1/2}$

otherwise it will terminate with condition y > x.

+10 votes

take m=8 and trace the Algorithm and verify the options A.3 B.64 C.2$\sqrt{2}$=2.82 D.3

Imp Note:-> we cant take variable type as int (cz it is an algorithm as specified in question) if U do so we end up with incorrect result

Now Trace the algorithm

Initially m=8 , $\epsilon$=1 , x=8 , y=1

Iteration # | x | y | while(x - y >1) |

1 | 8 | 1 | True |

2 | 4.5 | 1.78 | True |

3 | 3.14 | 2.55 | True |

4 | 2.85 |
2.8 | False |

So it match with Option C .

+8 votes

This is an implementation of Babylonian method for square root - http://www.geeksforgeeks.org/square-root-of-a-perfect-square/

its time complexity is - log(log(n/e)) -https://stackoverflow.com/questions/12309432/time-complexity-for-babylonian-method

- All categories
- General Aptitude 1.9k
- Engineering Mathematics 7.5k
- Digital Logic 2.9k
- Programming and DS 4.9k
- Algorithms 4.4k
- Theory of Computation 6.2k
- Compiler Design 2.1k
- Databases 4.1k
- CO and Architecture 3.4k
- Computer Networks 4.2k
- Non GATE 1.4k
- Others 1.4k
- Admissions 595
- Exam Queries 573
- Tier 1 Placement Questions 23
- Job Queries 72
- Projects 18

50,737 questions

57,341 answers

198,451 comments

105,212 users