This post has been edited by waqaraziz: 24 May 2007 - 05:23 AM
Find Depth of a Tree in C++ Code is requiredHow can i find depth of a tree
Page 1 of 1
3 Replies - 5905 Views - Last Post: 27 May 2007 - 08:10 AM
#1
Find Depth of a Tree in C++ Code is required
Posted 24 May 2007 - 05:22 AM
Please help in writting C++ code to find the depth of a tree
Replies To: Find Depth of a Tree in C++ Code is required
#2
Re: Find Depth of a Tree in C++ Code is required
Posted 24 May 2007 - 07:53 AM
we here at DIC have a strict policy that you must provide us with some code, otherwise known as "good faith" code, in order to recieve help. Please show us what you have attempted and we will be glad to help.
#3
Re: Find Depth of a Tree in C++ Code is required
Posted 26 May 2007 - 02:38 PM
To find the depth of a tree find its deepest node. How do you find its deepest node. Traverse the tree and count how far you had to go to get there.
#4
Re: Find Depth of a Tree in C++ Code is required
Posted 27 May 2007 - 08:10 AM
This is how to find the heigh of a tree abstractly
where max is a function that finds the maximum of two inputs , eg
youll have to translate this into c++ but it shouldnt be hard.
heigh(t: node) --> if t = null return 0 else return (1 + max(height(t.left), height(t.right))
where max is a function that finds the maximum of two inputs , eg
max(t1, t2) --> if t1.val > t2.val return t1 else return t2
youll have to translate this into c++ but it shouldnt be hard.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote






|