TAILIEUCHUNG - Thuật toán Algorithms (Phần 15)

Tham khảo tài liệu 'thuật toán algorithms (phần 15)', khoa học tự nhiên, toán học phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | PRIORITY QUEUES 133 again by exchanging C with the larger of its two sons in this case S . The process continues until the heap condition is no longer violated at the node occupied by C. In the example C makes it all the way to the bottom of the heap leaving The remove the largest operation involves almost the same process. Since the heap will be one element smaller after the operation it is necessary to decrement leaving no place for the element that was stored in the last position. But the largest element is to be removed so the remove operation amounts to a replace using the element that was in For example the following heap results from removing the T from the heap above The implementation of these procedures is centered around the operation of fixing up a heap which satisfies the heap condition everywhere except possibly at the root. The same operation can be used to fix up the heap after the value in any position is lowered. It may be implemented as follows 134 CHAPTER 11 procedure downheap k integer label 0 var i j v integer begin v a k while k N div 2 do begin j k k if j N then if a a j l then j j l if v a j then goto 0 a k a k j end 0 a k v end This procedure moves down the heap starting from position k exchanging the node at position j with the larger of its two sons if necessary stopping when j is larger than both sons or the bottom is reached. As above a full exchange is not needed because v is always involved in the exchanges. The inner loop in this program is an example of a loop which really has two distinct exits one for the case that the bottom of the heap is hit as in the first example above and another for the case that the heap condition is satisfied somewhere in the interior of the heap. Now the implementation of the remove operation is simple function remove integer begin remove a l a l a N N N-1 downheap l end The return value is set from then the element from a N is put into and the size of the heap decremented leaving only a call to .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.