Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
aa:lab:08 [2020/11/20 22:23] calin_andrei.bucur |
aa:lab:08 [2020/11/20 22:31] (current) calin_andrei.bucur |
||
---|---|---|---|
Line 5: | Line 5: | ||
Binary Heaps are binary trees with the following properties: | Binary Heaps are binary trees with the following properties: | ||
- | **I.** Any node's $math[n] value is greater then his children's $math[c]. ($math[n.value \geq c.value]) | + | **I.** Any node's $math[n] value is greater then his child's value $math[c]. ($math[n.value \geq c.value]) |
**II.** The tree is almost complete (missing elements are possible only on the last level) | **II.** The tree is almost complete (missing elements are possible only on the last level) | ||
Line 101: | Line 101: | ||
7 0 4 | 7 0 4 | ||
- | We start from the last level, which in this case is **ceil(log(10)) = 4** | + | We start from the last level, which in this case is $math[ceil(log(10)) = 4] |
- | from **j = 2^(4-1)** (which is 8) to n-1. On the last level, each tree is a heap. | + | from $math[j = 2^{(4-1)}] (which is 8) to n-1. On the last level, each tree is a heap. |
We now move to a previous level. Say the level is i: | We now move to a previous level. Say the level is i: | ||
- | from **j = 2^(i-1)** to **2^i-1**: | + | from $math[j = 2^{(i-1)}] to $math[2^i-1]: |
we send-down each value on this level, just like in the deletion algorithm, by keeping as the current root, | we send-down each value on this level, just like in the deletion algorithm, by keeping as the current root, |