I should mention it's a binary tree, not necessarily complete. Though,
i don't think BFS search has anything to do with tree being complete.
Child's position will be calculated from parent positions.
leftchildX = parentX - value(based on level)
rightchildY = parentY + value(based on level)
On
how will u then take care of spaces ?
Sanju
:)
On Sun, Aug 28, 2011 at 8:18 AM, Navneet navneetn...@gmail.com wrote:
I should mention it's a binary tree, not necessarily complete. Though,
i don't think BFS search has anything to do with tree being complete.
Child's position will be
@Navneet: I suggest that you do an in-order traversal. Assign x values
to the nodes sequentially, with y values based on the depth from the
root. Thus, in your example, d has coordinates (0,2), b: (1,1), e:
(2,2), a: (3,0), f: (4,2), c: (5,1), g: (6,2).
Dave
On Aug 28, 9:46 am, Navneet Gupta
if the number of levels is known - while traversing the tree in BFS order
keep a loop to print spaces in number- n/2,n/2-1,n/2-2 and so on ,before
entering at each level. Now if you find any child node empty just print a
blank space in place of its value.
On Sun, Aug 28, 2011 at 10:01 PM, Dave
mohit, wat if the tree is growing dynamically?
On Sun, Aug 28, 2011 at 11:27 PM, mohit verma mohit89m...@gmail.com wrote:
if the number of levels is known - while traversing the tree in BFS order
keep a loop to print spaces in number- n/2,n/2-1,n/2-2 and so on ,before
entering at each level.
i 've already mentioned if number of levels is known. Well for dynamic
case we can print the tree from bottom level to top using recursion and at
each increment if level after printing the values we pass back the level
number and accordingly we print space . The output will look like this-
5 6
I think for that we need to re-traverse the tree - in first recursion
counting the levels and second time printing values and spaces accordingly.
On Sun, Aug 28, 2011 at 11:50 PM, mohit verma mohit89m...@gmail.com wrote:
i 've already mentioned if number of levels is known. Well for dynamic