Survey

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Survey

Document related concepts

Transcript

Chapter 8--Disjoint Set ADT The disjoint set ADT is an efficient data structure to solve the equivalence problem. An equivalence relation R on a set S satisfies three properties: 1. 2. 3. Section 8.2 The Dynamic Equivalence Problem equivalence class data structure -- disjoint set ADT. operations The union/find algorithm The algorithm must operate on-line Two strategies A fast find operation Section 8.3 Figure 1 : 1 2 3 4 5 6 7 8 3 8 5 7 5 8 Union operations 5 2 Figure 2 Union operations Result of union(6, 4) on the set in figure 2: Figure 3 Section 8.4 Smart Union Algorithms union by height Section 8.5 Path Compression Example of path compression Now, after find(2) the result is: Other operations: Skip lists Motivation: Skip Lists (continued) Inserting 30 into the list Generating nodes for skip lists Algorithm is taken from Lewis and Denenberg's Data Structures & Their Algorithms function RandomLevel(): integer // Produce a random level between 0 and MaxLevel v0 while Rand() < 1/2 and v < MaxLevel do v v+ 1 return v The find operation on a skip list Advantages and disadvantages of skip lists Huffman Codes Suppose the following bit strings are the codes to w, x, y and z: w 00 x y 101 10 z 110 Consider the string 10110. Consider instead the following code for the same four characters: w 0 x y z 100 101 11 Then the message 01100110101100 decodes as Building Huffman Codes Methodology: Huffman Code Example letter: frequency: E 50 T 40 A 30 O 25 I 20 N 15 I N Then we have the following codes: letter: code: E T A O Huffman(C) n |C| QC for i 1 to n – 1 create a new node z left[z] x where x is obtained by a deletemin(Q) right[z] y where y is obtained by a deletmin(Q) freq[z] freq[x] + freq[y] insert(Q, z) return(deletemin(Q)) // the root of the tree