Re: [algogeeks] Re: Array Merge Problem

2011-06-06 Thread Aakash Johari
@ross: I couldn't get reddy's solution. Please explain.

On Sun, Jun 5, 2011 at 10:50 PM, Deepak Jha deepak.127.0@gmail.comwrote:

 the below solution should work given the input array is sorted ( I am
 assuming ascending order)
 void rearrangeArray(int[] a, int[] b){
 int m = a.length;
  int n = b.length;
 int i = m - 1;
 int j = 0;
  while((i =0)  (j = n-1)){
 if(a[i]  b[j]){
 int temp = a[i];
  a[i] = b[j];
 b[j] = temp;
 }
  i--;
 j++;
 }
  }

 On Sat, Jun 4, 2011 at 2:29 PM, ross jagadish1...@gmail.com wrote:

 Hi Rohit  all,
 Sorry that there was a small typo in the 'n' 'm' texts.
 The example given by me is anyway the correct one.
 Sravan Reddy's solution worked fine.

 On Jun 4, 10:08 am, rohit rajuljain...@gmail.com wrote:
  i think solution would be like this
 
  eg:
  A : 1 2 3 B: 0 1.5 4 5 9
  Output:
  A can contain any combination of nos 0,1,1.5
  and B should contain 2 3 4 5 9 (in any order.)
 
  this example is given by ROSS itself.
 
  so sravanreddy solution is right , correct me if i'm wrong.
 
  On Jun 3, 8:07 pm, bittu shashank7andr...@gmail.com wrote:
 
 
 
 
 
 
 
   @sravanreddy...logical bugs  if A is size of n  B is size m from your
   example  assuming nm  so if you want smallest m elements in A then u
   only capacity of n elements  didn't allocate memory so these elements
   initialized by INT_MIN for m-n nodes so thatarrayA can hold m
   smallest elements then what r u swapping u dude..isn't garbage
   value ?? you will get at 1st step only just run it ?? in you algo
   A_End=m-1(which 4th position inArraythat DNE)..??  also you have to
   free memory for  m-n  inarrayB as it contains n largest elements .
 
   take
   A= 1,2,3 n=3
   B= 0,1,4,5,9 m=5
 
   after allocating memory toArrayA  for  m-n elements A will looks
   likes 1 2 3 INT_Max INT_Max
   now what you wants A should contains m smallest elements  B have n
   largest elements
   so O/P should be  A=1,2,3,1,0  B=INT_Max,INT_Max,4,5,9 now free
   memory used by 1st elements inarrayB so that A will represent M
   smallest elements  B will have n Largest elements
 
   so that above will work.
 
   Hope I am Correct let me know if any issue with explanation
 
   Thanks
   ShashankThe Best Way To Escape From Theproblemis To Solve It
   CSE,BIT Mesra

 --
 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.


  --
 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.




-- 
-Aakash Johari
(IIIT Allahabad)

-- 
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.



[algogeeks] Re: Array Merge Problem

2011-06-06 Thread ross
@aakash Johari:
Let a and b be the 2 arrays.
At each stage of the process, if an element of A is greater than B,
then swap the largest element of A with the smallest element of B
and adjust pointers.

A : 2 4 15 12
B : 0.2 1  33 44

Now, 20, therefore swap 0 with 12..
Every step of the process, gets in the smallest elemnt of A and swaps
it
with the largest element of B.

Hope its clear.


On Jun 6, 11:15 am, Aakash Johari aakashj@gmail.com wrote:
 @ross: I couldn't get reddy's solution. Please explain.

 On Sun, Jun 5, 2011 at 10:50 PM, Deepak Jha deepak.127.0@gmail.comwrote:









  the below solution should work given the input array is sorted ( I am
  assuming ascending order)
  void rearrangeArray(int[] a, int[] b){
  int m = a.length;
   int n = b.length;
  int i = m - 1;
  int j = 0;
   while((i =0)  (j = n-1)){
  if(a[i]  b[j]){
  int temp = a[i];
   a[i] = b[j];
  b[j] = temp;
  }
   i--;
  j++;
  }
   }

  On Sat, Jun 4, 2011 at 2:29 PM, ross jagadish1...@gmail.com wrote:

  Hi Rohit  all,
  Sorry that there was a small typo in the 'n' 'm' texts.
  The example given by me is anyway the correct one.
  Sravan Reddy's solution worked fine.

  On Jun 4, 10:08 am, rohit rajuljain...@gmail.com wrote:
   i think solution would be like this

   eg:
   A : 1 2 3 B: 0 1.5 4 5 9
   Output:
   A can contain any combination of nos 0,1,1.5
   and B should contain 2 3 4 5 9 (in any order.)

   this example is given by ROSS itself.

   so sravanreddy solution is right , correct me if i'm wrong.

   On Jun 3, 8:07 pm, bittu shashank7andr...@gmail.com wrote:

