Re: [algogeeks] Re: Frequency Sort Algo

2011-12-25 Thread praveen raj
Hashmapping O(n) On 25-Dec-2011 2:15 AM, sravanreddy001 sravanreddy...@gmail.com wrote: any better approach than O(N log N) time? maintain a heap of nodes value, count for each element, if already present increase the count. Else add the elements. Max-Heap -- fetch the node, print it

[algogeeks] Re: Frequency Sort Algo

2011-12-25 Thread top coder
What about the case of the numbers having same frequency? Which one should come first? On Dec 24, 11:18 pm, atul anand atul.87fri...@gmail.com wrote: first sort the given array , you will get 1,1,1,1,2,2,2,3,3,3,3,3,4,4,5 now count frequency of each number and insert it into min heap. each

Re: [algogeeks] Re: Frequency Sort Algo

2011-12-25 Thread Ankur Garg
@Atul..your solution is correct and would do the job but its complexity wud be nlogn . Any better way of solving it ? Regards Ankur On Sun, Dec 25, 2011 at 2:10 AM, sravanreddy001 sravanreddy...@gmail.comwrote: any better approach than O(N log N) time? maintain a heap of nodes value, count

[algogeeks] Re: Facebook Question

2011-12-25 Thread SVIX
AND, for two points to be close, they need not be on the same quadrant On Dec 21, 10:55 pm, atul anand atul.87fri...@gmail.com wrote: to find all points which lies on the same quadrant for a specific node(say 1) , we have to check all nodes...rite?? we have to find difference b/w 2 node(frome

Re: [algogeeks] Re: Frequency Sort Algo

2011-12-25 Thread Ankur Garg
fpr the nos with same frequency , the one having lower value shud come first For ex 3,1,1,3,1,3,2 Here 1 should come first so 2,1,1,1,3,3,3 On Sun, Dec 25, 2011 at 11:18 AM, top coder topcode...@gmail.com wrote: What about the case of the numbers having same frequency? Which one should

Re: [algogeeks] Re: which is the right data structure to use for a given problem ?

2011-12-25 Thread Carol Smith
When two persons have same name and we use one hashtable(HT), what happens inside HT is entirely depends on HT implementation. In this case, HT may chain the values when keys match. When querying the HT for this key, HT returns all the values chained under this key and developer has to iterate and

Re: [algogeeks] Re: Facebook Question

2011-12-25 Thread Piyush Kansal
@Gene, The algorithm which you have given below is O(n^2). I tried too and could not figure out anything better than this unless we go for data structures like kd-trees, as you already suggested. Is it really the case that w/o using kd-tree, there is no better algorithm? On Fri, Dec 23, 2011 at

Re: [algogeeks] LINKED LIST

2011-12-25 Thread Ashish Goel
refer stanford page 1,2,3,4,5,6 will become 5,3,1 6,4,2 void MoveNode(struct node** destRef, struct node** sourceRef) { struct node* newNode = *sourceRef; // the front source node assert(newNode != NULL); *sourceRef = newNode-next; // Advance the source pointer newNode-next = *destRef; // Link

Re: [algogeeks] Re: Frequency Sort Algo

2011-12-25 Thread atul anand
@ankur : if i am able to figure out a better solution , i will post.but i guess nlogn is the best we can get. On Sun, Dec 25, 2011 at 4:50 PM, Ankur Garg ankurga...@gmail.com wrote: @Atul..your solution is correct and would do the job but its complexity wud be nlogn . Any better way of

Re: [algogeeks] Re: which is the right data structure to use for a given problem ?

2011-12-25 Thread Piyush Kansal
@atul: I dont think you should make this assumption entering at should list down all the phone numbers starting with at. It should be rather taken as at can occur anywhere in the name (beginning, mid or end). This is how it works in Android(I have android based phone and I checked it personally).

Re: [algogeeks] LINKED LIST

2011-12-25 Thread atul anand
@ashish : please provide link for that page On Sun, Dec 25, 2011 at 10:36 PM, Ashish Goel ashg...@gmail.com wrote: refer stanford page 1,2,3,4,5,6 will become 5,3,1 6,4,2 void MoveNode(struct node** destRef, struct node** sourceRef) { struct node* newNode = *sourceRef; // the front

Re: [algogeeks] LINKED LIST

2011-12-25 Thread atul anand
@ashish : acc to Karthikeyan question ...output should not be in reverse order. there is not much difference b/w both implementation. it will become little interesting if you try to solve using recursion . On Sun, Dec 25, 2011 at 10:36 PM, Ashish Goel ashg...@gmail.com wrote: refer stanford

Re: [algogeeks] Re: Frequency Sort Algo

2011-12-25 Thread Piyush Kansal
LSD Radix sort can be used: - First, it will sort the no. This will take O(k.n) (k: max no of digits in a number; n: no of integers) - Second, since the no are now sorted, scan all the integers and get their frequency count. O(n) - Use radix sort again to sort the frequency count in decreasing