Heap and Deap Flashcards
what is Heap?
a complete binary tree based data structure that satisfies heap property. lebih MUDAH pake ARRAY
jenis heap property?
- min heap, yang paling kecil diatas
2. max heap, yang paling besar diatas
implement heap dengan?
dapat dengan linked-list, tapi lebih mudah pake array
Heap Sort complexity?
O(n.lg(n))
Heap applications?
Priority Queue
djikstra, prim
Heap merupakan implementasi yang efisien dari?
Priority Queue
Heap, root di index keberapa?
1
array implementation pada Heap. parent(x), left-child(x), right-child(x) apa rumusnya?
parent(x) = x / 2 left-child(x) = 2 * x right-child(x) = 2 * x + 1
Heap Complexity?
find-min = O(1) insert = O(log(n)) delete-min = O(log(n))
Min-Max Heap?
Root merupakan smallest element. largest element bisa sebelah kiri atau kanan anak dari root
Deap adalah?
double ended heap. mirip dengan min-max heap. algorithm lebih simple dari min-max heap
Deap properties?
- root contains no element
- left sub-tree of root is a min heap
- right sub-tree of root is a max heap
Pengaplikasian Heap?
- priority queue
- selection algorithm (finding min/max element, median, k-th largest element)
- dijkstra algorithm
- prim algorithm
- heap sort
upheapmax?
compare current node with its grandparent value, if current node larger = swap. continue upheapmax from the granparent node
upheapmin?
compare current node with its grandparent value, if current node smaller = swap. continue upheapmin from the granparent node