Re: [algogeeks] c

2010-06-26 Thread divya jain
ya it is giving error cz u r incrementing x. u cant increment x as it is const. but there is no prob with declaration. its valid. On 26 June 2010 11:09, sharad kumar aryansmit3...@gmail.com wrote: pls c thz On Sat, Jun 26, 2010 at 10:48 AM, sharad kumar aryansmit3...@gmail.comwrote: cos if

Re: [algogeeks] c

2010-06-26 Thread Ashish kumar Jain
This is a well known C Gotcha,to change a const variable will always lead to error. I guess the main query is Is this declaration valid and your compiler only shows error at printf line and not in the declaration.It also states that 'x' is a read-only variable. Hence,it accepts this declaration

Re: [algogeeks] c

2010-06-26 Thread harit agarwal
replace x++ with x it is const so you can't change it. -- 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] common

2010-06-26 Thread sharad kumar
Given two log files, each with a billion usernames (each username appended to the log file), find the usernames existing in both documents in the most efficient manner? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group,

[algogeeks] rotation

2010-06-26 Thread sharad kumar
i have to right rotate an array by k positions 1 2 3 4 5 for k=2 o/p shud be 3 4 5 1 2 P.S---do not give block reversal method for array rotation and soln must be inplace.plzz write ur logic also along with d code -- You received this message because you are subscribed to the Google Groups

Re: [algogeeks] 23 candies among 7 kids

2010-06-26 Thread harit agarwal
ok.. i got it.. it is 29! / 23! 6! -- 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

[algogeeks] Java Random Method

2010-06-26 Thread trdant
I have the following sequence of integers: 104,105,106,108 and need to write a Java statement to randomly produce one of these numbers. I basically need a non-linear random number generator. Any ideas? Travis -- You received this message because you are subscribed to the Google Groups

Re: [algogeeks] a bst

2010-06-26 Thread jalaj jaiswal
din get it .. could you provide the pseudo code. On Sat, Jun 26, 2010 at 3:54 PM, divya jain sweetdivya@gmail.comwrote: yes.. i got the solution traverse till node-right!=node-right-left... at this point u ll get height.. rite? On 26 June 2010 11:49, Raj N rajn...@gmail.com wrote:

Re: [algogeeks] a bst

2010-06-26 Thread Raj N
#define max(x,y) ((x)(y)?(x):(y)) struct Bintree{ int element; struct Bintree *left; struct Bintree *right; }; typedef struct Bintree* Tree; int height(Tree T) { if(T-right==T-right-left) return -1; else return (1 +

Re: [algogeeks] common

2010-06-26 Thread harit agarwal
in linux use comm -12 log1 log2 -- 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

Re: [algogeeks] c

2010-06-26 Thread Anil C R
volatile also means that you don't perform compiler optimizations on the variable... Anil On Sat, Jun 26, 2010 at 5:47 PM, harit agarwal agarwalha...@gmail.comwrote: @sharad you made it const so it can't be changed inside same program.. but as it is volatile it will read it as a first time

Re: [algogeeks] common

2010-06-26 Thread Anil C R
lol! Anil On Sat, Jun 26, 2010 at 5:49 PM, harit agarwal agarwalha...@gmail.comwrote: in linux use comm -12 log1 log2 -- 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

Re: [algogeeks] equal prob

