# Find Depth of a Tree in C++ Code is required

Page 1 of 1

## 3 Replies - 7282 Views - Last Post: 27 May 2007 - 08:10 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=28344&amp;s=db1902c5216134737f9e5f32bb942c79&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 waqaraziz

Reputation: 0
• Posts: 1
• Joined: 24-May 07

# Find Depth of a Tree in C++ Code is required

Posted 24 May 2007 - 05:22 AM

This post has been edited by waqaraziz: 24 May 2007 - 05:23 AM

Is This A Good Question/Topic? 0

## Replies To: Find Depth of a Tree in C++ Code is required

### #2 William_Wilson

• lost in compilation

Reputation: 207
• Posts: 4,812
• Joined: 23-December 05

## 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 NickDMax

Reputation: 2254
• Posts: 9,245
• Joined: 18-February 07

## 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 chris.tkd

Reputation: 0
• Posts: 74
• Joined: 26-September 06

## 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

```

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.