How to find the depth of a binary tree?
Submitted by: AdministratorThe depth of a binary tree is found using the following process:
1. Send the root node of a binary tree to a function
2. If the tree node is null, then return false value.
3. Calculate the depth of the left tree; call it ‘d1' by traversing every node. Increment the counter by 1, as the traversing progresses until it reaches the leaf node. These operations are done recursively.
4. Repeat the 3rd step for the left node. Name the counter variable ‘d2'.
5. Find the maximum value between d1 and d2. Add 1 to the max value. Let us call it ‘depth'.
6. The variable ‘depth' is the depth of the binary tree.
Submitted by: Administrator
1. Send the root node of a binary tree to a function
2. If the tree node is null, then return false value.
3. Calculate the depth of the left tree; call it ‘d1' by traversing every node. Increment the counter by 1, as the traversing progresses until it reaches the leaf node. These operations are done recursively.
4. Repeat the 3rd step for the left node. Name the counter variable ‘d2'.
5. Find the maximum value between d1 and d2. Add 1 to the max value. Let us call it ‘depth'.
6. The variable ‘depth' is the depth of the binary tree.
Submitted by: Administrator
Read Online Data Structures Trees Job Interview Questions And Answers
Top Data Structures Trees Questions
☺ | Explain red-black trees? |
☺ | How to find the depth of a binary tree? |
☺ | What is threaded binary tree. Explain its common uses? |
☺ | Do you know implementation of traversal of a binary tree? |
☺ | Explain B+ tree? Explain its uses? |
Top Coding/Programming Categories
☺ | Python Interview Questions. |
☺ | OOP Interview Questions. |
☺ | Software engineering Interview Questions. |
☺ | PHP Interview Questions. |
☺ | VBA (Visual Basic for Applications) Interview Questions. |