1. Trang chủ
  2. » Giáo án - Bài giảng

phân tích va thiết kế giải thuật dương tuấn anh appendix a heap bottom up construction sinhvienzone com

5 103 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 182,65 KB

Nội dung

om nh Vi en Zo ne C Appendix A: Heap Bottomup Construction Si Course: Algorithm Analysis and Design SinhVienZone.com https://fb.com/sinhvienzonevn Heap bottom up construction Si nh Vi en Zo ne C om This method views every position in the array as the root of a small heap and uses downheap procedure for such small heaps Figure 1: The heap created from the array of characters: A, S, O, R, T, I, N, G, E, X, A, M, P, L, E SinhVienZone.com https://fb.com/sinhvienzonevn nh Vi en Zo ne C procedure build_heap; begin for k:= M div downto downheap(k); end om Heap bottom-up construction procedure Si M: the number of elements in the heap The keys in a[ (M div 2)+1 M] each form heaps of one element, so they satisfy the heap condition and don’t need to be checked SinhVienZone.com https://fb.com/sinhvienzonevn Property: Bottom-up heap construction is lineartime For example: To build a heap of 127 elements, the method calls downheap on - 64 heaps of size - 32 heaps of size - 16 heaps of size - heaps of size 15 - heaps of size 31 - heaps of size 63 - heaps of size 127 So the method needs 64.0 + 32.1 + 16.2 + 8.3 + 4.4 + 2.5 + 1.6 = 120 “promotions” 0.26 + 1.25 + 2.24 + 3.23 + 4.22 + 5.21 + 6.20 Si nh Vi en Zo ne C om  SinhVienZone.com https://fb.com/sinhvienzonevn om 0.26 + 1.25 + 2.24 + 3.23 + 4.22 + 5.21 + 6.20 (M= 127 = 27 -1) m = Si nh Vi en Zo ne C For M = 2m, an upper bound on the number of comparisions is (1-1)2m-1 + (2-1)2m-2 + (3 -1)2m-3+… + (k-1)2m-k + … (m-1-1)2m-(m-1) + (m -1)2m-m = 1.2m-2 + 2.2m-3 +3.2m-4+ 4.2m-5 +…+ (k-1)2m-k + … (m-2)21 + (m -1)20 = (2m-2 + 2m-3 + …+ 20) + (2m-3 + …+ 20) + (2m-4 + …+ 20) …+(22 + 21 + 20) + (21 + 20) + = (2m-1 -1)+ (2m-2 -1) + … (23-1) + (22-1) +(21-1) = (2m-1 + 2m-2 + … 22 + 21)– m +1 = (2m-1 + 2m-2 + … 22 + 21+1) – m = (2m -1) – m < M So the complexity of heap bottom-up building is O(M) SinhVienZone.com https://fb.com/sinhvienzonevn .. .Heap bottom up construction Si nh Vi en Zo ne C om This method views every position in the array as the root of a small heap and uses downheap procedure for such small heaps Figure 1: The heap. .. downto downheap(k); end om Heap bottom- up construction procedure Si M: the number of elements in the heap The keys in a[ (M div 2)+1 M] each form heaps of one element, so they satisfy the heap condition... condition and don’t need to be checked SinhVienZone. com https://fb .com/ sinhvienzonevn Property: Bottom- up heap construction is lineartime For example: To build a heap of 127 elements, the method calls

Ngày đăng: 30/01/2020, 22:02

TỪ KHÓA LIÊN QUAN