Posts

Showing posts from April, 2020

Data Structure || AVL Tree

Image
Name: I Putu Raka Natha Nugraha NIM: 2301865552 AVL Tree is a type of binary search tree in which it balances itself according to the differences in height between the two sub-trees of a node (the delta/difference must be 1 or 0) For example: Example of a Binary Search Tree As you can see 5 is the main node of this tree (the first node to be inserted) and all the other nodes have basically become sub-trees to this node according to its value and of course its insert order. This is how the normal binary search tree works, but this is not an AVL tree since the left and right sub-trees contain different heights. The difference of the sub-trees renders the tree to be a non-AVL tree In order to create a functioning AVL tree here we have to 'balance' the two sub-trees by a node rotation in which the main node is replaced by the sub tree that the balance is heavily leaning on. So we have to replace the main node (5) with a node one value lower of the main node, so eit...