Re: [algogeeks] 0's and 1's yet again!!!

2010-08-19 Thread Rais Khan
void ArrayShifting(int *str, int size)
{
int odd=1, even=0;
while(odd  size)
{
int position;
if(str[even]!=0)
{
position = even+1;
while(position  size)
{
if(str[position]==0)
{ str[position]=1;str[even]=0;break;}
position = position+2;
}
}
even = even+2;
if(str[odd]!=1)
{
position = odd+1;
while(position  size)
{
if(str[k]==0)
{ str[position]=0;str[odd]=1;break;}
position = position+2;
}
}
odd=odd+2;
}
}

This code seems working for me, If you agree then we can work on measuring
the complexity  improving the code accordingly.



On Thu, Aug 19, 2010 at 5:27 PM, Ashutosh Tamhankar asshuto...@gmail.comwrote:

 Hi Amit

 Am I allowed to keep counters to count the number of 1's and 0s right?

 The condition of not using extra memory is for the array!?

 Regards
 Ashutosh


 2010/8/18 amit amitjaspal...@gmail.com

 you are given an array of integers containing only 0s and 1s. you have
 to place all the 0s in even position and 1s in odd position and if
 suppose no if 0s exceed no. of 1s or vice versa then keep them
 untouched. Do that in ONE PASS and WITHOUT taking EXTRA MEMORY.

 --
 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.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 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.



Re: [algogeeks] Adobe Question : Convert a number given in base B1 to a number in base B2 without using any intermediate base

2010-08-18 Thread Rais Khan
Below formula seems working to me for converting number from base B1 to base
B2. But For intermediate operation we have to be careful, as comiler does
all operation with base 10.
 newNum = (oldNum/newBase)*oldBase + oldNum%newBase;

So
Algo,
1. Number, oldBase, newbase;
2. First convert number from oldBase to base 10, TempNumber.  [same above
formula, newBase = 10, oldBase = B1]

3. Now, Convert TempNumber from base 10 to base B2.   [same above formula,
newBase = B2, oldBase = 10] ==Number.


On Tue, Aug 17, 2010 at 9:50 PM, luckyzoner luckyzo...@gmail.com wrote:

 I had proposed an algorithm of repeatedly subtracting 1 from the given
 number and subsequently adding 1 to the new number initialised to 0,
 till the given number becomes 0. However as soon as the digit reaches
 the limit , the digit becomes 0 and you add 1 to the next digit. I was
 not able to code it properly as i had to use int data type only. It
 would have been easy if the array of integers was allowed to use.

 Pls suggest the code for the same or some better algo.

 Thanx
 Lakshaya

 --
 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.comalgogeeks%2bunsubscr...@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 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.



Re: [algogeeks] Array Problem

2010-08-18 Thread Rais Khan
@Nikhil: Your algo seems to fail with following input. What do you say?
Arr1[]= {1,2,3}
Arr2[]={6}



On Wed, Aug 18, 2010 at 7:17 AM, Nikhil Agarwal
nikhil.bhoja...@gmail.comwrote:

 Sum all the elements of both the arrays..let it be s1 and s2
 Multiply the elements and call as m1 and m2
 if(s1==s2) (m1==m2)
 return 1;else
 return 0;

 O(n)

 On Tue, Aug 17, 2010 at 11:33 PM, amit amitjaspal...@gmail.com wrote:

 Given two arrays of numbers, find if each of the two arrays have the
 same set of integers ? Suggest an algo which can run faster than NlogN
 without extra space?

 --
 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Thanks  Regards
 Nikhil Agarwal
 Senior Undergraduate
 Computer Science  Engineering,
 National Institute Of Technology, Durgapur,India
 http://tech-nikk.blogspot.com
 http://beta.freshersworld.com/communities/nitd


  --
 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.comalgogeeks%2bunsubscr...@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 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.



Re: [algogeeks] Array Problem

2010-08-18 Thread Rais Khan
@Chonku: Your algo seems to fail with following input.
Arr1[]= {1,6}
Arr2[]={7}



On Wed, Aug 18, 2010 at 8:42 PM, Rais Khan raiskhan.i...@gmail.com wrote:

 @Nikhil: Your algo seems to fail with following input. What do you say?
 Arr1[]= {1,2,3}
 Arr2[]={6}




 On Wed, Aug 18, 2010 at 7:17 AM, Nikhil Agarwal nikhil.bhoja...@gmail.com
  wrote:

 Sum all the elements of both the arrays..let it be s1 and s2
 Multiply the elements and call as m1 and m2
 if(s1==s2) (m1==m2)
 return 1;else
 return 0;

 O(n)

 On Tue, Aug 17, 2010 at 11:33 PM, amit amitjaspal...@gmail.com wrote:

 Given two arrays of numbers, find if each of the two arrays have the
 same set of integers ? Suggest an algo which can run faster than NlogN
 without extra space?

 --
 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Thanks  Regards
 Nikhil Agarwal
 Senior Undergraduate
 Computer Science  Engineering,
 National Institute Of Technology, Durgapur,India
 http://tech-nikk.blogspot.com
 http://beta.freshersworld.com/communities/nitd


  --
 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.comalgogeeks%2bunsubscr...@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 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.