MHB Checking if a Binary Tree is Full: A Hint

  • Thread starter Thread starter evinda
  • Start date Start date
  • Tags Tags
    Binary Tree
AI Thread Summary
To determine if a binary tree is full, the algorithm should check that every node is either a leaf or has two children. This can be achieved through a recursive traversal of the tree. For each node, evaluate whether it is a leaf or has two children, and combine these results using a logical AND operation. This approach ensures that all nodes meet the criteria for the tree to be classified as full.
evinda
Gold Member
MHB
Messages
3,741
Reaction score
0
Hello! (Smile)

I want to write an algorithm, that checks if a binary tree is full or not.

Could you give me a hint how I could do this? (Thinking)
 
Technology news on Phys.org
evinda said:
Hello! (Smile)

I want to write an algorithm, that checks if a binary tree is full or not.

Could you give me a hint how I could do this? (Thinking)

If every node is either a leaf, or has two children, then it's a full tree. So traverse the tree recursively, and for each node, compute the logical expression (IsLeaf OR HasTwoChildren), then AND all the results together.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top