[algogeeks] Re: Obtaining each digit from an integer in Java.

2006-09-22 Thread Mukul Gandhi
This is a complete Java program doing this: class X { public static void main(String[] args) { int n = 5732; int len = ((new Integer(n)).toString()).length(); int[] array = new int[len]; for (int i = 0; i < len; i++) { String x = ((new Integer(n)).toStr

[algogeeks] Re: Intersection of 2 rectangles

2006-08-03 Thread Mukul Gandhi
How do you specify the 2 rectangles? For e.g. do you specify the (x,y) coordinates of the 4 vertices of both the rectangles? Regards, Mukul --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. T

[algogeeks] Re: function to print all permutations of a string

2006-07-21 Thread Mukul Gandhi
anurag wrote: > write a function to print all permutations of a string.can anyone > please help me Here is a generic program (written in Java) which does this for a collection of objects. You can easily adapt it for a string. import java.util.List; import java.util.Iterator; import java.util.Col

[algogeeks] Re: To find cartesian product of sets

2006-04-26 Thread Mukul Gandhi
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.readL

[algogeeks] Re: To find cartesian product of sets

2006-04-26 Thread Mukul Gandhi
I experimented with your suggestion 1. Following is the modified function public static void cross(List sets) throws Exception { if (sets.size() == 2) { FileWriter op1 = new FileWriter("temp.txt"); FileWriter op2 = new FileWriter("out.txt"); for (int i = 0; i < ((Integer[])set

[algogeeks] Re: To find cartesian product of sets

2006-04-25 Thread Mukul Gandhi
Just to add to my question, I would like the cartesian product program to scale upto 81 sets, and the cardinality of each set can be maximum 9. I calculated that the resulting cartesian product will have 1.9662705047555291361807590852691e+77 elements. I think it is difficult to store this cartesi

[algogeeks] Re: Finding the k largest/smallest elements in the array !

2006-04-25 Thread Mukul Gandhi
I think you are right. Thanks for your comments.. 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 unsubscri

[algogeeks] Re: Finding the k largest/smallest elements in the array !

2006-04-24 Thread Mukul Gandhi
Please see here http://www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/Sorting/bubbleSort.htm It says the parallel time complexity of this algorithm is O(n).. Regards, Mukul --~--~-~--~~~---~--~~ You received this message because you are subscribed to th

[algogeeks] To find cartesian product of sets

2006-04-24 Thread Mukul Gandhi
I am trying to find cartesian product of sets(with integer elements) using Java. I have written a program as shown below. import java.util.List; import java.util.ArrayList; public class SetUtil { public static ArrayList cross(List sets) { ArrayList result = new ArrayList(); if (s

[algogeeks] Re: Finding the k largest/smallest elements in the array !

2006-04-24 Thread Mukul Gandhi
Since the iterations of nested for loop are done in parallel, the complexity is O(n).. 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 al

[algogeeks] Re: Finding the k largest/smallest elements in the array !

2006-04-19 Thread Mukul Gandhi
Parallel bubble sort (shown below) has O(n) complexity. PARALLEL BUBBLE SORT (A) For k = 0 to n-2 If k is even then for i = 0 to (n/2)-1 do in parallel If A[2i] > A[2i+1] then Exchange A[2i] ↔ A[2i+1] Else for i = 0 to (n/2)-2 do in parallel If A[2i+1] > A[2i+2