[algogeeks] Re: k nearest points

2010-12-07 Thread Mridul Malpani
i think it can be done in O( nlogk) using heap. i cant get how u can do it (n + klgn) time. On Dec 6, 4:49 pm, alexsolo wrote: > look here:http://en.wikipedia.org/wiki/Kd-tree -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this

[algogeeks] Re: 10 most repeating words

2010-10-23 Thread Mridul Malpani
use 2 datstructure : TRIE and an array of words along with their frequency. we can solve it in following step: 1) scan each word of the large file. insert the current word into the TRIE if not present already. update the frequency. using TRIE, the time complexity is O(L), where l is the total

[algogeeks] Re: Binary Tree

2010-10-23 Thread Mridul Malpani
do BFS. On Oct 23, 6:31 pm, Harshal wrote: > hi, i need to find the number of nodes at each level of a binary tree..the > binary tree may not be balanced.. > > output: > Level 0 - 1 node > Level 1 - 2 nodes > Level 2-  3 nodes > > and so on..based on the tree structure..I am not able to count at

[algogeeks] Re: Duplicate in an array

2010-10-22 Thread Mridul Malpani
@ mahesh i didnt get ur algo. why it will work?? plz expalin.. On Oct 20, 3:49 pm, Mahesh_JNU wrote: > Just add the number of the array and let the sum is S. Its complexity is > O(n). > Now XOR all elements of the array and say the result is X_SUM.Its complexity > is  O(n). > Now the duplicate e

[algogeeks] Re: how would you find the integer pairs which sum to m in o(n) time complexity

2010-10-22 Thread Mridul Malpani
if array is not sorted, then how u are solving it in O(n) using bitset. will u plz explain?? On Oct 22, 9:15 pm, "juver++" wrote: > You may use C++ bitset. It requires O(Max / 8) bytes for space. > If the array is sorted, there is O(n) solution with O(1) space > complexity: > keep two pointers, l

[algogeeks] Re: Maximum set of Collinear points

2010-10-18 Thread Mridul Malpani
@dave Thanx. On Oct 16, 12:25 am, Asquare wrote: > @Dave - > > Got it..!! thanks :) -- 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

[algogeeks] Re: Maximum set of Collinear points

2010-10-14 Thread Mridul Malpani
by forming n*n pairs of points. now you have to select any 2 pair such that these 2 set have atleast 1 points in common, and their slope must be equal. this will take O(n^4). correct me, if i m wrong. On Oct 14, 7:00 am, Dave wrote: > @Asquare. Yes, you are wrong. If the slope of the line AB eq

[algogeeks] Re: Smallest window of K[] in N[]. Best order solution

2010-10-13 Thread Mridul Malpani
@ ankit agarwal, you are right. thanx man. On Oct 13, 11:37 am, prodigy <1abhishekshu...@gmail.com> wrote: > Let I,Q be input array,query array respectively. > > 1. Sort query array. O(klogk) > 2. Allocate an array A of size N. > 3. Fill A such that A[i]= position of Q[i] in I, -1 if not present i

[algogeeks] Maximum set of Collinear points

2010-10-13 Thread Mridul Malpani
There are n points in 2d space.we have their (x,y) co-ordinates. you have to find the maximum set of points that are colinear? I have used brute force, time =O(n^4). he wants a solution in O(n^3 or n^2). -- You received this message because you are subscribed to the Google Groups "Algorithm Geek

[algogeeks] Re: Smallest window of K[] in N[]. Best order solution

