Download - Poscat seminar 4
![Page 1: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/1.jpg)
POSCAT Seminar 4 :Adv. Data Structure
yougatup @ POSCAT
1
![Page 2: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/2.jpg)
Topic
Topic today
−Heap ( Just for your knowledge )
• D-ary heap
• Binomial heap
• Fibonacci heap
− Indexed Tree
• Binary Indexed Tree
• Fenwick Tree
− Implementation of Indexed Tree
POSCAT Seminar 1-22 July 2014
yougatup
![Page 3: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/3.jpg)
Heap
You already know what it is
− Definition ?
Amazingly, there is faster data structures
− Fibonacci heap 은 이론적으로 Time complexity 가장 적음
− But, 구현해보면 느림 실제로 쓰지는 않습니다
− d-ary heap, Binomial heap, Fibonacci heap
Operations
− find_min, delete_min, insert, delete, decrease_key
POSCAT Seminar 1-32 July 2014
yougatup
![Page 4: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/4.jpg)
𝑑-ary heap
It has child at most 𝑑
− Extended version of binary heap
− How it works ?
− We use it for Prim algorithm
POSCAT Seminar 1-42 July 2014
yougatup
find_min ?insert ?delete ?decrease_key ?delete_min ?
⋅⋅⋅
at most 𝑑
![Page 5: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/5.jpg)
𝑑-ary heap
POSCAT Seminar 1-52 July 2014
yougatup
⋅⋅⋅
at most 𝑑find_min : root !insert : insert to right-mostdelete : decrease a value to -∞, and delete_mindecrease_key : decrease a value, and rearrange heapdelete_min : like binary heap
It has child at most 𝑑
− Extended version of binary heap
− How it works ?
− We use it for Prim algorithm
![Page 6: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/6.jpg)
𝑑-ary heap
POSCAT Seminar 1-62 July 2014
yougatup
⋅⋅⋅
at most 𝑑find_min : root !insert : insert to right-mostdelete : decrease a value to -∞, and delete_mindecrease_key : decrease a value, and rearrange heapdelete_min : like binary heap
Time complexity ?
It has child at most 𝑑
− Extended version of binary heap
− How it works ?
− We use it for Prim algorithm
![Page 7: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/7.jpg)
𝑑-ary heap
POSCAT Seminar 1-72 July 2014
yougatup
⋅⋅⋅
at most 𝑑
Time complexity ?
find_min : O(1)insert : O(log𝑑 𝑛)delete : O(𝑑 log𝑑 𝑛)decrease_key : O(log𝑑 𝑛)delete_min : O(𝑑 log𝑑 𝑛)
It has child at most 𝑑
− Extended version of binary heap
− How it works ?
− We use it for Prim algorithm
![Page 8: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/8.jpg)
Binomial tree
Definition
A binomial tree of height 𝑘 (denoted by 𝐵𝑘) is defined as follows
1. 𝐵0 consists of a single node.
2. 𝐵𝑘 is formed by joining two 𝐵𝑘−1 trees, making one’s root child
of the other
POSCAT Seminar 1-82 July 2014
yougatup
𝐵0 𝐵1 𝐵2 𝐵3
![Page 9: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/9.jpg)
Binomial tree
Property
1. 𝐵𝑘 has 2𝑘 nodes
2. The height of 𝐵𝑘 is 𝑘 = log |𝐵𝑘|
3. The root of 𝐵𝑘 has 𝑘 children
Use mathematical induction to prove
Therefore, the height and the degree of a node 𝑣 in a binomial tree
are both at most logarithmic in the size of the subtree rooted at 𝑣
POSCAT Seminar 1-92 July 2014
yougatup
![Page 10: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/10.jpg)
Binomial tree
Storing data
How can we store 𝑛 ≠ 2𝑘 nodes using binomial tree ?
POSCAT Seminar 1-102 July 2014
yougatup
![Page 11: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/11.jpg)
Binomial tree
Storing data
How can we store 𝑛 ≠ 2𝑘 nodes using binomial tree ?
Think about binary notation of 𝑛
POSCAT Seminar 1-112 July 2014
yougatup
![Page 12: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/12.jpg)
Binomial tree
Storing data
How can we store 𝑛 ≠ 2𝑘 nodes using binomial tree ?
Think about binary notation of 𝑛
We can use binomial tree chain ! We call it as root list
POSCAT Seminar 1-122 July 2014
yougatup
head 10 1 6
12 25
18
8
11 17
27
29 14
38
![Page 13: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/13.jpg)
Binomial heap
Definition
A binomial heap is a (set of) binomial tree(s) where each node is
associated with a key and the heap-order property is preserved.
We also have the requirement that for any 𝑖 there is at most one 𝐵𝑖 .
In other words, it doesn’t contain two 𝐵𝑖 in the binomial heap.
POSCAT Seminar 1-132 July 2014
yougatup
head 10 1 6
12 18
25
8
11 17
27
29 14
38
unique 𝐵2
![Page 14: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/14.jpg)
Binomial heap
Operations
− find_min, delete_min, insert, delete, decrease_key
POSCAT Seminar 1-142 July 2014
yougatup
![Page 15: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/15.jpg)
Binomial heap
Find_min
We need to consider all the root nodes of binomial tree
It takes O(log 𝑛). Why ?
POSCAT Seminar 1-152 July 2014
yougatup
head 10 1 6
12 18
25
8
11 17
27
29 14
38
![Page 16: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/16.jpg)
Binomial heap
Find_min
We need to consider all the root nodes of binomial tree
It takes O(log 𝑛). Why ? we have log 𝑛 binomial trees
POSCAT Seminar 1-162 July 2014
yougatup
head 10 1 6
12 18
25
8
11 17
27
29 14
38
![Page 17: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/17.jpg)
Binomial heap
Decrease_key
Decrease the value and rearrange binomial tree
It takes O(log 𝑛)
POSCAT Seminar 1-172 July 2014
yougatup
head 10 1 6
12 18
25
8
11
27
29 14
3817
![Page 18: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/18.jpg)
Binomial heap
Decrease_key
Decrease the value and rearrange binomial tree
It takes O(log 𝑛)
POSCAT Seminar 1-182 July 2014
yougatup
head 10 1 6
12 18
25
8
11
27
29 14
382
![Page 19: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/19.jpg)
Binomial heap
Decrease_key
Decrease the value and rearrange binomial tree
It takes O(log 𝑛)
POSCAT Seminar 1-192 July 2014
yougatup
head 10 1 6
12 18
2511
27
29 14
38
2
8
![Page 20: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/20.jpg)
Binomial heap
Decrease_key
Decrease the value and rearrange binomial tree
It takes O(log 𝑛)
POSCAT Seminar 1-202 July 2014
yougatup
head 10 1
12 18
2511
27
29 14
388
6
2
![Page 21: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/21.jpg)
Binomial heap
Delete_min
If we delete the root node of binomial tree, it is split into many trees
POSCAT Seminar 1-212 July 2014
yougatup
head 10
12 18
2511
27
29 14
388
6
21
delete it !
![Page 22: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/22.jpg)
Binomial heap
Delete_min
If we delete the root node of binomial tree, it is split into many trees
POSCAT Seminar 1-222 July 2014
yougatup
head 10
12 18
2511
27
29 14
388
6
2
delete it ?
![Page 23: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/23.jpg)
Binomial heap
Delete_min
If we delete the root node of binomial tree, it is split into many trees
Make another chain ! Then we get another binomial heap.
POSCAT Seminar 1-232 July 2014
yougatup
head 10 12 18
25
11
27
29 14
388
6
2 head’
![Page 24: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/24.jpg)
Binomial heap
Delete_min
If we delete the root node of binomial tree, it is split into many trees
Make another chain ! Then we get another binomial heap.
Merge two binomial heaps into one ! How ?
POSCAT Seminar 1-242 July 2014
yougatup
head 10 12 18
25
11
27
29 14
388
6
2 head’
![Page 25: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/25.jpg)
Binomial heap
Delete_min
If we delete the root node of binomial tree, it is split into many trees
Make another chain ! Then we get another binomial heap.
Merge two binomial heaps into one ! How ? Merging on merge sort ?
POSCAT Seminar 1-252 July 2014
yougatup
head 10 12 18
25
11
27
29 14
388
6
2 head’
![Page 26: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/26.jpg)
Binomial heap
Delete_min
If we delete the root node of binomial tree, it is split into many trees
Make another chain ! Then we get another binomial heap.
Merge two binomial heaps into one !
POSCAT Seminar 1-262 July 2014
yougatup
head 10 12 18
25
11
27
29 14
388
6
2
![Page 27: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/27.jpg)
Binomial heap
Delete_min
If we delete the root node of binomial tree, it is split into many trees
Make another chain ! Then we get another binomial heap.
Merge two binomial heaps into one !
Rearrange the binomial heap
POSCAT Seminar 1-272 July 2014
yougatup
head 10 12 18
25
11
27
29 14
388
6
2
![Page 28: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/28.jpg)
Binomial heap
Delete_min
If we delete the root node of binomial tree, it is split into many trees
Make another chain ! Then we get another binomial heap.
Merge two binomial heaps into one !
Rearrange the binomial heap
POSCAT Seminar 1-282 July 2014
yougatup
head 18
25
11
27
29 14
388
6
210 12
![Page 29: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/29.jpg)
Binomial heap
Delete_min
If we delete the root node of binomial tree, it is split into many trees
Make another chain ! Then we get another binomial heap.
Merge two binomial heaps into one !
Rearrange the binomial heap
POSCAT Seminar 1-292 July 2014
yougatup
head 18
25
11
27
29 14
388
6
2
12
10
![Page 30: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/30.jpg)
Binomial heap
Delete_min
If we delete the root node of binomial tree, it is split into many trees
Make another chain ! Then we get another binomial heap.
Merge two binomial heaps into one !
Rearrange the binomial heap
POSCAT Seminar 1-302 July 2014
yougatup
head
11
27
29 14
388
6
218
2512
10
![Page 31: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/31.jpg)
Binomial heap
Delete_min
If we delete the root node of binomial tree, it is split into many trees
Make another chain ! Then we get another binomial heap.
Merge two binomial heaps into one !
Rearrange the binomial heap
POSCAT Seminar 1-312 July 2014
yougatup
head
11
27
29 14
388
6
2
18
25
12
10
![Page 32: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/32.jpg)
Binomial heap
Delete_min
If we delete the root node of binomial tree, it is split into many trees
Make another chain ! Then we get another binomial heap.
Merge two binomial heaps into one !
Rearrange the binomial heap
POSCAT Seminar 1-322 July 2014
yougatup
head
11
27
29 14
388
6
2
18
25
12
10
![Page 33: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/33.jpg)
Binomial heap
Delete_min
Time complexity ?
POSCAT Seminar 1-332 July 2014
yougatup
head
11
27
29 14
388
6
2
18
25
12
10
![Page 34: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/34.jpg)
Binomial heap
Delete_min
Time complexity ?
Each node has at most log 𝑛 child.
POSCAT Seminar 1-342 July 2014
yougatup
head
11
27
29 14
388
6
2
18
25
12
10
![Page 35: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/35.jpg)
Binomial heap
Delete_min
Time complexity ?
Each node has at most log 𝑛 child.
New binomial heap consists of at most log 𝑛 binomial trees
POSCAT Seminar 1-352 July 2014
yougatup
head
11
27
29 14
388
6
2
18
25
12
10
![Page 36: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/36.jpg)
Binomial heap
Delete_min
Time complexity ?
Each node has at most log 𝑛 child.
New binomial heap consists of at most log 𝑛 binomial trees
Therefore, Merging and rearrange takes O(log 𝑛).
POSCAT Seminar 1-362 July 2014
yougatup
head
11
27
29 14
388
6
2
18
25
12
10
![Page 37: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/37.jpg)
Binomial heap
Insert
Insert a new node and rearrange binomial heap
O(log 𝑛)
POSCAT Seminar 1-372 July 2014
yougatup
head
11
27
29 14
388
6
2
18
25
12
10
![Page 38: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/38.jpg)
Binomial heap
Delete
Make it as -∞, and delete_min !
O(log 𝑛)
POSCAT Seminar 1-382 July 2014
yougatup
head
11
27
29 14
388
6
2
18
25
12
10
![Page 39: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/39.jpg)
Fibonacci heap
Theoretically fastest heap
− But it is just theoretical. It is slow if you implement it
− We don’t use it
Similar with binomial heap
− Relaxed version of binomial heap
− Use a lazy update scheme.
POSCAT Seminar 1-392 July 2014
yougatup
![Page 40: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/40.jpg)
Fibonacci heap
Main feature
− Individual trees are not necessarily binomial (let me denote it as 𝐵𝑖′)
− Allow many copies of 𝐵𝑖′ for the same 𝑖.
Operations
− find_min, delete_min, insert, delete, decrease_key
POSCAT Seminar 1-402 July 2014
yougatup
head 10 1 6
12 188
11 17
14
38
I allow it because I’m lazy
𝐵0′ 𝐵2′ 𝐵3′
3
11 27
𝐵2′
20
![Page 41: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/41.jpg)
Fibonacci heap
Find_min
via pointer !
POSCAT Seminar 1-412 July 2014
yougatup
head 10 1 6
12 188
11 17
14
38
𝐵0′ 𝐵2′ 𝐵3′
3
11 27
𝐵2′
20
![Page 42: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/42.jpg)
Fibonacci heap
Insert
Create a node. No update because I’m lazy
Give $1 to inserted node. I’ll explain the meaning of ‘coin’ later.
POSCAT Seminar 1-422 July 2014
yougatup
10 1 6
12 188
11 17
14
38
𝐵0′ 𝐵2′ 𝐵3′
3
11 27
𝐵2′
20
head 7
𝐵0′
![Page 43: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/43.jpg)
Fibonacci heap
Delete
-∞, delete_min
POSCAT Seminar 1-432 July 2014
yougatup
10 1 6
12 188
11 17
14
38
𝐵0′ 𝐵2′ 𝐵3′
3
11 27
𝐵2′
20
head 7
𝐵0′
![Page 44: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/44.jpg)
Fibonacci heap
Delete_min
Delete min and rearrange Fibonacci heap.
Time complexity will proportional to the number of trees.
Is it fast ?
POSCAT Seminar 1-442 July 2014
yougatup
10 1 6
12 188
11 17
14
38
𝐵0′ 𝐵2′ 𝐵3′
3
11 27
𝐵2′
20
head 7
𝐵0′
![Page 45: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/45.jpg)
Fibonacci heap
Delete_min
Delete min and rearrange Fibonacci heap.
Time complexity will proportional to the number of trees.
Is it fast ?
POSCAT Seminar 1-452 July 2014
yougatup
10 612 18
8
11 17
14
38
𝐵0′ 𝐵3′
3
11 27
𝐵2′
20
head 7
𝐵0′ 𝐵0′ 𝐵1′
![Page 46: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/46.jpg)
Fibonacci heap
Delete_min
Delete min and rearrange Fibonacci heap.
Time complexity will proportional to the number of trees.
Is it fast ?
POSCAT Seminar 1-462 July 2014
yougatup
10 6
12
18
8
11 17
14
38
𝐵1′ 𝐵3′
3
11 27
𝐵2′
20
head 7
𝐵0′ 𝐵1′
![Page 47: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/47.jpg)
Fibonacci heap
Delete_min
Delete min and rearrange Fibonacci heap.
Time complexity will proportional to the number of trees.
Is it fast ?
POSCAT Seminar 1-472 July 2014
yougatup
10 6
12 188
11 17
14
38
𝐵2′ 𝐵3′
3
11 27
𝐵2′
20
head 7
𝐵0′
![Page 48: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/48.jpg)
Fibonacci heap
Delete_min
Delete min and rearrange Fibonacci heap.
Time complexity will proportional to the number of trees.
Is it fast ?
POSCAT Seminar 1-482 July 2014
yougatup
10
6
12 18
8
11 17
14
38
𝐵3′
3
11 27 20
head 7
𝐵0′ 𝐵3′
![Page 49: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/49.jpg)
Fibonacci heap
Delete_min
Delete min and rearrange Fibonacci heap.
Time complexity will proportional to the number of trees.
Is it fast ?
POSCAT Seminar 1-492 July 2014
yougatup
106
12 188
11 17
14
38
3
11 27
20
head 7
𝐵0′ 𝐵4′
![Page 50: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/50.jpg)
Fibonacci heap
Delete_min
Delete min and rearrange Fibonacci heap.
Time complexity will proportional to the number of trees.
Is it fast ? we’ll analyze it soon.
POSCAT Seminar 1-502 July 2014
yougatup
106
12 188
11 17
14
38
3
11 27
20
head 7
𝐵0′ 𝐵4′
![Page 51: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/51.jpg)
Fibonacci heap
Decrease_key
Decrease the value of the element. If the heap-order property is
violated, cut the link between the node and its parent. ( It may
produce a result which is not a binomial tree)
Not just cut, we use “Cascading cut”
POSCAT Seminar 1-512 July 2014
yougatup
106
12 188
11 17
14
38
3
11 27
20
head 7
𝐵0′ 𝐵4′
![Page 52: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/52.jpg)
Fibonacci heap
Decrease_key
Decrease the value of the element. If the heap-order property is
violated, cut the link between the node and its parent. ( It may
produce a result which is not a binomial tree)
Not just cut, we use “Cascading cut”
POSCAT Seminar 1-522 July 2014
yougatup
6
12 188
11 17
14
38
3
11 27
20
head 7
𝐵0′ 𝐵4′
10decrease it to 4
![Page 53: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/53.jpg)
Fibonacci heap
Decrease_key
Decrease the value of the element. If the heap-order property is
violated, cut the link between the node and its parent. ( It may
produce a result which is not a binomial tree)
Not just cut, we use “Cascading cut”
POSCAT Seminar 1-532 July 2014
yougatup
6
12 188
11 17
14
38
3
11 27
20
head 7
𝐵4′
4decrease it to 4 heap-order is violated
𝐵0′
![Page 54: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/54.jpg)
Fibonacci heap
Decrease_key
Decrease the value of the element. If the heap-order property is
violated, cut the link between the node and its parent. ( It may
produce a result which is not a binomial tree)
Not just cut, we use “Cascading cut”
POSCAT Seminar 1-542 July 2014
yougatup
6
12 188
11 17
14
38
3
11 27
20
head 7
𝐵4′
4
decrease it to 4 heap-order is violated Cut !
𝐵0′𝐵0′
![Page 55: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/55.jpg)
Fibonacci heap
Decrease_key
Decrease the value of the element. If the heap-order property is
violated, cut the link between the node and its parent. ( It may
produce a result which is not a binomial tree)
Not just cut, we use “Cascading cut”
POSCAT Seminar 1-552 July 2014
yougatup
6
12 18
8
11 17
14
38
3
11 27
20
head 7
𝐵4′
4
decrease it to 4 heap-order is violated Cut !
𝐵0′ 𝐵0′ 𝐵1′𝐵0′
![Page 56: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/56.jpg)
Cascading cut
Definition
1. Whenever a node is being cut, mark the parent of the cut node in
the original tree, and
• Pay $1 for the cut
• Store $2 in the parent of the cut node
• Store $1 in the new root (cut node).
POSCAT Seminar 1-562 July 2014
yougatup
6
12 18
8
11 17
14
38
11 27
20
head 7
𝐵0′
𝐵4′
decrease it to 4 heap-order is violated Cut !
𝐵0′ 𝐵0′ 𝐵1′
34 marked!
![Page 57: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/57.jpg)
Cascading cut
Definition
2. When a 2nd child of a node 𝑣 is lost (cutting a child of an already
marked node), by that time node 𝑣 will have accumulated $ 4;
recursively cut that node from its parent, marking again the parent
of 𝑣 and using $4 to pay for the operation before.
$1 for the cut, $2 to its parent, $1 to the new root
POSCAT Seminar 1-572 July 2014
yougatup
6
12 18
8
11 17
14
38
27
20
head 7
𝐵4′
𝐵0′ 𝐵0′ 𝐵1′
4 3
11
decrease it to 2 !
𝐵0′
![Page 58: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/58.jpg)
Cascading cut
Definition
2. When a 2nd child of a node 𝑣 is lost (cutting a child of an already
marked node), by that time node 𝑣 will have accumulated $ 4;
recursively cut that node from its parent, marking again the parent
of 𝑣 and using $4 to pay for the operation before.
$1 for the cut, $2 to its parent, $1 to the new root
POSCAT Seminar 1-582 July 2014
yougatup
6
12 18
8
11 17
14
38
27
20
head 7
𝐵4′
𝐵0′ 𝐵0′ 𝐵1′
4 3
2
decrease it to 2 !
𝐵0′
![Page 59: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/59.jpg)
Cascading cut
Definition
2. When a 2nd child of a node 𝑣 is lost (cutting a child of an already
marked node), by that time node 𝑣 will have accumulated $ 4;
recursively cut that node from its parent, marking again the parent
of 𝑣 and using $4 to pay for the operation before.
$1 for the cut, $2 to its parent, $1 to the new root
POSCAT Seminar 1-592 July 2014
yougatup
6
12 18
8
11 17
14
38
27
20
head 7
𝐵0′ 𝐵0′ 𝐵0′ 𝐵1′
4 32
decrease it to 2 !
𝐵1′ 𝐵4′marked twice. It has $4
![Page 60: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/60.jpg)
Cascading cut
Definition
2. When a 2nd child of a node 𝑣 is lost (cutting a child of an already
marked node), by that time node 𝑣 will have accumulated $ 4;
recursively cut that node from its parent, marking again the parent
of 𝑣 and using $4 to pay for the operation before.
$1 for the cut, $2 to its parent, $1 to the new root
POSCAT Seminar 1-602 July 2014
yougatup
612 18
8
11 17
14
38
27
20
head 7
𝐵0′ 𝐵0′ 𝐵0′ 𝐵1′
4 2
𝐵1′ 𝐵3′𝐵0′
3
𝐵0′
![Page 61: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/61.jpg)
Cascading cut
Time complexity of cascading cut
Each node has the coin they already have.
Each cut requires only $4, and decrease_key takes overall still
amortized time O(1) ( Overall cost / The number of operation )
POSCAT Seminar 1-612 July 2014
yougatup
612 18
8
11 17
14
38
27
20
head 7
𝐵0′ 𝐵0′ 𝐵0′ 𝐵1′
4 2
𝐵1′ 𝐵3′𝐵0′
3
𝐵0′
![Page 62: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/62.jpg)
Fibonacci heap
Decrease_key
Decrease the value of the element. If the heap-order property is
violated, cut the link between the node and its parent. ( It may
produce a result which is not a binomial tree)
Not just cut, we use “Cascading cut”
POSCAT Seminar 1-622 July 2014
yougatup
612 18
8
11 17
14
38
27
20
head 7
𝐵0′ 𝐵0′ 𝐵0′ 𝐵1′
4 2
𝐵1′ 𝐵3′𝐵0′
3
𝐵0′
![Page 63: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/63.jpg)
Fibonacci heap
Decrease_key
Decrease the value of the element. If the heap-order property is
violated, cut the link between the node and its parent. ( It may
produce a result which is not a binomial tree)
Not just cut, we use “Cascading cut”
POSCAT Seminar 1-632 July 2014
yougatup
6
12
18
8
11 17
14
38
2720
head 7
𝐵0′
4
3
Rearrange !
𝐵4′
2
![Page 64: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/64.jpg)
Fibonacci heap
Analysis
Cascading cut takes O(1)
How much is merging cost ?
POSCAT Seminar 1-642 July 2014
yougatup
6
12
18
8
11 17
14
38
2720
head 7
𝐵0′
4
3
Rearrange !
𝐵4′
2
![Page 65: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/65.jpg)
Fibonacci heap
Analysis
Cascading cut takes O(1)
How much is merging cost ? O(1) because of the coin
POSCAT Seminar 1-652 July 2014
yougatup
6
12
18
8
11 17
14
38
2720
head 7
𝐵0′
4
3
Rearrange !
𝐵4′
2
![Page 66: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/66.jpg)
Fibonacci heap
Analysis
Cascading cut takes O(1)
After cut, we get (# of child) additional trees
How much is merging cost per child ? O(1) because of the coin
How many child does a node has ?
POSCAT Seminar 1-662 July 2014
yougatup
6
12
18
8
11 17
14
38
2720
head 7
𝐵0′
4
3
Rearrange !
𝐵4′
2
![Page 67: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/67.jpg)
Fibonacci heap
Analysis
Cascading cut takes O(1)
After cut, we get (# of child) additional trees
How much is merging cost per child ? O(1) because of the coin
How many child does a node has ? Degree of a node
POSCAT Seminar 1-672 July 2014
yougatup
6
12
18
8
11 17
14
38
2720
head 7
𝐵0′
4
3
Rearrange !
𝐵4′
2
![Page 68: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/68.jpg)
Fibonacci heap
Analysis
Let 𝑥 be any node in a Fibonacci heap. Then
size(𝑥) ≥ 𝐹𝑘+2 ≥ ∅𝑘 where 𝑘 is the degree of 𝑥, ∅ is golden ratio
Proof by induction on 𝑘. Consider a node 𝑥 of degree 𝑘 = 𝑛 + 1.
Let 𝑦𝑖 be the 𝑘 children of 𝑥, from oldest to youngest (i.e. 𝑦0 was
made children of 𝑥 before 𝑦1, and so on). Then
size(𝑥) = 1 + size(𝑦0) + size(𝑦1) + … + size(𝑦𝑘−1)
POSCAT Seminar 1-682 July 2014
yougatup
![Page 69: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/69.jpg)
Fibonacci heap
Analysis
Let 𝑥 be any node in a Fibonacci heap. Then
size(𝑥) ≥ 𝐹𝑘+2 ≥ ∅𝑘 where 𝑘 is the degree of 𝑥, ∅ is golden ratio
Proof by induction on 𝑘. Consider a node 𝑥 of degree 𝑘 = 𝑛 + 1.
The degree of 𝑦𝑖 is at least 𝑖 − 1 for 1 ≤ 𝑖 ≤ 𝑑 because we merge two
trees when their degree is the same.
POSCAT Seminar 1-692 July 2014
yougatup
![Page 70: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/70.jpg)
Fibonacci heap
Analysis
Let 𝑥 be any node in a Fibonacci heap. Then
size(𝑥) ≥ 𝐹𝑘+2 ≥ ∅𝑘 where 𝑘 is the degree of 𝑥, ∅ is golden ratio
Proof by induction on 𝑘. Consider a node 𝑥 of degree 𝑘 = 𝑛 + 1.
Therefore,
size(𝑥) = 1 + size(𝑦0) + size(𝑦1) + size(𝑦2) + … + size(𝑦𝑘−1)
≥ 1 + 1 + 𝐹2 + 𝐹3 + … + 𝐹𝑘
≥ 𝐹𝑘+2 ≥ ∅𝑘 ( also it can be proved by induction )
POSCAT Seminar 1-702 July 2014
yougatup
![Page 71: Poscat seminar 4](https://reader031.vdocuments.pub/reader031/viewer/2022022203/5876d45f1a28ab1d238b53e7/html5/thumbnails/71.jpg)
Fibonacci heap
Analysis
Therefore, 𝑘 ≤ log∅ 𝑠𝑖𝑧𝑒 (𝑥).
∴ 𝑘 ≤ log 𝑛
Therefore, decrease_key takes O(log 𝑛)
POSCAT Seminar 1-712 July 2014
yougatup