@sravanreddy...logical bugs  if A is size of n  B is size m from your
example  assuming nm  so if you want smallest m elements in A then u
only capacity of n elements  didn't allocate memory so these elements
initialized by INT_MIN for m-n nodes so thatarrayA can hold m
smallest elements then what r u swapping u dude..isn't garbage
value ?? you will get at 1st step only just run it ?? in you algo
A_End=m-1(which 4th position inArraythat DNE)..??  also you have to
free memory for  m-n  inarrayB as it contains n largest elements .

take
A= 1,2,3 n=3
B= 0,1,4,5,9 m=5

after allocating memory toArrayA  for  m-n elements A will looks
likes 1 2 3 INT_Max INT_Max
now what you wants A should contains m smallest elements  B have n
largest elements
so O/P should be  A=1,2,3,1,0  B=INT_Max,INT_Max,4,5,9 now free
memory used by 1st elements inarrayB so that A will represent M
smallest elements  B will have n Largest elements

so that above will work.

Hope I am Correct let me know if any issue with explanation

Thanks
ShashankThe Best Way To Escape From Theproblemis To Solve It
CSE,BIT Mesra

  --
  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.

   --
  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.

 --
 -Aakash Johari
 (IIIT Allahabad)

-- 
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.



Re: [algogeeks] Re: Array Merge Problem

2011-06-05 Thread Deepak Jha
the below solution should work given the input array is sorted ( I am
assuming ascending order)
void rearrangeArray(int[] a, int[] b){
int m = a.length;
int n = b.length;
int i = m - 1;
int j = 0;
while((i =0)  (j = n-1)){
if(a[i]  b[j]){
int temp = a[i];
a[i] = b[j];
b[j] = temp;
}
i--;
j++;
}
 }

On Sat, Jun 4, 2011 at 2:29 PM, ross jagadish1...@gmail.com wrote:

 Hi Rohit  all,
 Sorry that there was a small typo in the 'n' 'm' texts.
 The example given by me is anyway the correct one.
 Sravan Reddy's solution worked fine.

 On Jun 4, 10:08 am, rohit rajuljain...@gmail.com wrote:
  i think solution would be like this
 
  eg:
  A : 1 2 3 B: 0 1.5 4 5 9
  Output:
  A can contain any combination of nos 0,1,1.5
  and B should contain 2 3 4 5 9 (in any order.)
 
  this example is given by ROSS itself.
 
  so sravanreddy solution is right , correct me if i'm wrong.
 
  On Jun 3, 8:07 pm, bittu shashank7andr...@gmail.com wrote:
 
 
 
 
 
 
 
   @sravanreddy...logical bugs  if A is size of n  B is size m from your
   example  assuming nm  so if you want smallest m elements in A then u
   only capacity of n elements  didn't allocate memory so these elements
   initialized by INT_MIN for m-n nodes so thatarrayA can hold m
   smallest elements then what r u swapping u dude..isn't garbage
   value ?? you will get at 1st step only just run it ?? in you algo
   A_End=m-1(which 4th position inArraythat DNE)..??  also you have to
   free memory for  m-n  inarrayB as it contains n largest elements .
 
   take
   A= 1,2,3 n=3
   B= 0,1,4,5,9 m=5
 
   after allocating memory toArrayA  for  m-n elements A will looks
   likes 1 2 3 INT_Max INT_Max
   now what you wants A should contains m smallest elements  B have n
   largest elements
   so O/P should be  A=1,2,3,1,0  B=INT_Max,INT_Max,4,5,9 now free
   memory used by 1st elements inarrayB so that A will represent M
   smallest elements  B will have n Largest elements
 
   so that above will work.
 
   Hope I am Correct let me know if any issue with explanation
 
   Thanks
   ShashankThe Best Way To Escape From Theproblemis To Solve It
   CSE,BIT Mesra

 --
 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.



