[algogeeks] median

2010-06-21 Thread jalaj jaiswal
give an algo to find the median of a bst ... no additional info is given -- With Regards, Jalaj Jaiswal +919026283397 B.TECH IT 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] Int from number in words

2010-06-21 Thread debajyotisarma
How to device an algo to convert a number given in words to int? Eg- i/p: ninety nine thousand fourth o/p: 99040 Algorithm should work for all possible inputs. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email

[algogeeks] max

2010-06-21 Thread sharad
How will you find the number of occurrence of maximum value in an array u can traverse only 1 time -- 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,

[algogeeks] numbers

2010-06-21 Thread jalaj jaiswal
given an integer.. assume some range by yourself give an algo such that if i input 1024 it outputs one thousand twenty four -- With Regards, Jalaj Jaiswal +919026283397 B.TECH IT IIIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group.

Re: [algogeeks] Re: SPOJ:RRSCHED

2010-06-21 Thread Terence
Don't try to simulate the scheduler on every second. The total execution time can reach 5 * 10^9 sec. Play with small examples, get the task list in execution order, and find the cyclic property of the list. You can solve this problem in O(N) time complexity. On 2010-6-20 18:15, Shravan

[algogeeks] Swap the bits

2010-06-21 Thread amit
Given a byte, write a code to swap every two bits. [Using bit operators] Eg: Input: 10 01 11 01 Output: 01 10 11 10 -- 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

[algogeeks] Re: Swap the bits

2010-06-21 Thread Dave
Not hard at all: y = ((x 0xAA) 1) | ((x 0x55) 1) Dave On Jun 21, 7:07 am, amit amitjaspal...@gmail.com wrote: Given a byte, write a code to swap every two bits. [Using bit operators] Eg: Input: 10 01 11 01 Output: 01 10 11 10 -- You received this message because you are subscribed to

[algogeeks] Re: max

2010-06-21 Thread Dave
As you traverse the array, every time an element of the array is greater than the maximum you have found so far, update the max and save its index. Dave On Jun 21, 9:34 am, sharad sharad20073...@gmail.com wrote: How will you find the number of occurrence of maximum value in an array u can

[algogeeks] Re: max

2010-06-21 Thread Dave
Upon rereading your question, maybe I answered the wrong one. My previous response was how to find the location of the maximum occurrence, but maybe you meant the number of occurrences of the maximum. In that case, as you traverse the array, every time you find an element greater than the max you

Re: [algogeeks] Re: max

2010-06-21 Thread Anand
Here is a code for it. http://codepad.org/P115Iud7 On Mon, Jun 21, 2010 at 9:48 AM, Dave dave_and_da...@juno.com wrote: Upon rereading your question, maybe I answered the wrong one. My previous response was how to find the location of the maximum occurrence, but maybe you meant the number

[algogeeks] find all the combination of number whose sum is n

2010-06-21 Thread sharad
How will you find all the combination of number whose sum is n -- 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

Re: [algogeeks] Re: Swap the bits

2010-06-21 Thread mohit ranjan
oops so sleek and simple :) Mohit Ranjan On Mon, Jun 21, 2010 at 10:11 PM, Dave dave_and_da...@juno.com wrote: Not hard at all: y = ((x 0xAA) 1) | ((x 0x55) 1) Dave On Jun 21, 7:07 am, amit amitjaspal...@gmail.com wrote: Given a byte, write a code to swap every two bits. [Using

Re: [algogeeks] Swap the bits

2010-06-21 Thread mohit ranjan
@Amit char foo=157;//10 01 11 01 unsigned char temp; unsigned char base=1; int i; for(i=7; i0; i=i-2) { temp=foo (basei); // saving the 7th, 5th, 3rd, 1st bit printf(%x\n, temp); foo = (~(basei) foo) | (((base(i-1)) foo)1); // moving 6th, 4th, 2nd, 0th bit to adjacnt

Re: [algogeeks] Array Problem

2010-06-21 Thread jalaj jaiswal
traverse the array ...take two variables min and max ... and update them ...while traversing. finally min will contain the most negative value,,, and max will contain the most positive vale... do max-min.. that will be S On Mon, Jun 21, 2010 at 5:38 PM, amit amitjaspal...@gmail.com wrote:

Re: [algogeeks] n ary tree

2010-06-21 Thread sharad kumar
sry ..whatever u have posted ...i hve posted this approach mistakenly in lexographically next string waale mewaise i think this approach works -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] Re: Swap the bits

2010-06-21 Thread Amit Jaspal
@ Dave would u plz bother to discuss how do u arrive at this formula? On Mon, Jun 21, 2010 at 10:11 PM, Dave dave_and_da...@juno.com wrote: Not hard at all: y = ((x 0xAA) 1) | ((x 0x55) 1) Dave On Jun 21, 7:07 am, amit amitjaspal...@gmail.com wrote: Given a byte, write a code to

Re: [algogeeks] longest chain

2010-06-21 Thread Amir hossein Shahriari
i think that if you implement the elements of a string in set you can find its children easily (specially if you map each set to the real strings) in O( n . max length of a string . d) where n is the number of strings and d is running time of set.delete() after making the graph since the maximum

Re: [algogeeks] Array Problem

2010-06-21 Thread Amir hossein Shahriari
using divide and conquer you can do it in O(nlogn) your recursive function must return three values the max and min value in this range and the maximum difference but this can also be solved in O(n) start from the end of array if you loop backward you can determine the max(a[i]) for i=j and then

[algogeeks] Re: minimum spanning tree

2010-06-21 Thread Gene
On Jun 20, 7:48 am, jalaj jaiswal jalaj.jaiswa...@gmail.com wrote: give an algo to find a minimum spanning tree of a directed graph ?? -- With Regards, Jalaj Jaiswal +919026283397 B.TECH IT IIIT ALLAHABAD Kruskal's algorithm: Remove all the edges in the graph. Re-insert them in

[algogeeks] Re: Swap the bits

2010-06-21 Thread Dave
Let me explain, supposing that you haven't really tried to understand the code. The first logical product picks out bits 1, 3, 5, and 7 and shifts them 1 position to the right. The second logical product picks out bits 0, 2, 4, and 6 and shifts them 1 position to the left. Then just or the two

Re: [algogeeks] Array Problem

2010-06-21 Thread sharad kumar
@jalaj one more constraint is there ij -- 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.

[algogeeks] Re: knapsack

2010-06-21 Thread ANUJ KUMAR
i used this code but its giving me segmentation fault. vectorintans;//maintains the list of selected objects for(int x=t-1;x0;x--)//t is the no. of objects { if(knap[x][tt]!=knap[x-1][tt])//tt is the capacity of knapack { ans.push_back(ar[x].index);

Re: [algogeeks] Count Structurally different binary tree possible ..

2010-06-21 Thread MOHIT ....
yes i mean diffrent sub binary search tree of Given binary tree -- 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