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

Tham khảo tài liệu 'thuật toán algorithms (phần 42)', 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ả | CONNECTIVITY 403 function fastfind x y integer union boolean boolean var i j t integer begin j x while dad i 0 do i dad i j y while dad j 0 do j dad j while dad x 0 do begin t x x dad x dad t i end while dad y do begin end if union and then if dad j dad i then begin dad J dad j dad i 1 dad i j end else begin dad i dad I dad j 1 dad j .i end fastfind i j end The dad array is assumed to be initialized to 0. We ll assume in later chapters that this is done in a separate procedure findinit. For our sample set of edges this program builds the following trees from the first ten edges The trees containing DEF and JKLM are flatter than before because of path compression. Now FE doesn t contribute anything as before then AF combines the first two trees with A at the root since its tree is larger the GC doesn t contribute anything then GH puts the HI tree below A then JG puts the JKLM tree below A resulting in the following tree The following table gives the contents of the dad array as this forest is constructed 404 CHAPTER 30 ABCDEFGH I JKLM A G A B A C 3AAOOOAOOOOO0 LM 3AA00OA00001L JM 3AA0 0 O A 0 O L 0 2L JL 3AAOOOAOOL02L J K E D F D HI 3AAE 2EA 1HLL3 L F E A F 6AAEAEA1HLL3L G E 6AAEAEA1HLL3L G C 6AAEAEA1HLL3L G H JG 12AAEAEAAHL LA L LG 12AAEAEAAHLLAL For clarity in this table each positive entry i is replaced by the ith letter of the alphabet the name of the father and each negative entry is complemented to give a positive integer the weight of the tree . Several other techniques have been developed to avoid degenerate structures. For example path compression has the disadvantage that it requires another pass up through the tree. Another technique called halving is to make each node point to its granddad on the way up the tree. Still another technique splitting is like halving but is applied only to every other node on the search path. Either of these can be used in combination with weight balancing or with height balancing which is similar but uses tree height instead

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.