-- 
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.



[algogeeks] Re: Array Merge Problem

2011-06-04 Thread rohit
i think solution would be like this

eg:
A : 1 2 3 B: 0 1.5 4 5 9
Output:
A can contain any combination of nos 0,1,1.5
and B should contain 2 3 4 5 9 (in any order.)

this example is given by ROSS itself.

so sravanreddy solution is right , correct me if i'm wrong.

On Jun 3, 8:07 pm, bittu shashank7andr...@gmail.com wrote:
 @sravanreddy...logical bugs  if A is size of n  B is size m from your
 example  assuming nm  so if you want smallest m elements in A then u
 only capacity of n elements  didn't allocate memory so these elements
 initialized by INT_MIN for m-n nodes so thatarrayA can hold m
 smallest elements then what r u swapping u dude..isn't garbage
 value ?? you will get at 1st step only just run it ?? in you algo
 A_End=m-1(which 4th position inArraythat DNE)..??  also you have to
 free memory for  m-n  inarrayB as it contains n largest elements .

 take
 A= 1,2,3 n=3
 B= 0,1,4,5,9 m=5

 after allocating memory toArrayA  for  m-n elements A will looks
 likes 1 2 3 INT_Max INT_Max
 now what you wants A should contains m smallest elements  B have n
 largest elements
 so O/P should be  A=1,2,3,1,0  B=INT_Max,INT_Max,4,5,9 now free
 memory used by 1st elements inarrayB so that A will represent M
 smallest elements  B will have n Largest elements

 so that above will work.

 Hope I am Correct let me know if any issue with explanation

 Thanks
 ShashankThe Best Way To Escape From Theproblemis To Solve It
 CSE,BIT Mesra

-- 
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.



[algogeeks] Re: Array Merge Problem

2011-06-04 Thread ross
Hi Rohit  all,
Sorry that there was a small typo in the 'n' 'm' texts.
The example given by me is anyway the correct one.
Sravan Reddy's solution worked fine.

On Jun 4, 10:08 am, rohit rajuljain...@gmail.com wrote:
 i think solution would be like this

 eg:
 A : 1 2 3 B: 0 1.5 4 5 9
 Output:
 A can contain any combination of nos 0,1,1.5
 and B should contain 2 3 4 5 9 (in any order.)

 this example is given by ROSS itself.

 so sravanreddy solution is right , correct me if i'm wrong.

 On Jun 3, 8:07 pm, bittu shashank7andr...@gmail.com wrote:







  @sravanreddy...logical bugs  if A is size of n  B is size m from your
  example  assuming nm  so if you want smallest m elements in A then u
  only capacity of n elements  didn't allocate memory so these elements
  initialized by INT_MIN for m-n nodes so thatarrayA can hold m
  smallest elements then what r u swapping u dude..isn't garbage
  value ?? you will get at 1st step only just run it ?? in you algo
  A_End=m-1(which 4th position inArraythat DNE)..??  also you have to
  free memory for  m-n  inarrayB as it contains n largest elements .

  take
  A= 1,2,3 n=3
  B= 0,1,4,5,9 m=5

  after allocating memory toArrayA  for  m-n elements A will looks
  likes 1 2 3 INT_Max INT_Max
  now what you wants A should contains m smallest elements  B have n
  largest elements
  so O/P should be  A=1,2,3,1,0  B=INT_Max,INT_Max,4,5,9 now free
  memory used by 1st elements inarrayB so that A will represent M
  smallest elements  B will have n Largest elements

  so that above will work.

  Hope I am Correct let me know if any issue with explanation

  Thanks
  ShashankThe Best Way To Escape From Theproblemis To Solve It
  CSE,BIT Mesra

-- 
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.



[algogeeks] Re: Array Merge Problem

2011-06-03 Thread bittu
@sravanreddy...logical bugs  if A is size of n  B is size m from your
example  assuming nm  so if you want smallest m elements in A then u
only capacity of n elements  didn't allocate memory so these elements
initialized by INT_MIN for m-n nodes so that array A can hold m
smallest elements then what r u swapping u dude..isn't garbage
value ?? you will get at 1st step only just run it ?? in you algo
A_End=m-1(which 4th position in Array that DNE)..??  also you have to
free memory for  m-n  in array B as it contains n largest elements .

