[algogeeks] Re: Code it...

2011-10-16 Thread sravanreddy001
the only way to do this is to store in an external space like file.

if its a function that is called, a static variable can be used to track 
count.

Question: Can extern variables span accross processes? They cannot right. I 
mean two forked process share the same extern variable instance??

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/z-zCWgyer20J.
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: Sorting a array which is already sorted but has some disorder

2011-10-16 Thread sravanreddy001
OK..
what is expected?

its again sort problem, unless the amount of distortion is constant, in 
which a Binary search or Insertion sort can be employed to do in O(n) time.
Didn't give a programmatic thought. But, if the the amount of distortion is 
of order n, then sort in O(n lg n)

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/ttSTk3_w6qIJ.
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: Sorting a array which is already sorted but has some disorder

2011-10-16 Thread vickywiz
We can just keep swapping characters, until it gets in order.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/3VFwJUGRGS0J.
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] Sorting a array which is already sorted but has some disorder

2011-10-16 Thread Siddharth Pipriya
Question: If given string with sorted order with some disorder in
between for example
"abcfedghi" you need to make it as "abcdefghi" with no 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 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: Bit Magic ....Always Stuck ..

2011-10-16 Thread vikas
for next larger number

 check for 1st bit set
  x = n&~(n-1)
 e.g. n = 10100 = 20
n -1 = 10011
x = 10100 & 01100 = 100

for next larger number check for 1st 0 and set the bit

thus y = ~x
   n = y &~(y-1)
   x |= n

x = 10101 = 21

y = 01010 = 10
y-1 = 01001 = 9
n = 1010 & 110 = 0010

x = 10111 = 23

now this has one bit more

so to turn this off
again
x = x & ~( x & ~(x-1))

i.e. 10111 & ~(10111 &  01001) = 10111 & 0 = 10110 = 22

do similarly for small number

On Oct 16, 2:31 pm, rajul jain  wrote:
> I have read this question earlier
> the algo is like this
> 1)Traverse from right to left , once we passed 1, turn on next 0 and also
> turn off the one that's just to right side of
> that.
> example xxx11011  become xx101011
> 2) for making number small just rearrange all 1's to be as right as
> possible.
> xx101011 become  xx100111
> similary you can get larger number by rearrange all 1's to left .
>
> On Wed, Mar 2, 2011 at 1:20 AM, bittu  wrote:
> > Given an integer, print the next smallest and next largest number that
> > have the same number of 1 bits in their binary representation.
>
> > Example for n=12
> > next smallest  with same no. of set bit is 17  but  to found next
> > largest ..we have to be careful ..
>
> > let c others ..??
>
> > Thanks & Regards
> > Shashank
>
> > --
> > 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] Code it...

2011-10-16 Thread amrit harry
use a file...every time we run it... get number from file increment it print
it and again replace back to filedats it.

On Sat, Oct 15, 2011 at 3:56 PM, kumar raja wrote:

>
> you have to write a program which tell about how many times it has run.
> ex:
> if you run first time it will print 1.
> if you run second time it will print 2.
> like this.
>
> --
> Regards
> Kumar Raja
> M.Tech(SIT)
> IIT Kharagpur,
> 10it60...@iitkgp.ac.in
>
>
>  --
> 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.
>



-- 
AMRIT

-- 
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] Code it...

2011-10-16 Thread kumar raja
you have to write a program which tell about how many times it has run.
ex:
if you run first time it will print 1.
if you run second time it will print 2.
like this.

-- 
Regards
Kumar Raja
M.Tech(SIT)
IIT Kharagpur,
10it60...@iitkgp.ac.in

-- 
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] print vertical sums of a binary tree

2011-10-16 Thread sravanreddy001
Even I see this as the best solution...
O(n) time and space..

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/sIzIL2amUckJ.
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] print vertical sums of a binary tree

2011-10-16 Thread Ankur Garg
Sorry code got reposted twice here is the correct one
void getLevelSum(node* root,int level,int &minL,int &maxR,int left[],int
right[]){
if(!root) return ;
minL = min(minL,level);
maxR = max(maxR,level);
getLevelSum(root->left,level-1,minL,maxR,left,right);
getLevelSum(root->right,level+1,minL,maxR,left,right);
if(level<0)
  left[abs(level)] +=root->data;
else
  right[level] +=root->data;
}
On Sun, Oct 16, 2011 at 4:23 PM, Ankur Garg  wrote:

