HEAP & TRIES 1. Heap Dalam ilmu komputer , sebuah heap adalah struktur data yang berdasarkan konsep struktur data pohon . Di heap, juga diterapkan konsep binary tree. Terdapat 3 jenis heap, diantaranya : a. Min heap Min heap merupakan heap yang node rootnya adalah angka terkecil dan setiap anak dari rootnya selalu lebih kecil daripada parentnya. Biasanya min heap ini, dia ascending ( dari terkecil ke terbesar ). b. Max heap Max heap ini sama seperti min heap, tapi bedanya adalah angka yang berada di root adalah angka terbesar dan max heap ini descending ( dari terbesar ke terkecil ). c. Min Max heap Untuk min max heap ini cukup unik, dimana root dari heap ini merupakan angka terkecil didalam tree nya, tapi angka yang berada dii node anak dari sebuah root merupakan angka paling besar dan berlaku seterusnya sampai ke bawah. Berikut ad...
AVL TREE AVL tree is a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees cannot be more than one for all nodes. For example : (Left : Correct AVL Tree || Right : Wrong AVL Tree) The reason why right AVL tree is wrong because the above tree is not AVL because differences between heights of left and right subtrees for 8 and 18 is greater than 1. AVL trees have an additional guarantee: The difference between the depth of right and left subtrees cannot be more than one. In order to maintain this guarantee, an implementation of an AVL will include an algorithm to rebalance the tree when adding an additional element would upset this guarantee. AVL trees have a worst case lookup, insert and delete time of O(log n). In AVL Tree, we can perform Insertion and Deletion. · Insertion To make sure that the given tree remains AV...