Hello again.I recently have been doing a assignment which asks us to write a function to check whether a tree is perfectly balanced.I know the concept of Perfectly balanced tree but I just cant make out how to write this function.Any help in right direction will be highly welcome.
ariel930
11
Newbie Poster
Recommended Answers
Jump to PostYou can modify and use DFS. For every node you can check if the depth of the two subtrees coming under it is equal or not.
Jump to PostBy perfectly balanced do you mean a complete tree? A full tree? Merely a height balanced or weight balanced tree? The algorithm is different for each. Typically what's meant is height balance, or what would be the desired end structure maintained an AVL tree.
A recursive algorithm presents itself immediately …
All 7 Replies
ken_taiken
0
Newbie Poster
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
ariel930
11
Newbie Poster
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
ariel930
11
Newbie Poster
deceptikon
commented:
Grats!
+11
mrnutty
761
Senior Poster
yde
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.