Given a number n, find the cube root of n.
Input: n = 3 Output: Cubic Root is 1.442250 Input: n = 8 Output: Cubic Root is 2.000000
We can use binary search. First we define error e. Let us say 0.0000001 in our case. The main steps of our algorithm for calculating the cubic root of a number n are:
- Initialize start = 0 and end = n
- Calculate mid = (start + end)/2
- Check if the absolute value of (n – mid*mid*mid) < e. If this condition holds true then mid is our answer so return mid.
- If (mid*mid*mid)>n then set end=mid
- If (mid*mid*mid)<n set start=mid.
Below is the implementation of above idea.
Cubic root of 3.000000 is 1.442250
Time Complexity : O(Log n)
This article is contributed by Madhur Modi .If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Find the integral roots of a given Cubic equation
- Program to check if N is a Centered Cubic Number
- Find root of a number using Newton's method
- C program to find square root of a given number
- Find Cube root of a number using Log function
- Find Nth positive number whose digital root is X
- Find square root of number upto given precision using binary search
- Form the Cubic equation from the given roots
- Cubic Bezier Curve Implementation in C
- Nth root of a number using log
- N-th root of a number
- Find Square Root under Modulo p | Set 1 (When p is in form of 4*i + 3)
- Square root of a number using log
- Program to find root of an equations using secant method
- Smallest root of the equation x^2 + s(x)*x - n = 0, where s(x) is the sum of digits of root x.
- Long Division Method to find Square root with Examples
- Find Square Root under Modulo p | Set 2 (Shanks Tonelli algorithm)
- Print a number containing K digits with digital root D
- Primitive root of a prime number n modulo n
- Square root of a number without using sqrt() function
Improved By : nitin mittal