binary tree question
From: Sebi (harko_at_cluj.astral.ro)
Date: 02/23/04
- Previous message: The Lord of Chaos \(Suresh Devanathan\): "Re: P vs NP and the analog machine"
- Next in thread: Ben Pfaff: "Re: binary tree question"
- Reply: Ben Pfaff: "Re: binary tree question"
- Reply: Gila Morgenstern: "Re: binary tree question"
- Reply: Orlondow: "Re: binary tree question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 23 Feb 2004 12:24:58 -0800
given a binary tree is there any way to find the level that contains
the highest number of nodes but without using an additional array for
storing the number of nodes on each level. ?
1
/ \
2 3
/ \ / \
4 5 6 7
/
8
in the example above the third level is the level with the highest
number of nodes.
my code is something like:
int nodes[1000];
void preOrder(BinaryTreeNode t,int level)
{
if (t != null)
{
nodes[level]=nodes[level]+1;
preOrder(t.leftChild,level+1);
preOrder(t.rightChild,level+1);
if (nodes[level] > maxlevel)
maxlevel=level;
}
}
is there anyway to do this thing without using that array ? maybe by
using a recursive function ?
- Previous message: The Lord of Chaos \(Suresh Devanathan\): "Re: P vs NP and the analog machine"
- Next in thread: Ben Pfaff: "Re: binary tree question"
- Reply: Ben Pfaff: "Re: binary tree question"
- Reply: Gila Morgenstern: "Re: binary tree question"
- Reply: Orlondow: "Re: binary tree question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|