@Dav....hw can u compute in contant time where runing time dwepends
on elements of array e.g.
its has complexcity O(n).... isn'tit..??????
import java.util.Arrays;
import java.util.LinkedList;
class SolutionFinder
{
public static void find(final LinkedList<Integer> remaining, final
LinkedList<Integer> found)
{
if (remaining.size() == 0) // We made it through the whole list, this
is a solution
{
for (final Integer curr : found)
{
System.out.printf("%d ", curr);
}
}
else
{
for (int i = 0; i < remaining.size(); i++)
{
final Integer next = remaining.get(i);
System.out.print("next \t" + next);
int size=found.size()-1;
Integer fnd=found.get(size);//always return last
System.out.print("\t fnd \t" + fnd + "\n");
if (Arrays.asList(4, 9, 16, 25).contains(fnd+ next))
{
found.add(remaining.remove(i));
find(remaining, found);
remaining.add(i, found.remove(found.size() - 1));
}
}
}
}
public static void main(final String[] args)
{
final LinkedList<Integer> remaining = new LinkedList<Integer>();
final LinkedList<Integer> found = new LinkedList<Integer>();
for (int i = 1; i <= 15; i++)
{
remaining.add(i);
}
found.add(16);
find(remaining, found);
}
}
Right me if i m wrong
Regard's
Shashank Mani Narayan " Don't Be Evil U Can Earn While U learn"
Computer Science & Engineering
Birla Institute of Technology,Mesra
Cell No. +91-9166674831
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.