Hey Swathi,
The problem does mention any path but refers to straight paths along
a root to leaf path. Therefore, a path need not necessarily start from
the root or end with a leaf but should be along the path from the root
to a leaf.
On Nov 25, 4:05 am, Swathi chukka.swa...@gmail.com wrote:
@ piyush: u dont need to work with queues, just modify the height
function...
int findDiameter(node *root,int *p){
printf(hi\n);
//if(root-left==NULL root-right==NULL) return 0;
if(root!=NULL){
int l,r;
l=findDiameter(root-left,p);
@amit jaspal..I am not able to understand how will u be saving the
nodes for which the largest diameter existsI know how to find the
largest diameter but the question was to find the nodes too for which
the largest diameter exists...please correct me if I missed something
On 5/30/11, Amit
Dudethe question was to find the two nodes also for which the
maximum distance exists.in ur code there is nothing as
suchkindly read the question carefully before posting...
On 5/31/11, bittu shashank7andr...@gmail.com wrote:
HI All Yes It The Diameter of BT . Can be done in O(N)
@piyush,
Hi, thanks alot for the solution,
Thats to find the diameter of a tree. :)
But, how would you obtain the 2 nodes which have the max. distance
betwn them?
On May 30, 1:17 pm, Vipul Kumar vipul.k.r...@gmail.com wrote:
That is same as finding the diameter of the tree.
On Mon, May
simplest algo: find a node with max depth M and go up tree calculating max
depth of all upper branches that do not contain M until reaching root node
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
@ross...I think it can be done by taking a queue/stack...I am working on the
code...Please comment if there is any error in my approach..
On Mon, May 30, 2011 at 2:19 PM, Maksym Melnychok keym...@gmail.com wrote:
simplest algo: find a node with max depth M and go up tree calculating max
depth
this is a very standard problem :D
start with any node(x) find the node which is at maximum distance.
now start with x travese the tree and find the node(y) which is at maximum
distance.
so finally answer wil be (x, y)
traversing the tree two times. so the order for finiding the such nodes
little modification
start with any node(r) find the node(x) which is at maximum distance.
--
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
I think following algo will work..I haven't tested it plus its in its crude
form...Kindly correct me if i am wrong..
*typedef struct queue
{
struct node *q[2];
int h1,h2;
}queue;*
**
*queue max_dist(struct node * tree)
{
if (tree == NULL)
return;
queue q1,q2,q3;
q1.h1 =
won't this simple algo work ??
start from root node, say it has value 0
at any time if a node has a value v
pass v-1 to left subtree and v+1 to right subtree
keep track of max and min
final answer will be max -min = Diameter of tree.
correct me if i m wrong.
--
You received this message
nope, it will not work :(
got a case
On Mon, May 30, 2011 at 11:57 PM, sunny agrawal sunny816.i...@gmail.comwrote:
won't this simple algo work ??
start from root node, say it has value 0
at any time if a node has a value v
pass v-1 to left subtree and v+1 to right subtree
keep track of max
Right!! that is pretty standard problem but the solution u have given
is for undirected graphs and intuitively binary trees are directed.
Piyush solution will work for binary tree.
On May 30, 2:04 am, anshu mishra anshumishra6...@gmail.com wrote:
this is a very standard problem :D
start with
13 matches
Mail list logo