2010-06-26 Thread Anil C R
On Sat, Jun 26, 2010 at 3:51 PM, sharad kumar sharad20073...@gmail.comwrote: assume your computer is reading characters one by one from a stream (you don't know the length of the stream before ending). Note that you have only one character of storage space (so you cann't save the characters

[algogeeks] Re: equal prob

2010-06-26 Thread Dave
Since count is always 1, doesn't rand(0, count) always return 0? So you always get the last item in the input. Dave On Jun 26, 11:00 am, Anil C R cr.a...@gmail.com wrote: On Sat, Jun 26, 2010 at 3:51 PM, sharad kumar sharad20073...@gmail.comwrote:  assume your computer is reading characters

Re: [algogeeks] Re: equal prob

2010-06-26 Thread Anil C R
oops! yeah you also need to increment the count inside... def get_random_obj( objstream ): count = 1 obj = objstream.get() while not objstream.end(): r = rand(0, count) if r == 0: obj = objstream.get() else: objstream.get() #discard

[algogeeks] Re: sum k in sub array

2010-06-26 Thread Dhritiman Das
@amit: Need to store indices also in the tree. Did you mean a self-balancing BST, like AVL or RB-Tree. Else worst case is O(n^2) for all positive numbers On Jun 25, 2:55 am, Amir hossein Shahriari amir.hossein.shahri...@gmail.com wrote: @divya: yes you're right my algo doesn't work

Re: [algogeeks] a bst

2010-06-26 Thread Raj N
@Algoose: Thanks for correcting it. Even I have made the same mistake as Divya. It shud be node == node-right-left On Sat, Jun 26, 2010 at 7:20 PM, Algoose Chase harishp...@gmail.com wrote: If the parent Pointer is available we can use if( node-right-data node-parent-data || node-right-data

[algogeeks] String Problem

2010-06-26 Thread amit
You r given a large string of characters lets call it Sbig. Then there is a small set of characters lets call it Ssmall. You have to find smallest substring of Sbig which contains all characters in Ssmall. For example you are given Sbig = hello what are you doing Ssmall= eo answer is ello 24 --

[algogeeks] Re: b tree

2010-06-26 Thread souravsain
I am assuming that nodes of this tree contain numbers and we want to get the median of these numbers. Also is this B-Tree a search tree - are the 3 numbers in each node (each node has 4 chidren and hence 3 values) sorted? Regards, Sourav Sain On Jun 26, 8:27 am, sharad kumar

[algogeeks] Diameter of a set of points

2010-06-26 Thread amit
Hi , can anyone tell me how to find the diameter of a set of N points i.e the distance between the 2 most farthest points efficiently -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

[algogeeks] Re: Next higher element

2010-06-26 Thread souravsain
@Raj You need to examine the nature of the array from end. If form end you move forward and you find elements are decreasing [10,12,14,16] then for each element, the previous is next higher. So keep pushing them on a stack. If you find an increase [say 11,10,12,14,16], then pop from stack till

Re: [algogeeks] c

2010-06-26 Thread sharad kumar
@harit but it is static so internal linkage is there then how it can be changed by external source may b i m mis understanding...so plzzz make it more clear -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send

[algogeeks] microsoft

2010-06-26 Thread jalaj jaiswal
Given an array of integers, {1,0,2,0,3,0,0,4,5,6,7,0,0,0}, you have to create a new array which will be like (1,2,3,4,5,6,7,0,0,0,0,0,0,0}, without using any other temporary array. -- With Regards, Jalaj Jaiswal +919026283397 B.TECH IT IIIT ALLAHABAD -- You received this message because you

Re: [algogeeks] a bst

2010-06-26 Thread Raj N
@jalaj: Use the same algorithm as finding the height of a normal tree (I hope you're familiar with it) . But to know that you've reached a leaf, you would normally use node-left or node-right ==NULL. But here in this case, the leaves form a doubly linked list, so the former condition can no longer

Re: [algogeeks] shuffle

2010-06-26 Thread sharad kumar
int array[52]; for(i=0;i52;++i) { int rand=rand()%52; swap(a[i],a[rand]); } On Sat, Jun 26, 2010 at 8:35 PM, Anil C R cr.a...@gmail.com wrote: I'm assuming that the random function can generate uniformly distributed random numbers between 0 and n(excluding n), where n is an +ive integer. def

Re: [algogeeks] microsoft

2010-06-26 Thread Jitendra Kushwaha
@jalaj just think 0 as one array and other numbers as other array the problem is into converted in zero one array which have to be sorted now sort the array in O(n) with no extra space. keep a pointer on left most 0 and find the next number in the sequence when next number found then swap the

[algogeeks] Re: microsoft

2010-06-26 Thread Dave
j = 0 for i = 1 to n if a(i) not equal 0 j = j + 1 a(j) = a(i) end if end for for i = j + 1 to n a(i) = 0 end for Dave On Jun 26, 3:27 pm, jalaj jaiswal jalaj.jaiswa...@gmail.com wrote: Given an array of integers, {1,0,2,0,3,0,0,4,5,6,7,0,0,0}, you have to create a

Re: [algogeeks] Re: equal prob

2010-06-26 Thread sharad kumar
@above probabilty for all numbers in d stream must be *same*.whether first or last -- 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

[algogeeks] arrays

2010-06-26 Thread sharad kumar
Give an unsorted array find count of pairs of numbers[a,b] where a b and b comes after a in the array. Eg. {8,3,6,10,5} the count of such numbers is 5. i.e. (8,3), (8,6), (8,5), (6,5) and (10,5) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks

Re: [algogeeks] Java Random Method

2010-06-26 Thread Anurag Sharma
int getNum(){ int arr[]={104,105,106,108}; return arr[(int)(Math.random()*4)]; } Anurag Sharma On Sat, Jun 26, 2010 at 8:43 PM, trdant trd...@gmail.com wrote: I have the following sequence of integers: 104,105,106,108 and need to write a Java statement to randomly produce one of these

Re: [algogeeks] String Problem

2010-06-26 Thread Anand
http://codepad.org/NDAeIpxR http://codepad.org/NDAeIpxRHere is code for it On Sat, Jun 26, 2010 at 9:54 PM, Anand anandut2...@gmail.com wrote: you can use Longest common subsequence algorithm to solve it. On Sat, Jun 26, 2010 at 4:04 PM, amit amitjaspal...@gmail.com wrote: You r given a

Re: [algogeeks] Re: equal prob

2010-06-26 Thread Anil C R
it is... but a small mistake in the code again... def get_random_obj( objstream ): count = 1 obj = objstream.get() while not objstream.end(): *count += 1* r = rand(0, count) if r == 0: obj = objstream.get() else: objstream.get()

Re: [algogeeks] Java Random Method

2010-06-26 Thread Chakravarthi Muppalla
@trdant, is non-linear random number different from general random number? On Sun, Jun 27, 2010 at 9:36 AM, Anurag Sharma anuragvic...@gmail.comwrote: int getNum(){ int arr[]={104,105,106,108}; return arr[(int)(Math.random()*4)]; } Anurag Sharma On Sat, Jun 26, 2010 at 8:43 PM,