Algo

loop down  array find 2 elements such that c= sqrt(a*a + b*b)
& compare if( c*c ==a*a+b*b) //can be optimized we can leave this line
just writing fro clarification  if yes prints all the combination

For This I Have  A Gud Working Solution  which has time complexity of
O(n^2)

Lets genralize this question fro some k & say k=100 means we wants to
find out all triplets which is less then kth (here 100)   number

so
         int n=100;
         void doit()
         {
                int n2 = n*n;
                int count = 0;

                for (int a=0; a<=n; ++a)
                        for (int b=a; b<=n && a*a+b*b<=n2;++b)
                        {
                                int c = (int) Math.sqrt(a*a + b*b);
                                if (c*c == a*a + b*b)
                                {
                                        printf("(" + a + ", " + b + ", " + c + 
") ");
                                        count++;
                                }
                        }

                printf("There are " + count + " combinations.");
        }

In Case of Array we need to put a[i] e.g. array elements for which we
need to find out triplets that is also On^n)
solution .....Optimization with Others are welcomes.
But this algo will works fine. will not led any error.

Please Write Comment if Anything Wrong with above program or how we
can improve optimize it..because after analyzing u will find that so
many steps
unnecessary calculated ..although we don't want that...


Thanks & Regards
Shashank Mani "don't B evil U Can Earn While U Learn"



-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to