take
A= 1,2,3 n=3
B= 0,1,4,5,9 m=5

after allocating memory to Array A  for  m-n elements A will looks
likes 1 2 3 INT_Max INT_Max
now what you wants A should contains m smallest elements  B have n
largest elements
so O/P should be  A=1,2,3,1,0  B=INT_Max,INT_Max,4,5,9 now free
memory used by 1st elements in array B so that A will represent M
smallest elements  B will have n Largest elements

so that above will work.

Hope I am Correct let me know if any issue with explanation

Thanks
ShashankThe Best Way To Escape From The problem is To Solve It
CSE,BIT Mesra

-- 
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.



Re: [algogeeks] Re: Array Merge Problem

2011-06-03 Thread Aakash Johari
Please try this solution. And tell if it fails at any case. If it works
fine, I will tell the logic.


 #include stdio.h
 #include stdlib.h

 void merge(int *a, int m, int *b, int n)
 {
 int i, j, k;
 int t;

 i = j = 0;
 k = -1;

 while ( i  m  a[i]  b[j] ) {
 i++;
 }

 while ( i  m  j  n ) {
 if ( k == -1  b[j]  a[i] ) {
 t = a[i]; a[i] = b[j]; b[j] = t;
 k = j;
 j++;
 i++;
 } else if ( b[j]  b[k] ) {
 t = a[i]; a[i] = b[j]; b[j] = t;
 j++;
 i++;
 } else {
 t = a[i]; a[i] = b[k]; b[k] = t;
 i++;
 }
 }
 }

 int main()
 {
 int m, n;
 int *a, *b;
 int i;

 scanf (%d%d, m, n);

 a = (int*) malloc(sizeof(int) * m);
 b = (int*) malloc(sizeof(int) * n);

 for ( i = 0; i  m; i++ )
 scanf (%d, a + i);

 for ( i = 0; i  n; i++ )
 scanf (%d, b + i);

 merge (a, m, b, n);

 printf (After Merge Operation : \n);

 printf (1st Array : );

 for ( i = 0; i  m; i++ ) {
 printf (%d , a[i]);
 }

 printf (\n2nd Array :  );

 for ( i = 0; i  n; i++ ) {
 printf (%d , b[i]);
 }

 return 0;
 }


 On Fri, Jun 3, 2011 at 8:07 AM, bittu shashank7andr...@gmail.com wrote:

 @sravanreddy...logical bugs  if A is size of n  B is size m from your
 example  assuming nm  so if you want smallest m elements in A then u
 only capacity of n elements  didn't allocate memory so these elements
 initialized by INT_MIN for m-n nodes so that array A can hold m
 smallest elements then what r u swapping u dude..isn't garbage
 value ?? you will get at 1st step only just run it ?? in you algo
 A_End=m-1(which 4th position in Array that DNE)..??  also you have to
 free memory for  m-n  in array B as it contains n largest elements .

 take
 A= 1,2,3 n=3
 B= 0,1,4,5,9 m=5

 after allocating memory to Array A  for  m-n elements A will looks
 likes 1 2 3 INT_Max INT_Max
 now what you wants A should contains m smallest elements  B have n
 largest elements
 so O/P should be  A=1,2,3,1,0  B=INT_Max,INT_Max,4,5,9 now free
 memory used by 1st elements in array B so that A will represent M
 smallest elements  B will have n Largest elements

 so that above will work.

 Hope I am Correct let me know if any issue with explanation

 Thanks
 ShashankThe Best Way To Escape From The problem is To Solve It
 CSE,BIT Mesra

 --
 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.




-- 
-Aakash Johari
(IIIT Allahabad)

-- 
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.



Re: [algogeeks] Re: Array Merge Problem

2011-06-03 Thread Ravinder Kumar
it can be done in O(m) . Use something like binary search .

code is here ...

#includestdio.h

void splitMN(int a[],int m , int b[], int n){
int al = 0 , bl = 0 ;
int ah = m-1 , bh = n-1 ;
int ai = (ah+al+1)/2;
int bi = (bh+bl+1)/2;
while(ai+bi!=m){
printf(Enter ai = %d, bi = %d\n ,ai,bi);
if(ai+bi  m){
if(a[ai]  b[bi]){
al = ai ;
if(al == ai) break;
ai = (ah+al+1)/2;
}else{
bl = bi ;
if(bh == bi) break;
bi = (bh+bl+1)/2;
}
}else{
if(a[ai]  b[bi]){
ah = ai ;
if(ah == ai) break;
ai = (ah+al+1)/2;
}else{
bh = bi ;
if(bh == bi) break;
bi = (bh+bl+1)/2;
}
}
}
bi = 0 ;
ai ;
while(ai  m){
a[ai] = a[ai]^b[bi]^(b[bi] = a[ai]);
ai++ ; bi++ ;
}

}

