| | |
Avl Tree
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Hi,
Please suggest me how to check a given tree is balanced using the height of tree.
we need to use the avl tree concept.
i.e, the difference between height of any left or right subtree is atmost 1.
i have written the code for inserting the node, but this one i can't understand .
Please suggest me how to check a given tree is balanced using the height of tree.
we need to use the avl tree concept.
i.e, the difference between height of any left or right subtree is atmost 1.
i have written the code for inserting the node, but this one i can't understand .
Minds are like parachutes - they only work when they are open
Gaiety
Gaiety
Can't explain it as good as Narue does here, so you should take an hour or two to read the article. Everything will be clear afterwards
Last edited by niek_e; Sep 23rd, 2009 at 7:59 am.
•
•
Join Date: Oct 2006
Posts: 164
Reputation:
Solved Threads: 3
If you understand the concepts and have written the insert function, then this should not be all that difficult to understand. Just for reference:
So one solution would be to write a function that takes a node, at any given point in the tree, and can calculate its height (might involve recursion depending on how you determine it). Then you can pass child of the root to this function and determine if its a proper AVL tree or not.
Below is some scrappy pseudocode:
if heightLeftSubTree - heightRightSubTree is between -1 and 1
--this tree is an AVL tree
else
--this tree is NOT an AVL tree
end
Hope that helps (without giving to much away
)
•
•
•
•
In an AVL tree, the heights of the two child subtrees of any node differ by at most one
Below is some scrappy pseudocode:
if heightLeftSubTree - heightRightSubTree is between -1 and 1
--this tree is an AVL tree
else
--this tree is NOT an AVL tree
end
Hope that helps (without giving to much away
) Last edited by Barefootsanders; Sep 23rd, 2009 at 9:48 am.
![]() |
Similar Threads
- Multiple files - AVL tree help (C++)
- Algorithm for AVL tree (Computer Science)
- AVL tree based Dictionary (Java)
- AVL tree issues (C++)
- What do you think? BS tree or AVL tree for fast searching? (C++)
- AVL tree ? (C++)
- In desperate need of help with iterative insert method for avl tree. please help (Java)
- Avl tree and Bst tree (C++)
- Database manipulation with AVL tree.. please help (Java)
Other Threads in the C++ Forum
- Previous Thread: glut still not working... much
- Next Thread: error reading file
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






