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
Perfect explanation!!
Your way of teaching is very good.
Thanks a lot
explanation is visually awesome teaching, clarity wow
💥💥💥💥Congrats for Advance success of your channel ..I try to share to most of my friends
Thank you so much 😀
Sir shall I return h instead of using res?
Wonderful ❤❤❤
Wow amazing sir
visually look like avatar 3.0 wow clear, awesome
Very good explanation sir😊
Amazing brother wow
Sir how you learned this dsa sir because your teaching is extraordinary sir
if the testcase is 2 it returns 0 but it should be 1
yess u got it bro
Take the high value (n/2) + 1 ...that will do the job