int main(){
int m , n ;
printf(Enter m , n : );
scanf(%d%d,m,n);
int a[m] , b[n] ;
int i ;
for(i = 0 ; i m ; i++)
scanf(%d,a[i]);
for(i = 0 ; i n ; i++)
scanf(%d,b[i]);
printf(Enter m , n : );
splitMN(a,m,b,n);
for(i = 0 ; i m ; i++)
printf(%d\t,a[i]);
printf(\n);
for(i = 0 ; i n ; i++)
printf(%d\t,b[i]);
printf(\n);
}

On Sat, Jun 4, 2011 at 4:03 AM, Aakash Johari aakashj@gmail.com wrote:

 Please try this solution. And tell if it fails at any case. If it works
 fine, I will tell the logic.


 #include stdio.h
 #include stdlib.h

 void merge(int *a, int m, int *b, int n)
 {
 int i, j, k;
 int t;

 i = j = 0;
 k = -1;

 while ( i  m  a[i]  b[j] ) {
 i++;
 }

 while ( i  m  j  n ) {
 if ( k == -1  b[j]  a[i] ) {
 t = a[i]; a[i] = b[j]; b[j] = t;
 k = j;
 j++;
 i++;
 } else if ( b[j]  b[k] ) {
 t = a[i]; a[i] = b[j]; b[j] = t;
 j++;
 i++;
 } else {
 t = a[i]; a[i] = b[k]; b[k] = t;
 i++;
 }
 }
 }

 int main()
 {
 int m, n;
 int *a, *b;
 int i;

 scanf (%d%d, m, n);

 a = (int*) malloc(sizeof(int) * m);
 b = (int*) malloc(sizeof(int) * n);

 for ( i = 0; i  m; i++ )
 scanf (%d, a + i);

 for ( i = 0; i  n; i++ )
 scanf (%d, b + i);

 merge (a, m, b, n);

 printf (After Merge Operation : \n);

 printf (1st Array : );

 for ( i = 0; i  m; i++ ) {
 printf (%d , a[i]);
 }

 printf (\n2nd Array :  );

 for ( i = 0; i  n; i++ ) {
 printf (%d , b[i]);
 }

 return 0;
 }


 On Fri, Jun 3, 2011 at 8:07 AM, bittu shashank7andr...@gmail.com wrote:

 @sravanreddy...logical bugs  if A is size of n  B is size m from your
 example  assuming nm  so if you want smallest m elements in A then u
 only capacity of n elements  didn't allocate memory so these elements
 initialized by INT_MIN for m-n nodes so that array A can hold m
 smallest elements then what r u swapping u dude..isn't garbage
 value ?? you will get at 1st step only just run it ?? in you algo
 A_End=m-1(which 4th position in Array that DNE)..??  also you have to
 free memory for  m-n  in array B as it contains n largest elements .

 take
 A= 1,2,3 n=3
 B= 0,1,4,5,9 m=5

 after allocating memory to Array A  for  m-n elements A will looks
 likes 1 2 3 INT_Max INT_Max
 now what you wants A should contains m smallest elements  B have n
 largest elements
 so O/P should be  A=1,2,3,1,0  B=INT_Max,INT_Max,4,5,9 now free
 memory used by 1st elements in array B so that A will represent M
 smallest elements  B will have n Largest elements

 so that above will work.

 Hope I am Correct let me know if any issue with explanation

 Thanks
 ShashankThe Best Way To Escape From The problem is To Solve It
 CSE,BIT Mesra

 --
 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.




 --
 -Aakash Johari
 (IIIT Allahabad)





  --
 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.




-- 
*With Regards :*

Ravinder Kumar
B.Tech 3rd Year
Computer Science and Engineering
MNNIT Allahabad

-- 
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 

[algogeeks] Re: Array Merge Problem

2011-05-28 Thread sravanreddy001
Maintain a pointer A_end = m-1;
doing a comparision something similar to merge sort

