Thanks for your comments..

I feel, this portion of code can be optimized as per your suggestion
(I'll try to measure the improvement)

>  BufferedReader temp = new BufferedReader(new FileReader("out.txt"));
>  FileWriter ot = new FileWriter("temp.txt");
>  String l = "";
>  while ((l = temp.readLine()) != null) {
>    ot.write(l+"\n");
>   }

But the file reading and writing code below it cannot be optimized as
you have told. Otherwise cartesian product logic won't work.
(
I just observe I unnecessarily used the StringTokenizer in this portion
of code. I can instead write
  while ((line = in.readLine()) != null) {
     for (int j = 0; j < x.length; j++) {
       out.write(line+" ");
       out.write(x[j].toString()+"\n");
   }
 }

)

But I am actually not interested in computing the whole cartesian
product and storing it somewhere, and finally using it.

In the actual problem I am solving, *I need to determine only one
member of cartesian product which satisfies a certain condition*. The
number of sets can be maximum 81, and each set can have maximum
cardinality 9. As per the programs I have posted so far, I have to
first compute the full cartesian product(and store it somewhere) and
then iterate the whole cartesian product to determine which member
satifies a condition. This is a huge waste of secondary/primary storage
and time. The ideal way I need is, that I could iterate the cartesian
product only once(probably while computation), efficiently, and exit
when a particular member meets a certain condition.

I am eager to know such an algorithm..

Regards,
Mukul


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to