Re: [algogeeks] Re: Given a node of BST make it the root

2011-10-31 Thread kumar raja
@Dave : Wonderful answer sir.. On 31 October 2011 12:50, Dave wrote: > @Ankuj: Your method would be O(n), where n is the number of nodes in > the tree. However, it can be done with a sequence of tree rotations. > If the desired node is not the root of the tree, rotate it with its > parent. This

Re: [algogeeks] Interview question

2011-10-31 Thread shady
from where does the index starts, 0 or 1 ? in this, array to be moved is {7, 5, 8} ? and source array the destination | | {9, 7, 5, 8, 1, 5, 4, 8, 10, 1} please explain move_set o

Re: [algogeeks] Microsoft Question

2011-10-31 Thread Anup Ghatage
:) On Tue, Nov 1, 2011 at 12:54 AM, WgpShashank wrote: > @Anup You Seems to Active Member , u remembered that :) > > +1 to You. > > Thanks > Shashank > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To view this discussion on the web

[algogeeks] Re: Print all path of the tree that sums up to the given value

2011-10-31 Thread Ankuj Gupta
No constraint on path. Though it is not necessary that it starts from root only On Oct 31, 10:02 pm, Prakash D wrote: > any constraints for path? > > > > > > > > On Mon, Oct 31, 2011 at 11:19 AM, Ankuj Gupta wrote: > > Print all path of the tree that sums up to the given value. The path > > may

[algogeeks] Re: Given a node of BST make it the root

2011-10-31 Thread Dave
@Ankuj: Your method would be O(n), where n is the number of nodes in the tree. However, it can be done with a sequence of tree rotations. If the desired node is not the root of the tree, rotate it with its parent. This preserves the BST property and makes the desired node one level closer to the ro

Re: [algogeeks] Microsoft Question

2011-10-31 Thread WgpShashank
@Anup You Seems to Active Member , u remembered that :) +1 to You. Thanks Shashank -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/qRJslcZjhboJ. To post t

Re: [algogeeks] Re: What Data Structure to use ?

2011-10-31 Thread mohit verma
@shashank , i agree. To reduce this overhead , we can implement prefix trie in bit-form or DAWG or lots of compression techniques are there at the cost of complex coding. On Tue, Nov 1, 2011 at 12:35 AM, WgpShashank wrote: > @Mohit Space Overhead Will be more if m,n are large isn't it ? > > > S

[algogeeks] Re: Minimize bins

2011-10-31 Thread WgpShashank
Search For Bin Packing Problem on Wiki . Thanks Shashank -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/qM4k1vJneRoJ. To post to this group, send email

[algogeeks] Re: printK Distance Nodes

2011-10-31 Thread SAMMM
My Dear friend , For Getting the Path above the source node here is the simple step .. The below table illustrates it :- During traversing the in BFS way from the root until we find the source node . Current Node = a | b c | d e Distance from Root = 0 | 1 1 | 2 2 PrevNode

Re: [algogeeks] Re: What Data Structure to use ?

2011-10-31 Thread WgpShashank
@Mohit Space Overhead Will be more if m,n are large isn't it ? Shashank -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/Z9zOwDig0mMJ. To post to this grou

[algogeeks] Convert N-Ary Tree to Singly Linked List

2011-10-31 Thread WgpShashank
structure of n-ary tree Class:Node String:label List children Method List TreeToLinkedList(Node n) { return list; } return List of all nodes; [image: image.png]Pics Taken From Google Image . N-Ary Tree Output head-> 1-2-3-4-5-6-7-8-9

[algogeeks] Re: Reconstruct BST from preorder traversal

2011-10-31 Thread Ankuj Gupta
I had a doubt , if we simply go on constructing the tree from preorder traversal one gets the same tree back am I missing something here On Oct 19, 7:49 am, sravanreddy001 wrote: > @Sunny, Rahul: > Thanks a lot.. :) > > @Anshu: the code is perfect,  This would be  h = n* (height of BST) --> O

Re: [algogeeks] Re: What Data Structure to use ?

2011-10-31 Thread mohit verma
One (compressed-optional) prefix trie with each course ptrs to students and another prefix tree for students having ptrs to courses. Guaranteed O(m) search time instead of O(n*m) if using hash table where m avg size of word at hand to be compared to n nodes. On Sun, Oct 30, 2011 at 7:31 PM, WgpSha

Re: [algogeeks] Maximize Subsquare

2011-10-31 Thread SAMM
Any body got any idea of just how to approach It need a DP algo. On 10/30/11, SAMMM wrote: > Suppose u have a square matrix, where every cell is filled with 0 or > 1 . U need to find the maximum subsquare such that all four borders > are filled with all 1s. > > Ex:- > > 1 0 0 1 1 0 > 1 0 1 1

Re: [algogeeks] Dp solution for this problem?

2011-10-31 Thread mohit verma
thnx all On Mon, Oct 31, 2011 at 10:13 PM, Vandana Bachani wrote: > Hi Mohit, > Bellman-Ford algorithm is a dynamic programming algorithm but u need it > only if dijkstra's SP wont solve the problem... and Dijkstra's algo works > only for +ve weights. So if u r sure that there maybe negative weig

Re: [algogeeks] Problem

2011-10-31 Thread SAMM
This is like the TOPOLOGY SORT . Repeat the steps until all the elements of orginal set is visited:- Do First need to add all those elements in a set whose inorder is Zero . Then create another set whose inorder is 1 , after making set 1 , then decrease the inorder by 1 for those elements who was

Re: [algogeeks] Print all path of the tree that sums up to the given value