> I am assuming we are allowed to use space ..With that i make 2 arrays 1 to
> store values from left side and other from right side .
>
> Here is the func
>
>
> void getLevelSum(node* root,int level,int &minL,int &maxR,int left[],int
> right[]){
> if(!root) return ;
> minL = min(minL,level);
> maxR = max(maxR,level);
> getLevelSum(root->left,level-1,minL,maxR,left,right);
> getLevelSum(root->right,level+1,minL,maxR,left,right);
> if(level<0)
>   left[abs(level)] +=root->data;
> else
>   right[level] +=root->data;
> }
>
> I am traversing whole tree nodes only once but storing them in an array so
> Space complexity is also O(n) for me
>
> Anyone having a better solution or approach ?
>
>
> On Sun, Oct 16, 2011 at 9:27 AM, SUMANTH M  wrote:
>
>> Hi,
>>
>>A binary tree is given we need to print vertical sums of nodes. for
>> example
>>
>>   12  34 5
>>
>>   |  |   5| |
>>   |  | / |   \ | |
>>   |  |   /   |8 |
>>   |  | / |   / |\|
>>   |  4  |/|   10
>>   |/ |  \9| |
>>   |  /   |  \  | |
>>   7 |  6   |
>>   |  |  |  | |
>>   |  |  |  | |
>>   ---
>>   7 4 20   8   10
>>
>>  Here we need to print sum 7,4,20,8,10.
>>
>> -Thanks
>>
>> --
>> 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] print vertical sums of a binary tree

2011-10-16 Thread Ankur Garg
I am assuming we are allowed to use space ..With that i make 2 arrays 1 to
store values from left side and other from right side .

Here is the func


void getLevelSum(node* root,int &minL,int &maxR,int level){
if(!root) return ;
minL = min(minL,level);
maxR = max(maxR,level);
getLevelSum(root->left,minL,maxR,level-1);
getLevelSum(root->right,minL,maxR,level+1);
}
void getLevelSum(node* root,int level,int &minL,int &maxR,int left[],int
right[]){
if(!root) return ;
minL = min(minL,level);
maxR = max(maxR,level);
getLevelSum(root->left,level-1,minL,maxR,left,right);
getLevelSum(root->right,level+1,minL,maxR,left,right);
if(level<0)
  left[abs(level)] +=root->data;
else
  right[level] +=root->data;
}
I am traversing whole tree nodes only once but storing them in an array so
Space complexity is also O(n) for me

Anyone having a better solution or approach ?


On Sun, Oct 16, 2011 at 9:27 AM, SUMANTH M  wrote:

> Hi,
>
>A binary tree is given we need to print vertical sums of nodes. for
> example
>
>   12  34 5
>
>   |  |   5| |
>   |  | / |   \ | |
>   |  |   /   |8 |
>   |  | / |   / |\|
>   |  4  |/|   10
>   |/ |  \9| |
>   |  /   |  \  | |
>   7 |  6   |
>   |  |  |  | |
>   |  |  |  | |
>   ---
>   7 4 20   8   10
>
>  Here we need to print sum 7,4,20,8,10.
>
> -Thanks
>
> --
> 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] Bit Magic ....Always Stuck ..

2011-10-16 Thread rajul jain
I have read this question earlier
the algo is like this
1)Traverse from right to left , once we passed 1, turn on next 0 and also
turn off the one that's just to right side of
that.
example xxx11011  become xx101011
2) for making number small just rearrange all 1's to be as right as
possible.
xx101011 become  xx100111
similary you can get larger number by rearrange all 1's to left .


On Wed, Mar 2, 2011 at 1:20 AM, bittu  wrote:

> Given an integer, print the next smallest and next largest number that
> have the same number of 1 bits in their binary representation.
>
> Example for n=12
> next smallest  with same no. of set bit is 17  but  to found next
> largest ..we have to be careful ..
>
> let c others ..??
>
>
>
> Thanks & Regards
> Shashank
>
>
>
>
>
>
>
>
>
>
>
> --
> 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] Bit Magic ....Always Stuck ..

2011-10-16 Thread shivam kapoor
i think it will work...

#include
unsigned getNextBigger(unsigned a) {
   /* works for any word length */
 unsigned c = (a & -a);
 unsigned r = a+c;
  return r ^ a) >> 2) / c) | r);}
int getNextSmaller(int num) {
return ~getNextBigger(~num);}

int main(){
   unsigned int res , min;
   res = getNextBigger(12);
   printf("max = %d" , res);
   min = getNextSmaller(12);
   printf("min = %d" , min);
   return 0;}






Regards

Shivam

-- 
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] Find THE NUMBERS URGENT PLZZZZZ HELP...........

2011-10-16 Thread shady
lol, the guy is asking for solutions, should i report you :D :D :D :D

On Sun, Oct 16, 2011 at 11:56 AM, sunny agrawal wrote:

> This Question is from ACM-ICPC 2011 Amritapuri online round which ends
> today at 1pm
> so no answers to this post till 1 pm
>
> On Sun, Oct 16, 2011 at 11:12 AM, Pradex  wrote:
>
>> Given two number A and B, count all the number lies between them
>> including both which have no more than two digit in common 1 <= A <= B
>> <= 10^18
>> eg. : 100 120
>> output : 20 excluding 111
>> please help very important ??
>>
>> --
>> 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.
>>
>>
>
>
> --
> Sunny Aggrawal
> B.Tech. V year,CSI
> Indian Institute Of Technology,Roorkee
>
>
>  --
> 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.