int i=0;j=0;
while (i m){
 if (a[i]  b[j])
  i++;
 else{
  swap(a[A_end],b[j])
  A_end --;
  j++;
 }
}

This runs in O(m) time and no extra space, also the sort order is not 
guarenteed.

-- 
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.



[algogeeks] Re: Array Merge Problem

2011-05-28 Thread ross
@sravanreddy:
Hey, Nice Solution :) cool!

On May 29, 7:44 am, sravanreddy001 sravanreddy...@gmail.com wrote:
 Maintain a pointer A_end = m-1;
 doing a comparision something similar to merge sort

 int i=0;j=0;
 while (i m){
  if (a[i]  b[j])
   i++;
  else{
   swap(a[A_end],b[j])
   A_end --;
   j++;
  }

 }

 This runs in O(m) time and no extra space, also the sort order is not
 guarenteed.

-- 
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.



Re: [algogeeks] Re: Array Merge Problem

2011-05-28 Thread ankit sambyal
@sravanreddy: it won't work.   Try 3,91,9   and   90,1,8,2,5   .  correct me
if i m wrong.

Thanks,
Ankit Sambyal

On Sat, May 28, 2011 at 9:16 PM, ross jagadish1...@gmail.com wrote:

 @sravanreddy:
 Hey, Nice Solution :) cool!

 On May 29, 7:44 am, sravanreddy001 sravanreddy...@gmail.com wrote:
  Maintain a pointer A_end = m-1;
  doing a comparision something similar to merge sort
 
  int i=0;j=0;
  while (i m){
   if (a[i]  b[j])
i++;
   else{
swap(a[A_end],b[j])
A_end --;
j++;
   }
 
  }
 
  This runs in O(m) time and no extra space, also the sort order is not
  guarenteed.

 --
 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.



-- 
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.



Re: [algogeeks] Re: Array Merge Problem

2011-05-28 Thread immanuel kingston
@Ankit, The input should be 2 sorted arrays

Thanks,
Immanuel

On Sun, May 29, 2011 at 10:48 AM, ankit sambyal ankitsamb...@gmail.comwrote:

 @sravanreddy: it won't work.   Try 3,91,9   and   90,1,8,2,5   .  correct
 me if i m wrong.

 Thanks,
 Ankit Sambyal

 On Sat, May 28, 2011 at 9:16 PM, ross jagadish1...@gmail.com wrote:

 @sravanreddy:
 Hey, Nice Solution :) cool!

 On May 29, 7:44 am, sravanreddy001 sravanreddy...@gmail.com wrote:
  Maintain a pointer A_end = m-1;
  doing a comparision something similar to merge sort
 
  int i=0;j=0;
  while (i m){
   if (a[i]  b[j])
i++;
   else{
swap(a[A_end],b[j])
A_end --;
j++;
   }
 
  }
 
  This runs in O(m) time and no extra space, also the sort order is not
  guarenteed.

 --
 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.


  --
 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.


-- 
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.



Re: [algogeeks] Re: Array Merge Problem

2011-05-28 Thread ankit sambyal
Oh I didn't read the question properly,   Thanks for pointing out...

On Sat, May 28, 2011 at 10:28 PM, immanuel kingston 
kingston.imman...@gmail.com wrote:

 @Ankit, The input should be 2 sorted arrays

 Thanks,
 Immanuel

 On Sun, May 29, 2011 at 10:48 AM, ankit sambyal ankitsamb...@gmail.comwrote:

 @sravanreddy: it won't work.   Try 3,91,9   and   90,1,8,2,5   .  correct
 me if i m wrong.

 Thanks,
 Ankit Sambyal

 On Sat, May 28, 2011 at 9:16 PM, ross jagadish1...@gmail.com wrote:

 @sravanreddy:
 Hey, Nice Solution :) cool!

 On May 29, 7:44 am, sravanreddy001 sravanreddy...@gmail.com wrote:
  Maintain a pointer A_end = m-1;
  doing a comparision something similar to merge sort
 
  int i=0;j=0;
  while (i m){
   if (a[i]  b[j])
i++;
   else{
swap(a[A_end],b[j])
A_end --;
j++;
   }
 
  }
 
  This runs in O(m) time and no extra space, also the sort order is not
  guarenteed.

 --
 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.


  --
 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.


  --
 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.


-- 
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.