2010-10-10 Thread Mridul Malpani
it can be solved in O(n). let query array be b[k] and array of int is a[n], int j=i=0, s=-1; for(i=0;i wrote: > @prodigy: how is it coming O(nlogk) can u explain??? -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send

[algogeeks] Re: Largest Rectangle in a binary Matrix:

2010-10-10 Thread Mridul Malpani
@ ashish agarwal ur solution will not work on this : 10101 0 1 11000 On Oct 10, 6:59 pm, ashish agarwal wrote: > This question was asked in google interview > one solution for this question is DP > make a matrix p (all rows and columns are initialized to zero) > if(a[i][j]==1]{ > p[i][

[algogeeks] Re: Duplicate in an array

2010-10-10 Thread Mridul Malpani
can this problem be solved in O(n) time and in O(1) space? On Oct 6, 10:41 pm, ligerdave wrote: > @mukesh, nope, you do not need to know the range. are you thinking > about array? ankit's solution is the implementation of "bucket" > logic. > > On Oct 6, 11:47 am, Mukesh Gupta wrote: > > > @Ankit

[algogeeks] Re: first k digits of n^n.

2010-10-09 Thread Mridul Malpani
:17 pm, Dave wrote: > > > @Mridul: Does it work for k = 50? > > > On Oct 5, 5:09 am, Mridul Malpani wrote: > > > > use log properties (mantissa) to calculate the first k digit of n^n. > > > > i am giving u working code, which gives answer in answer variabl

[algogeeks] Re: Birds on wire

2010-10-08 Thread Mridul Malpani
i think we can use poisson distribution formulae for it. On Oct 7, 2:02 pm, malli wrote: > An interesting puzzle. Assume size of each bird to be negligibly > small. Please provide your answers with analysis. > > Take a wire stretched between two posts, and have a large number of > birds land on

[algogeeks] Re: Ternary Huffman Algorithm

2010-10-05 Thread Mridul Malpani
its same. instead of taking min 2, select mnimum 3. but since the no.of symbols may not form complete 3-ary tree, so add some dummy variable with value=0 (highest priority). extend this logic for n symbols. On Oct 5, 12:21 pm, pre lak wrote: > Hi all, > Pls help me with the following problem..

[algogeeks] Re: first k digits of n^n.

2010-10-05 Thread Mridul Malpani
use log properties (mantissa) to calculate the first k digit of n^n. i am giving u working code, which gives answer in answer variable, double dummy =0; f= (double)pow(10,modf((double)n*log10((double)n),&dummy)+k-1); answer=(int)f; On Oct 4, 9:03 pm, navin wrote: > http://www.codechef.com/probl

[algogeeks] Re: iTS aLL gOOGLE- iNTERVIEW

2010-10-03 Thread Mridul Malpani
Will u plz elaborate ur solution. give the algo to how to find all binary trees. On Oct 2, 9:51 pm, "Harshal ..Bet oN iT!!" wrote: >  2) We need to find the all complete binary trees using 3 of the (+,*,/,-) > at a time as internal nodes and n1,n2,n3,n4 as leaves, and then inorder > traversal of

[algogeeks] Re: apple problem

2010-10-03 Thread Mridul Malpani
is case. Correct me if I am wrong > > On Sat, Oct 2, 2010 at 8:27 AM, Mridul Malpani wrote: > > > @ anand: the code u have given is an greedy approach. & it will not > > work. > > > On Oct 1, 12:34 am, Anand wrote: > > > Here is a code for solving the problem

[algogeeks] Re: Sort in Linear time O(n)

2010-10-03 Thread Mridul Malpani
a storage cost: > you need R buckets. > > On Oct 2, 3:04 pm, Mridul Malpani wrote: > > > Radix sort is independent of the range and only depends on the number > > of items. > > > here  k=max value= n^3. > >  since , radix sort is independent of k, so here also

[algogeeks] Re: Sort in Linear time O(n)

2010-10-02 Thread Mridul Malpani
Radix sort is independent of the range and only depends on the number of items. here k=max value= n^3. since , radix sort is independent of k, so here also it sorts "n integers" in O(n). On Oct 2, 10:38 pm, "Harshal ..Bet oN iT!!" wrote: > this theorem is true for comparision sorts only! cou

[algogeeks] Re: apple problem

2010-10-02 Thread Mridul Malpani
@ anand: the code u have given is an greedy approach. & it will not work. On Oct 1, 12:34 am, Anand wrote: > Here is a code for solving the problem using DP.http://codepad.org/AoPtCmwA > > On Thu, Sep 30, 2010 at 3:01 AM, Modeling Expert < > > cs.modelingexp...@gmail.com> wrote: > > recurssion...