Postingan

Menampilkan postingan dari Mei, 2020

Heaps dan Tries

Gambar
Heaps dan Tries Heap Heap adalah struktur data berbasis pohon biner lengkap yang memenuhi properti heap. Heap properti terbagi menjadi 3 bagian yaitu Min-Heap, Max-Heap, dan Min-Max Heap. Mari kita bahas satu persatu seperti dibawah ini: Aplikasi Heap Priority Queue Selection Algorithms (menemukan elemen min / maks, median, elemen kth-terbesar, dll). Dijkstra’s Algorithm (menemukan jalur terpendek dalam grafik) Prim Algorithm (menemukan minimum spanning tree) Heap Sort An O(n.lg(n)) algorithm. Implementasi Array  Heap biasanya diimplementasikan didalam array. Elemen-elemen nya tersimpan secara berurutan adri index 1 sampai N dari atas sampai bawah dan dari kiri ke kanan dari node of the tree . Root tersimpan dari index 1 (kita biarkan index 0 kosong/tidak terpakai, demi kenyamanan) Setiap hubungan node dengan orang tuanya, anak kiri dan anak kanan dalam implementasi array dapat dihitung dengan mudah. Biarkan indeks simpul saat ini menjadi x. I...

AVL Tree

Gambar
AVL TREE ---English Version--- Before we start to AVL Tree let's review Binary Search Tree (BST). Binary Search Tree This picture is the example of a skewed Binary Search Tree (BST). The left BST is inserted by 2, 5, 7, 8, and 13 respectively.  The right BST is inserted by 9, 1, 6, 3, and 4 respectively. 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 of all nodes. Height of a node: The height of an empty subtree is 0. The height of a leaf is 1. The height of an internal node is the maximum height of its children plus 1. Balance factor: The difference height of its LEFT subtree and its RIGHT subtree. The balance factor of all nodes in the AVL Tree should be at most 1. AVL Tree has two operations such as: 1. Insertion 2. Deletion AVL Tree Operation (Insertion) Look at the picture above, isn't it co...