is there any general algo for this question,ie, upto any n(here 16) ? ? On Sep 15, 2:46 am, Minotauraus <anike...@gmail.com> wrote: > I guess the problem could be modified for any 1..n where n is 2^m. > so say 1....32 > or 1...64 > Try it out. It still works! The time complexity in this case is O(log > n). > > On Sep 14, 6:02 am, Dave <dave_and_da...@juno.com> wrote: > > > > > @Bittu: First, it makes no sense to say O(n) when n is fixed. Second, > > if you know the solution, a program to print it out just consists of a > > printf statement, e.g., > > > printf("16, 9, 7, 2, 14, 11, 5, 4, 12, 13, 3, 6, 10, 15, 1, 8\n"); > > > plus whatever language stuff you need to get it to compile and run. > > > Dave > > > On Sep 14, 4:26 am, bittu <shashank7andr...@gmail.com> wrote: > > > > @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 algoge...@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.