[algogeeks] Re: given a stream of numbers FIND MEDIAN

2011-12-18 Thread WgpShashank
@lucifier thought to post the same post , saw the post little bit late . though other approaches exist ,its the most efficient till we have. nice job :) Thanks Shashank CSE, BIT Mesra -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To vie

[algogeeks] Re: ACM-ICPC Kanpur 2011 LCM Extreme

2011-12-18 Thread tec
the required sum is: F(n) = sum({lcm(x,y)|1<=x wrote: > long long function( int n ) { >     long long res = 0; >     for( int i = 1; i <= n; i++ ) >         for( int j = i+1; j <= n; j++ ) >                   res+=lcm(i,j); >     return res; > > } > > N<=5*10^6 and TestCases<=25000.. TimeLimit=5s >

Re: [algogeeks] zig zag problem

2011-12-18 Thread Ankur Garg
@Atul ur solution is wrong It seems u r comparing just the neighbouring elements . The question is not to find the contiguous zig-zag sequence but longest subsequence Also even in case of contiguous sequence ur solution will not print the correct length like for 6 7 4 ur solution will print answer

Re: [algogeeks] zig zag problem

2011-12-18 Thread Ankur Garg
a linear solution for this problem . although its more than O(n) but will never be O(n*2)..used DP to solve it space used -O(2n) int ZigZagLength(vector a){ int n=a.size(); int DP[n][2]; DP[0][0]=1; DP[0][1]=0; DP[1][0]=2; DP[1][1]=0; int j; for(int i=2;i0){ if((a[i]-a[j])*(a[j]-a[DP[j][1]])<0){

Re: [algogeeks] ACM-ICPC Kanpur 2011 LCM Extreme

2011-12-18 Thread SAMMM
Hi , As u can c tht test cases are huge,so we cann't go abt doing it by repeatative sum , I think it can be done using prime seive and Euler Toutient function .. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, sen

Re: [algogeeks] suggest algo

2011-12-18 Thread atul anand
@Karthikeyan : i have little doubt in you algorithm... acc to the question input stream is the stream of numbers not words. now if we consider Trie , first you have to extract digits from each input number and use those digit to created trie. so how will you get k most frequent occurring words in

Re: [algogeeks] hash to find repeated no

2011-12-18 Thread atul anand
use HashMap ... take KEY as the number to be counted and value to be count to value of given number. now every time same number appears increment value of count int the hashMap for that number. use STL to write code. On Sun, Dec 18, 2011 at 1:13 PM, venkat kumar wrote: > how to use hashing t

Re: [algogeeks] ACM-ICPC Kanpur 2011 LCM Extreme

2011-12-18 Thread Ravi Ranjan
use eucleid algorithm to calculate HCF n den use function a * b = HCF*LCM > 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 > al

[algogeeks] correctness of "point inside polygon: algorithm ?

2011-12-18 Thread WgpShashank
Would anyone will interested to discuss ? Algo is simple but i am wondering about correctness of http://en.wikipedia.org/wiki/Point_in_polygon algorithm ? Thanks Shashank CSE, BIT Mesra -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To

Re: [algogeeks] Re: doubt in TSUM

2011-12-18 Thread SAMM
@ All, The multiplication of the polynomial need to be done using FFT becoz it will take O(nlog n) where n is the number of elements in the set. For finding the triplet we need to have a equation of the form : f(x) ^3 + af(x)^2 + b f(x) . U need to to find the cofficient of a and b where f(x)

Re: [algogeeks] Re: doubt in TSUM

2011-12-18 Thread SAMM
This comment was for anubhav code which he wrote :--- U will not get correct solution with this algo becoz ur algo will not able to generate all the 3 triplets sum. You hav to loop through all the triplets ... take for example the numbers :- 1 2 3 5 6.. Ur algo will generate the following t

[algogeeks] ACM-ICPC Kanpur 2011 LCM Extreme

2011-12-18 Thread arun kumar
long long function( int n ) { long long res = 0; for( int i = 1; i <= n; i++ ) for( int j = i+1; j <= n; j++ ) res+=lcm(i,j); return res; } N<=5*10^6 and TestCases<=25000.. TimeLimit=5s Can anyone give hints to solve this ? Thanks in advance ! -- You receive

Re: [algogeeks] suggest algo

2011-12-18 Thread atul anand
we can use hashtable to maintain count of each number coming from the file. now make a MIN heap of size K now every time a count is updated in the hastable , compare it with the root of the Min heap. if root of heap is smaller then replace it with new greater count and then heapify again. In the e

Re: [algogeeks] Re: doubt in TSUM

2011-12-18 Thread anubhav raj
@shamm:it means if we want for triplet do we nd 2 go for 3 time multiplication of polynomial and den division of coefficient by 3.. -- 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.co

Re: [algogeeks] zig zag problem

2011-12-18 Thread atul anand
complexity of this algo is O(n) ..I guess it is better than dynamic programming approach which is O(n^2). On Sat, Dec 17, 2011 at 6:28 PM, atul anand wrote: > please see the algo and let me know if i am doing it wrong:- > > toggle= arr[i+1] > arr[i]; > subseq=0; > > for( i=0 ; i { > >

Re: [algogeeks] suggest algo

2011-12-18 Thread Karthikeyan V.B
Trie data structure can be used... In the trie, you can record item count in each node representing frequency of word consisting of characters on the path from root to current node. The time complexity to setup the trie is O(Ln) (where L is number of characters in the longest item). To find the t

Re: [algogeeks] Re: doubt in TSUM

2011-12-18 Thread Karthikeyan V.B
Hi, Actually i m sorry since i didn explain the algo fully i checked with the code the o/p is: run: 6:1 7:0 8:1 9:2 10:2 11:1 12:1 13:1 14:1 where sum 9 has two triplets so,totally (1+0+1+2+2+1+1+1+1=10) Regards, KARTHIKEYAN.V.B PSG TECH CBE -- You received this message because you are s

[algogeeks] Re: suggest algo

2011-12-18 Thread SAMMM
How about using a Tournament tree . As the size of the size of huge we heap is better option to opt for , which is also been implemented in Tournament tree , and when the same element come more than once just increment the count for the Frequency of the Internal Node . The leaves will contain eithe

[algogeeks] hash to find repeated no

2011-12-18 Thread venkat kumar
how to use hashing to find repeated no in an array? pls give me code in c? -- 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 algogee