2011-10-31 Thread Prakash D
any constraints for path? On Mon, Oct 31, 2011 at 11:19 AM, Ankuj Gupta wrote: > Print all path of the tree that sums up to the given value. The path > may start from any node. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post

Re: [algogeeks] Problem

2011-10-31 Thread teja bala
+1 abhishek On Mon, Oct 31, 2011 at 6:26 PM, abhishek kumar wrote: > Represent the dependencies as a graph. Store all the values in a list. For > each vertex in the graph find all values for which there is no edge from > the vertex. If these values are there in the list, remove them from the > l

[algogeeks] Binary tree to BST

2011-10-31 Thread Ankuj Gupta
How to convert a Binary tree to BST ? Naive way is to create each node of Binary tree one by one and keep on creating the BST. -- 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. T

[algogeeks] Given a node of BST make it the root

2011-10-31 Thread Ankuj Gupta
Given a node of a BST, modify it in such a way that the given node becomes the root. The tree should still be BST. One way I could get is store the Inoder traversal of the tree. Find that node in the traversal and recursively make the BST. -- You received this message because you are subscribed t

Re: [algogeeks] Dp solution for this problem?

2011-10-31 Thread Vandana Bachani
Hi Mohit, Bellman-Ford algorithm is a dynamic programming algorithm but u need it only if dijkstra's SP wont solve the problem... and Dijkstra's algo works only for +ve weights. So if u r sure that there maybe negative weights then you will need to use bellmann ford which is a DP algo. On Mon, Oct

[algogeeks] Re: printK Distance Nodes

2011-10-31 Thread Ankuj Gupta
I am not getting what you said. For given tree a(2)b(7)c(5)d(2)e(6)f(9)g(5)h(11)i(4) if i say given node is 6 and distance is 1 then the output should be 7,5,11. The nodes below the given nodes can be easily printed. I am not getting the way to print nodes above the given node On Oct 31, 1:30 

Re: [algogeeks] Re: Dp solution for this problem?

2011-10-31 Thread Piyush Kapoor
There are cycles in recursion,there is no recursion tree over here, which can be traversed in bottom up fashion,so no DP. Shortest path algorithms will be the answer On Mon, Oct 31, 2011 at 9:30 PM, Don wrote: > Use a path cost matrix of the same size as the given matrix. Set all > locations to

[algogeeks] Re: Dp solution for this problem?

2011-10-31 Thread Don
Use a path cost matrix of the same size as the given matrix. Set all locations to a maximum cost value. Use a queue to store locations which still need to be processed. Start by setting the cost to the destination equal to the cost of that location and adding that location to the queue. Then, while

Re: [algogeeks] Re: Unique partition

2011-10-31 Thread mohit verma
yeah , my algo wont work for these cases :(. On Mon, Oct 31, 2011 at 6:32 PM, sunny agrawal wrote: > @Mohit > that will also not work > example: {1,1,1,2,2,2,3,3,3} > > i think all the methods that try to fill the matrix(considering k sets as > k rows) either horizontally or vertically will fail

Re: [algogeeks] Problem

2011-10-31 Thread abhishek kumar
Represent the dependencies as a graph. Store all the values in a list. For each vertex in the graph find all values for which there is no edge from the vertex. If these values are there in the list, remove them from the list and create a set of the vertex and the removed values. If the values are n

Re: [algogeeks] Re: Unique partition

2011-10-31 Thread sunny agrawal
@Mohit that will also not work example: {1,1,1,2,2,2,3,3,3} i think all the methods that try to fill the matrix(considering k sets as k rows) either horizontally or vertically will fail we need to fill these both horizontally and vertically at the same time depending upon the frequency of elements

Re: [algogeeks] Re: Unique partition

2011-10-31 Thread mohit verma
Hi SAMM, The above code is not clear enough to understand . Sorry for that. My idea was , like for above example : map will contain frequency of all distinct elements. so freq[1] = 6 freq[3]= 1 freq[5]=1 freq[6]=1 Now for n=9 and k=3 P1={1,3,5}; and now after this partition freque

Re: [algogeeks] Dp solution for this problem?

2011-10-31 Thread mohit verma
I knew this could be done using Min Path finding algo. But what about DP for this problem , guys? On Mon, Oct 31, 2011 at 3:49 AM, SAMM wrote: > This can be done using the Dijkstra's algorithm , Start frm the source > frm the Destination (In this example from (2 2)) . You need to > consider the

[algogeeks] simpel DP solution

2011-10-31 Thread mc2 .
Hey guys , I am trying to solve this DP problem : http://community.topcoder.com/stat?c=problem_statement&pm=10033&rd=13513 SRM 422, DIV 2 ,level 2. Here is my DP solution. But it is not working. Can someone please tell me the flaw in this code : #include"topheader.h" int prime(int i) { retur

[algogeeks] Problem

2011-10-31 Thread Bharath 2009503507 CSE
Given a set of values..in which there are some dependencies.. Eg.. x y z a b Dependencies: x,y a,z Note that dependency is not transitive..Is it possible to separate these elements into sets such that no two elements in the same set are dependant and we should end up with the least number of se

[algogeeks] Re: printK Distance Nodes

2011-10-31 Thread SAMMM
As the problem states that the distance can be upwards and downwards . So we considering both the case . I am going to implement BFS to implement it (Because requires the poped elements to trace back to the Source node to check whether path is sorted) Consider the tree Given in this link .. I am

[algogeeks] Print all path of the tree that sums up to the given value

2011-10-31 Thread Ankuj Gupta
Print all path of the tree that sums up to the given value. The path may start from any node. -- 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, sen