Click here to Skip to main content
15,886,137 members
Home / Discussions / Algorithms
   

Algorithms

 
QuestionRe: Can someone please help me optimize(decrease time complexity) this algorithm.. Pin
claymorehack18-May-18 3:38
claymorehack18-May-18 3:38 
AnswerRe: Can someone please help me optimize(decrease time complexity) this algorithm.. Pin
Richard MacCutchan18-May-18 5:59
mveRichard MacCutchan18-May-18 5:59 
QuestionAlgorithm for golf putting. Slope 1-4 degrees Pin
Member 1375000827-Mar-18 11:06
Member 1375000827-Mar-18 11:06 
AnswerRe: Algorithm for golf putting. Slope 1-4 degrees Pin
Gerry Schmitz2-Apr-18 6:01
mveGerry Schmitz2-Apr-18 6:01 
Questionrecursive algorithm Pin
Member 1374335523-Mar-18 7:00
Member 1374335523-Mar-18 7:00 
AnswerRe: recursive algorithm Pin
Gerry Schmitz23-Mar-18 12:00
mveGerry Schmitz23-Mar-18 12:00 
AnswerRe: recursive algorithm Pin
Peter_in_278023-Mar-18 14:53
professionalPeter_in_278023-Mar-18 14:53 
QuestionSquare root of positive integer using binary search. Pin
lnikon25-Feb-18 9:40
lnikon25-Feb-18 9:40 
Hello everyone!
I've a follow question: is there any way to optimize this algorithm, which recursively computes the square root of an positive integer?.

C++
int mySqrt(int x, int left, int right)
{
    static int result = 0;
    if (left <= right)
    {
        int middle = left + (right - left) / 2;
        if ((middle != 0 && middle <= x / middle) ||
            (middle == 0 && middle <= x / (middle + 1)))
        {
            result = middle;
            return mySqrt(x, middle + 1, right);
        }
        else
        {
            return mySqrt(x, left, middle - 1);
        }
    }
    return result;
}


Thank you!
GeneralRe: Square root of positive integer using binary search. Pin
harold aptroot25-Feb-18 10:29
harold aptroot25-Feb-18 10:29 
GeneralRe: Square root of positive integer using binary search. Pin
lnikon25-Feb-18 10:54
lnikon25-Feb-18 10:54 
AnswerRe: Square root of positive integer using binary search. Pin
Richard Deeming26-Feb-18 1:21
mveRichard Deeming26-Feb-18 1:21 
AnswerRe: Square root of positive integer using binary search. Pin
Patrice T7-Apr-18 21:01
mvePatrice T7-Apr-18 21:01 
Question3D Points to 2D Points Pin
Member 1368222216-Feb-18 15:34
Member 1368222216-Feb-18 15:34 
AnswerRe: 3D Points to 2D Points Pin
Ralf Meier17-Feb-18 0:35
mveRalf Meier17-Feb-18 0:35 
GeneralRe: 3D Points to 2D Points Pin
jschell17-Feb-18 11:41
jschell17-Feb-18 11:41 
GeneralRe: 3D Points to 2D Points Pin
Ralf Meier17-Feb-18 23:02
mveRalf Meier17-Feb-18 23:02 
QuestionNode discovery in a truly decentralized system Pin
stopthespying15-Feb-18 6:40
stopthespying15-Feb-18 6:40 
AnswerRe: Node discovery in a truly decentralized system Pin
Gerry Schmitz16-Feb-18 5:21
mveGerry Schmitz16-Feb-18 5:21 
QuestionFinding strongly connected component in a directed Graph using PHP Pin
Member 136573131-Feb-18 21:22
Member 136573131-Feb-18 21:22 
QuestionA very interesting question for you all Pin
Member 1364484725-Jan-18 14:28
Member 1364484725-Jan-18 14:28 
AnswerRe: A very interesting question for you all Pin
Richard MacCutchan25-Jan-18 22:26
mveRichard MacCutchan25-Jan-18 22:26 
AnswerRe: A very interesting question for you all Pin
jschell8-Feb-18 13:33
jschell8-Feb-18 13:33 
AnswerRe: A very interesting question for you all Pin
Luc Pattyn8-Feb-18 14:59
sitebuilderLuc Pattyn8-Feb-18 14:59 
Questionpython code on Effect of order of accuracy on the numerical differentiation Pin
Member 1362564316-Jan-18 1:32
Member 1362564316-Jan-18 1:32 
GeneralRe: python code on Effect of order of accuracy on the numerical differentiation Pin
harold aptroot17-Jan-18 23:28
harold aptroot17-Jan-18 23:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.