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 104 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

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Appendix A: Heap Bottom-up Construction Course: Algorithm Analysis and Design SinhVienZone.Com... Heap bottom up constructionThis method views every position in the array as the root of

Trang 1

Appendix A: Heap

Bottom-up Construction

Course: Algorithm Analysis and Design

SinhVienZone.Com

Trang 2

Heap bottom up construction

This method views every position in the array as the root of a

small heap and uses downheap procedure for such small

heaps.

SinhVienZone.Com

Trang 3

Heap bottom-up construction procedure

procedure build_heap;

begin

for k:= M div 2 downto 1 do

downheap(k);

end

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

Trang 4

 Property: Bottom-up heap construction is

linear-time.

For example: To build a heap of 127 elements, the

method calls downheap on

- 64 heaps of size 1

- 32 heaps of size 3

- 16 heaps of size 7

- 8 heaps of size 15

- 4 heaps of size 31

- 2 heaps of size 63

- 1 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.2SinhVienZone.Com4 + 3.23 + 4.22 + 5.21 + 6.20

Trang 5

0.26 + 1.25 + 2.24 + 3.23 + 4.22 + 5.21 + 6.20

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

TỪ KHÓA LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm