Program To Find Square Root/Floor Of Square Root Of A Number | FREE DSA Course in JAVA | Lecture 64

Поділитися
Вставка
  • Опубліковано 3 жов 2024
  • Given an integer N, compute and return the square root of N. If N is not a perfect square then return floor (sqrt (N)). Do not use SQRT function from the standard library.
    Note - Don't use the sort function from the standard library. Users are expected to solve this question with O (log (N)) time complexity.
    So this isn't another square root finding program and hence it was asked in companies like Amazon, Microsoft, VM ware, etc.
    We can solve this question using the binary search algorithm. It is because we have a sequentially increasing array of 1 to the number where we will find the square root.
    For eg, to find the square root of 16, it will surely be between 1,2,3, ............., 16.
    Moreover, this is also certain that square root will be available between 1 to 8 ie 1 to n/2.
    Hence we have to use the binary search algorithm to find the square root of a number.
    Let's see how we can write the logic for the program and also how we can find the floor of the square root if the number is not a perfect square.
    For more information, fill out this form: forms.gle/8eiU...
    or call us at 8884881203
    Facebook: / thetapacademy
    Instagram: / tapacademy_online
    Linkedin: / 73820805
    Website: www.thetapacad...​
    #java #javaprogramming #coding #coder #dsa #javatutorial #arrayjava

КОМЕНТАРІ • 17