[algogeeks] Binary Tree

2010-10-23 Thread Harshal
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 each level..pls suggest a way to do that. -- Harshal

[algogeeks] Re: Binary Tree

2010-10-23 Thread Mridul Malpani
do BFS. On Oct 23, 6:31 pm, Harshal hc4...@gmail.com 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

[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

[algogeeks] Re: Binary Tree

2010-10-23 Thread juver++
When visiting appropriate vertex v, increment counter + +levels[current_depth] and go further. You may done this using DFS or BFS. On 23 окт, 17:31, Harshal hc4...@gmail.com wrote: hi, i need to find the number of nodes at each level of a binary tree..the binary tree may not be balanced..

Re: [algogeeks] BST Question

2010-10-23 Thread nishaanth
@Praveenit is not possible..in a BST *all the nodes* on the right subtree are greater than the node :) On Sat, Oct 16, 2010 at 3:26 PM, Praveen Baskar praveen200...@gmail.comwrote: @nishaanth: wat if the left child of the right node has a negative value On Thu, Oct 14, 2010 at 11:12 AM,

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

2010-10-23 Thread nishaanth
It is nothing but a common subsequence problem...isnt it ? On Wed, Oct 13, 2010 at 3:42 PM, Mridul Malpani malpanimri...@gmail.comwrote: @ 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.

[algogeeks] Re: 10 most repeating words

2010-10-23 Thread Chi
I've written a kart-trie in php. You can easily extend yourself the payload to count the word frequency. http://sourceforge.net/projects/kart-trie After you build your dictionary from your large file, you can easily find the highest frequency be recursively search the trie. It should be faster

[algogeeks] Easy A

2010-10-23 Thread el3lam
http://www.series.el3lam.com/293.html -- 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

Re: [algogeeks] Finding parallel edges in graph

2010-10-23 Thread preetika tyagi
Parallel edges mean? On Thu, Oct 21, 2010 at 3:22 AM, Algorithimist yogi15...@gmail.com wrote: Design an algorithm to determine whether a graph has any parallel edges in time proportional to E + V. -- You received this message because you are subscribed to the Google Groups Algorithm

[algogeeks] Re: 10 most repeating words

2010-10-23 Thread Chi
The biggest weakness of the trie is the amount of space it wastes - chances are there will be runs of characters with a word only at the end, meaning a bunch of extra levels of the tree that aren't needed. The PATRICIA trie, or radix trie, attempts to address this by allowing the 'decision' at

[algogeeks] Algorithm to find whether any 3point on the same line

2010-10-23 Thread Meng Yan
Given n point on the plane, find out whether any 3point on the same line. How to use recursion to solve the problem? Could you help me find the algorithm and give the time complexity? Bests, Claire -- You received this message because you are subscribed to the Google Groups Algorithm Geeks

Re: [algogeeks] Algorithm to find whether any 3point on the same line

2010-10-23 Thread preetika tyagi
Is there any specific need to use recursion? One alternate is to find slope and constant (m and c) for every pair of points and same value of m c will specify the points on the same line. Time complexity is O(n*n). On Sat, Oct 23, 2010 at 4:31 PM, Meng Yan mengyan.fu...@gmail.com wrote:

Re: [algogeeks] Algorithm to find whether any 3point on the same line

2010-10-23 Thread Meng Yan
there are (n*(n-1))/2pairs of points. I think if we use your method, the time complexity should be O(n^4). Is it possible to put all points into k different domain and using T(n)=T(n/k)+f(n) to solve this problem? On Sat, Oct 23, 2010 at 7:51 PM, preetika tyagi preetikaty...@gmail.comwrote: Is

[algogeeks] Re: Algorithm to find whether any 3point on the same line

2010-10-23 Thread Dave
I gave an O(n^2 log n) algorithm to find the maximal number of collinear points in a set is given in http://groups.google.com/group/algogeeks/msg/d329dda12b332dd1. A fairly simple modification could answer the question as to whether any three points are collinear. Dave On Oct 23, 6:31 pm, Meng

