|
|
![]() |
| Thread Tools | Search this Thread |
#1
| |||
| |||
How to Count nodes in Binary Tree ? Hello friends, I want to find the total number of nodes in a binary tree structure at the same time i also need the the leftside and right side separately.I try to find over the Internet but didn't got a Solution. Can anyone help me out with this. Intel Core 2 Duo 2.8 Ghz G31 Asrock Motherboard with Intel chipset 2gb RAM 256 Nvidia Graphic Card 200gb HDD |
#2
| |||
| |||
Re: How to Count nodes in Binary Tree ? Sure i will help you out with this issue before going ahead may i know which programming language are you using it. |
#3
| |||
| |||
Re: How to Count nodes in Binary Tree ? I am using Java as my Programming language. Intel Core 2 Duo 2.8 Ghz G31 Asrock Motherboard with Intel chipset 2gb RAM 256 Nvidia Graphic Card 200gb HDD Edit/Delete Message |
#4
| |||
| |||
Re: How to Count nodes in Binary Tree ? Try to use this code i assume that you node class will work. Code: public static <T> int nodesAtFirstKLevels(BTNode<T> root, int k) { if (root == null || k<=0) { return 0; } else { return 1 + count(root.left,k-1) + count(root.right,k-1); } } } |
#5
| |||
| |||
Re: How to Count nodes in Binary Tree ? If you want it very simple you can use this too. Code: public static <T> int nodesAtFirstKLevels(BTNode<T> root, int k) { return (root == null || k<=0) ? 0: (1 + count(root.left,k-1) + count(root.right,k-1)); } |
![]() |
|
Tags: binary, count, nodes |
Thread Tools | Search this Thread |
|
![]() | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Algorithm for counting number of nodes in a binary tree | anithachacko | Software Development | 1 | 20-04-2010 01:20 PM |
JAVA binary tree | Daren | Software Development | 4 | 29-09-2009 12:17 AM |
Count all files in a directory tree including subdirectories in Windows XP | !const | Operating Systems | 3 | 29-06-2009 06:58 PM |
Dictionary with a binary tree | Lord | Software Development | 4 | 01-05-2009 08:25 PM |
Algorithm to count in binary | Zool | Software Development | 3 | 28-04-2009 01:22 PM |