| |
|
Welcome to KnowledgeSutra - Dear Guest | |
I Need Some Help In Data Structures.
Started by ayom88, May 02 2010 06:46 PM
2 replies to this topic
#2
Posted 02 May 2010 - 09:00 PM
well ayom88, you are a member now, so why you are posting in guest forums. please read the rules of the forum before posting and post under the right category to get all the help you need. also be more detailed so we can help for example you want the function in which language?
and you want both the algorithm and the function for Btree?
and you want both the algorithm and the function for Btree?
Edited by web_designer, 02 May 2010 - 09:06 PM.
#3
Posted 10 May 2010 - 06:28 PM
Hi!
@ayom88
The problem of finding the leaf nodes of a tree is a simple one. Irrespective of whether the tree is binary or not, you can have a function that accepts a parameter, the tree node. Initially, this will be called by the main function or any other entry point of your program. The function would then check if the node passed as a parameter has any children. If the node does have children, the function will call itself recursively with each of the child nodes and if the node does not have any children, it can add the parameter into a list. A stack overflow would occur if any of the nodes points back to a parent (immediate or indirect) so you would have to add additional logic to perform a check if you are expecting loops within the tree (a regular binary tree should have none).
Most novice programmers are unable to comprehend the usage of recursion and would consider iterative means. The problem can be solved iteratively too, but a recursive solution is simpler.
@ayom88
The problem of finding the leaf nodes of a tree is a simple one. Irrespective of whether the tree is binary or not, you can have a function that accepts a parameter, the tree node. Initially, this will be called by the main function or any other entry point of your program. The function would then check if the node passed as a parameter has any children. If the node does have children, the function will call itself recursively with each of the child nodes and if the node does not have any children, it can add the parameter into a list. A stack overflow would occur if any of the nodes points back to a parent (immediate or indirect) so you would have to add additional logic to perform a check if you are expecting loops within the tree (a regular binary tree should have none).
Most novice programmers are unable to comprehend the usage of recursion and would consider iterative means. The problem can be solved iteratively too, but a recursive solution is simpler.
Reply to this topic

1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users