Re: [algogeeks] Re: Algorithm to find whether any 3point on the same line

2010-10-23 Thread Meng Yan
Thank you! By the way, to do the 'sort s(i+1:n)', if I use counting sort, I think it should be better. imax = 0 // location of longest string of duplicate slopes lmax = 0 // length of longest string of duplicate slopes smax =

Re: [algogeeks] Algorithm to find whether any 3point on the same line

2010-10-23 Thread preetika tyagi
You have to scan every pair of points only once to get the value of 'm' and 'a', so the time complexity would be O(n^2). On Sat, Oct 23, 2010 at 6:22 PM, Meng Yan mengyan.fu...@gmail.com wrote: there are (n*(n-1))/2pairs of points. I think if we use your method, the time complexity should be

Re: [algogeeks] BST Question

2010-10-23 Thread Praveen Baskar
i think it is possible nishaanth please do take a look at this example -10 /\ -11 8 /\ -5 10 -5 is greater than -10 On Sat, Oct 23, 2010 at 11:19 PM, nishaanth

Re: [algogeeks] BST Question

2010-10-23 Thread preetika tyagi
@Praveen- In this case, we will not ignore the right subtree of the root (-10, which is less than zero) while traversing the tree. On Sat, Oct 23, 2010 at 9:06 PM, Praveen Baskar praveen200...@gmail.comwrote: i think it is possible nishaanth please do take a look at this example

[algogeeks] Re: Algorithm to find whether any 3point on the same line

2010-10-23 Thread Dave
@Meng Yan: s is an array of real numbers, not integers, so perhaps a counting sort is not applicable. Dave On Oct 23, 10:51 pm, Meng Yan mengyan.fu...@gmail.com wrote: Thank you! By the way, to do the 'sort s(i+1:n)', if I use counting sort, I think it should be better.

[algogeeks] Re: Algorithm to find whether any 3point on the same line

2010-10-23 Thread Dave
@Preetika: Then you have to look for duplicates in an array of n(n-1)/ 2 real numbers. I think this takes the complexity above O(n^2). Dave On Oct 23, 10:54 pm, preetika tyagi preetikaty...@gmail.com wrote: You have to scan every pair of points only once to get the value of 'm' and 'a', so the

[algogeeks] Re: Binary Tree

2010-10-23 Thread ankit agarwal
Do level order traversal using two queues. On Oct 23, 8:19 pm, juver++ avpostni...@gmail.com wrote: When visiting appropriate vertex v, increment counter + +levels[current_depth] and go further. You may done this using DFS or BFS. On 23 окт, 17:31, Harshal hc4...@gmail.com wrote:

Re: [algogeeks] Re: Algorithm to find whether any 3point on the same line

2010-10-23 Thread ravindra patel
Can be done in O(n^2) time using the slope as people suggested above. 1- Sort the points in increasing order of x cord. O(nlogn) 2- prepare a n*n matrix A where A[i,j] = slope( point(i), point(j) ) - O(n^2) [Note that point i and j are sorted in increasing order of x] 3- find a pair of A[i,j]

Re: [algogeeks] Re: Algorithm to find whether any 3point on the same line

2010-10-23 Thread preetika tyagi
For duplicates, either we can sort or use a Hash Set at the cost of extra space. While traversing all the points for slope etc calculation, insert the point into hash set. If a point already exists, skip it. Like this, we are calculating the slope and keeping track of distinct points in a single

Re: [algogeeks] Re: Binary Tree

2010-10-23 Thread preetika tyagi
@Ankit- I think it can be done using a single queue also. 2010/10/23 ankit agarwal ankit.agarwal.n...@gmail.com Do level order traversal using two queues. On Oct 23, 8:19 pm, juver++ avpostni...@gmail.com wrote: When visiting appropriate vertex v, increment counter +