[algogeeks] DS question

2009-09-07 Thread yash
wap a program in efficient manner to remove all occurrence of duplicate character in the word and all occurrence of duplicate word in the file. i break the problem in two section( this is my approach it may be better one ) wap to remove all duplicate character in the word. (order is important) [

[algogeeks] Re: random number...

2009-09-07 Thread Dave
Use the rejection technique, something like this: do { do U1 = random_1_to_5(); while( U1 == 5 ); // At this point, U1 is a uniform integer in the range 1 to 4. U2 = random_1_to_5(); if( U1 > 2 ) U2 += 5; } while( U2 > 7 ); // At this point, U2 is a uniform random

[algogeeks] Re: random number...

2009-09-07 Thread Nagendra Kumar
@ankur: u r right. On Mon, Sep 7, 2009 at 9:36 PM, ankur aggarwal wrote: > I KNow a sol for given a rand_5() function which generates 0 to 5 > and we have to find rand_7() for 0 to 7 > > could not think about it... > > > > On Mon, Sep 7, 2009 at 9:26 PM, ankur aggarwal > wrote: >> >> Given a ran

[algogeeks] Re: addition without using arithmetic operators

2009-09-07 Thread ayush chauhan
Cud u plz explain the logic behind this? On Mon, Sep 7, 2009 at 9:44 PM, Gokul wrote: > > you can try this.. > int add(int x, int y) > { >if (!x) return y; >else > return add((x & y) << 1, x ^ y); > } > > > > On Sep 7, 4:01 pm, ritter

[algogeeks] Re: addition without using arithmetic operators

2009-09-07 Thread Gokul
you can try this.. int add(int x, int y) { if (!x) return y; else return add((x & y) << 1, x ^ y); } On Sep 7, 4:01 pm, ritter wrote: > how to add two integers without using arithmetic operators? > can anyone help me. --~--~--

[algogeeks] random number...

2009-09-07 Thread ankur aggarwal
Given a random number generator that generates numbers in the range 1 to 5, how can u create a random number generator to generate numbers in the range 1 to 7. (remember that the generated random numbers should follow a uniform distribution in the corresponding range) --~--~-~--~~---

[algogeeks] Re: random number...

2009-09-07 Thread ankur aggarwal
I KNow a sol for given a rand_5() function which generates *0* to 5 and we have to find rand_7() for *0* to 7 could not think about it... On Mon, Sep 7, 2009 at 9:26 PM, ankur aggarwal wrote: > Given a random number generator that generates numbers in the range 1 to > 5, how can u create a ra

[algogeeks] Re: find triangle in a graph

2009-09-07 Thread Nagendra Kumar
is it not finding a cycle in a graph of length 3. On Sun, Sep 6, 2009 at 9:02 PM, Dufus wrote: > > The following approach might work. > Let K be the maximum degree of a vertex in the graph > Enumerate each of the n vertex as 1...n > Enumerate undirected edge between vertex i and j  (i.e. i--j

[algogeeks] Re: n balls having k colors

2009-09-07 Thread Bharath
How about using a hash. Hash element to its position in the array. This way we can preserve the order. On Sep 7, 4:33 pm, gaurav gupta <1989.gau...@googlemail.com> wrote: > Counting Sort is a good solution. This problem is same like : > > you have an array 1,3,1,3,2,6,5,7,8,5,6,4,5,2 You have to

[algogeeks] Re: addition without using arithmetic operators

2009-09-07 Thread gaurav gupta
To Add two integer you can use full adder at bit level. if bit1 and bit2 are kth bits and car is previous carry then sum = bit1 ^ bit2 ^ carry; carry = bit1.carry + bit2.carry + bit1.bit2; here ^ = bitwise zor . = bitwise and + = bitwise or repeat it for all bits of two integer,

[algogeeks] Re: n balls having k colors

2009-09-07 Thread gaurav gupta
Counting Sort is a good solution. This problem is same like : you have an array 1,3,1,3,2,6,5,7,8,5,6,4,5,2 You have to arrange them such that all number having same value should occur together and order of occurrence in series should conserve. So result will be : 1,1 ,3,3,2,2,6,6,5,5,5,7,8 ,4 O

[algogeeks] Re: addition without using arithmetic operators

2009-09-07 Thread Shobhit Bhatnagar
I think this can be done by using XOR operations...or can be done by using a loop and using increment operators (if they are allowed). On Mon, Sep 7, 2009 at 4:31 PM, ritter wrote: > > how to add two integers without using arithmetic operators? > can anyone help me. > > > > -- Thanks and Rega

[algogeeks] Re: Find longest palindrom in a give n string in O(N)

2009-09-07 Thread ankur aggarwal
nagendra.. plz show the working using an example .. take input babbaabbc On Sun, Sep 6, 2009 at 2:07 PM, Nagendra Kumar wrote: > > @all: > > T(i,j) : denotes the length of longest palindrome with start index > i and end index j index. > T(i,j )= > max { >

[algogeeks] Re: find triangle in a graph

2009-09-07 Thread ankur aggarwal
*" * > > * > @kunzmilan * > * * > *" What do you mean by polynomial of the graph ? " > * > * * --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@g

[algogeeks] Re: Find longest palindrom in a give n string in O(N)

2009-09-07 Thread Dufus
@ Ankur, IMHO suffix tree is ONE of the solution. _dufus On Sep 3, 7:37 am, ankur aggarwal wrote: > only suffix tree is the soln i think.. > > On Wed, Sep 2, 2009 at 11:20 AM, nitin mathur > wrote: > > > > > > > Hi everybody.. > > > I am sorry as the algorithm I proposed takes O(n^2) and not

[algogeeks] stock market

2009-09-07 Thread ankur aggarwal
1.Write a function to smooth out stock fluctuations. --~--~-~--~~~---~--~~ 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 gr

[algogeeks] Re: n balls having k colors

2009-09-07 Thread Dufus
How about counting sort in O(N+K) time and O(K) space. _dufus On Sep 6, 1:06 pm, ankur aggarwal wrote: > You have N balls having one of K colors. Arrange them into groups of same > colors. e.g. > > RRGRG > can be arranged as > RRRGG (Answer) > GGRRR --~--~-~--~~---

[algogeeks] Re: find triangle in a graph

2009-09-07 Thread Dufus
The following approach might work. Let K be the maximum degree of a vertex in the graph Enumerate each of the n vertex as 1...n Enumerate undirected edge between vertex i and j (i.e. i--j) as (i,j) Sort all the |E| edges in O(|V| + |E|) time // radix sort. Now (i1,i2,i3) form a triangle iff

[algogeeks] phone numbers.

2009-09-07 Thread ankur aggarwal
3.You have 50,000 html files, some of which contain phone numbers. How would you create a list of all the files which contain phone numbers? Solutions should be optimal --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups

[algogeeks] addition without using arithmetic operators

2009-09-07 Thread ritter
how to add two integers without using arithmetic operators? can anyone help me. --~--~-~--~~~---~--~~ 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

[algogeeks] Re: Z[n^2]={such that z belongs to X+Y

2009-09-07 Thread Dufus
If Z[] is allowed to modify then i think we can do in O(1) space // quite clear from the link I have posted above else we need O(k) space to restore Z[]. _dufus On Sep 6, 2:32 pm, ankur aggarwal wrote: > @dufus > wat is your complexity ?? > > On Sat, Sep 5, 2009 at 8:17 PM, Dufus wrote: > > >