![Phân tích tư tưởng của nhân dân qua đoạn thơ: Những người vợ nhớ chồng… Những cuộc đời đã hóa sông núi ta trong Đất nước của Nguyễn Khoa Điềm](https://timtailieu.net/upload/document/136415/phan-tich-tu-tuong-cua-nhan-dan-qua-doan-tho-039-039-nhung-nguoi-vo-nho-chong-nhung-cuoc-doi-da-hoa-song-nui-ta-039-039-trong-dat-nuoc-cua-nguyen-khoa-136415.jpg)
Lecture Data Structures: Lesson 29
Số trang: 20
Loại file: ppt
Dung lượng: 498.00 KB
Lượt xem: 4
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Lecture Data Structures: Lesson 29 provide students with knowledge about complete binary tree; the heap ADT; the parent node has key smaller than or equal to both of its children nodes; heap property violated; inserting into a heap;...
Nội dung trích xuất từ tài liệu:
Lecture Data Structures: Lesson 29Data Structures Lecture 29 Sohail Aslam 1Complete Binary Tree 1 A 2 3 B C 4 5 6 7 D E F G 8 9 10 H I J A B C D E F G H I J 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Question: why don’t we store all binary trees in arrays? Why use pointers? 2The Heap ADT 3 Heap A heap is a complete binary tree that conforms to the heap order. The heap order property: in a (min) heap, for every node X, the key in the parent is smaller than (or equal to) the key in X. Or, the parent node has key smaller than or equal to both of its children nodes. 4Heap 13 21 16 24 31 19 6865 26 32 Thisisaminheap 5HeapNot a heap: heap property violated 13 21 19 6 31 16 68 65 26 32 6 Heap Analogously, we can define a max-heap, where the parent has a key larger than the its two children. Thus the largest key would be in the root. 7Inserting into a Heap 1 13 2 21 3 16 4 24 5 31 6 19 7 68 8 9 26 10 32 65 Thisisanexistingheap 13 21 16 24 31 19 68 65 26 32 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 8Inserting into a Heap 1insert(14) 13 2 21 3 16 4 24 5 31 6 19 7 68 8 9 26 10 32 11 14 65 13 21 16 24 31 19 68 65 26 32 14 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 9Inserting into a Heap 1insert(14) 13 2 21 3 16 4 24 5 31 6 19 7 68 8 9 26 10 32 11 65 13 21 16 24 31 19 68 65 26 32 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 10Inserting into a Heap 1insert(14) 13 2 21 3 16 4 24 5 6 19 7 68 8 9 26 10 32 11 31 65 13 21 16 24 19 68 65 26 32 31 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 11Inserting into a Heap 1insert(14) 13 2 3 16 4 24 5 21 6 19 7 68 8 9 26 10 32 11 31 65 13 16 24 21 19 68 65 26 32 31 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 12Inserting into a Heap 1insert(14) 13 2 14 3 16 4 24 5 21 6 19 7 68 8 9 26 10 32 11 31 65 13 14 16 24 21 19 68 65 26 32 31 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 13Inserting into a Heap 1insert(14) with 13exchange 2 21 3 16 4 24 5 31 6 19 7 68 8 9 26 10 32 11 14 65 13 21 16 24 31 19 68 65 26 32 14 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14Inserting into a Heap ...
Nội dung trích xuất từ tài liệu:
Lecture Data Structures: Lesson 29Data Structures Lecture 29 Sohail Aslam 1Complete Binary Tree 1 A 2 3 B C 4 5 6 7 D E F G 8 9 10 H I J A B C D E F G H I J 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Question: why don’t we store all binary trees in arrays? Why use pointers? 2The Heap ADT 3 Heap A heap is a complete binary tree that conforms to the heap order. The heap order property: in a (min) heap, for every node X, the key in the parent is smaller than (or equal to) the key in X. Or, the parent node has key smaller than or equal to both of its children nodes. 4Heap 13 21 16 24 31 19 6865 26 32 Thisisaminheap 5HeapNot a heap: heap property violated 13 21 19 6 31 16 68 65 26 32 6 Heap Analogously, we can define a max-heap, where the parent has a key larger than the its two children. Thus the largest key would be in the root. 7Inserting into a Heap 1 13 2 21 3 16 4 24 5 31 6 19 7 68 8 9 26 10 32 65 Thisisanexistingheap 13 21 16 24 31 19 68 65 26 32 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 8Inserting into a Heap 1insert(14) 13 2 21 3 16 4 24 5 31 6 19 7 68 8 9 26 10 32 11 14 65 13 21 16 24 31 19 68 65 26 32 14 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 9Inserting into a Heap 1insert(14) 13 2 21 3 16 4 24 5 31 6 19 7 68 8 9 26 10 32 11 65 13 21 16 24 31 19 68 65 26 32 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 10Inserting into a Heap 1insert(14) 13 2 21 3 16 4 24 5 6 19 7 68 8 9 26 10 32 11 31 65 13 21 16 24 19 68 65 26 32 31 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 11Inserting into a Heap 1insert(14) 13 2 3 16 4 24 5 21 6 19 7 68 8 9 26 10 32 11 31 65 13 16 24 21 19 68 65 26 32 31 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 12Inserting into a Heap 1insert(14) 13 2 14 3 16 4 24 5 21 6 19 7 68 8 9 26 10 32 11 31 65 13 14 16 24 21 19 68 65 26 32 31 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 13Inserting into a Heap 1insert(14) with 13exchange 2 21 3 16 4 24 5 31 6 19 7 68 8 9 26 10 32 11 14 65 13 21 16 24 31 19 68 65 26 32 14 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14Inserting into a Heap ...
Tìm kiếm theo từ khóa liên quan:
Lecture Data Structures Bài giảng Cấu trúc dữ liệu Data structures Complete binary tree The heap ADT Heap property violatedTài liệu liên quan:
-
Bài giảng Cấu trúc dữ liệu và thuật toán: Chương 3 - Một số mô hình thuật toán
42 trang 79 0 0 -
Bài giảng Cấu trúc dữ liệu và giải thuật: Chương 2 - Ngô Công Thắng
8 trang 69 0 0 -
Bài giảng Cấu trúc dữ liệu và giải thuật: Chương 5 - ThS. Trịnh Quốc Sơn (ĐH Công nghệ Thông tin)
20 trang 54 0 0 -
Ebook Eloquent JavaScript - A modern introduction to programming: Part 1
199 trang 36 0 0 -
Giáo trình cấu trúc dữ liệu part 4
16 trang 35 0 0 -
Bài giảng Cấu trúc dữ liệu và thuật toán: Chương 1 - Khái niệm cơ bản
19 trang 34 0 0 -
Giáo trình cấu trúc dữ liệu part 3
16 trang 32 0 0 -
Lecture Introduction to computing systems (2/e): Chapter 19 - Yale N. Patt, Sanjay J. Patel
28 trang 31 0 0 -
Bài giảng Cấu trúc dữ liệu và giải thuật: Bài 14a - Hoàng Thị Điệp (2014)
35 trang 31 0 0 -
Ebook Introduction to algorithms (3rd edition)
1313 trang 30 0 0