Login Register


Help with an AVL TREE filter_list
Author
Message
RE: Help with an AVL TREE #14
@Psycho_Coder already got it correct.
Anyways, I added the Balance factor in his Tree.

[Image: l0TFyH0.jpg]

Do it like this:
The First Element in your Array is your Root node [at least for now. It will be changed later]

Add 100 as the root node

Now pick the next element, if this element is bigger than the root node, insert it as the Right Child, else as the Left Child, and repeat with the rest elements.

In each step, write down the Balance factor beside each node. [BF = Height of the node's Left Subtree - Right Subtree]

Now, if the BF for a node is +1, -1 or 0, you can proceed normally, but if the BF becomes -2 or +2, you have to rotate the tree from the current node's position [Node that has BF +2 or -2].
Rotate if clockwise if +2 and Anti-clockwise if -2. [You do the opposite if it doesn't work out]

Remember to add the next element only when your AVL tree is balanced, ie. you do not have +2 or -2 BF somewhere in the tree.
[Image: MUJ8qSW.png]
-----------------------------------
Now learning:
Android Development, Java
Working on:
An FTP Client for Android
-----------------------------------

Reply





Messages In This Thread
Help with an AVL TREE - by Apocalypse - 06-11-2014, 09:03 PM



Users browsing this thread: 1 Guest(s)