Presentation is loading. Please wait.

Presentation is loading. Please wait.

1Computer Sciences Department. 2 Advanced Design and Analysis Techniques TUTORIAL 7.

Similar presentations


Presentation on theme: "1Computer Sciences Department. 2 Advanced Design and Analysis Techniques TUTORIAL 7."— Presentation transcript:

1 1Computer Sciences Department

2 2 Advanced Design and Analysis Techniques TUTORIAL 7

3 Computer Sciences Department3 OBJECTIVES Steps of dynamic programming algorithm. Optimal binary search trees.

4 Computer Sciences Department4 The development of a dynamic programming algorithm  The development of a dynamic-programming algorithm can be broken into a sequence of four steps. 1. Characterize the structure of an optimal solution. 2. Recursively define the value of an optimal solution. 3. Compute the value of an optimal solution in a bottom-up fashion. 4. Construct an optimal solution from computed information.

5 Computer Sciences Department5 Computing the optimal costs

6 Computer Sciences Department6 Example For the following tables m and s and the given dimensions, compute the value of m[3,6] and s[3,6]

7 Computer Sciences Department7 m[3, 6] = 5375 S[3, 6] = 3 Solution

8 Computer Sciences Department8 Optimal binary search trees

9 Computer Sciences Department9 Regarding “Dynamic Programming [Optimal binary search trees]”: calculate the optimal solution for e[3,4]. deduce the values of w[3,4] and root[3,4]. Optimal binary search trees

10 Computer Sciences Department10 i ≤ r ≤ j 3 ≤ r ≤ 4, r = 3 or 4 W(3, 4) = 0.30 Solution

11 Computer Sciences Department11 Solution e[3, 4] = 0.60 r[3, 4] = 4

12 Computer Sciences Department12 Conclusion Dynamic programming is an optimization approach that transforms a complex problem into a sequence of simpler problems. Steps of dynamic programming algorithm :  Characterize the structure of an optimal solution.  Recursively define the value of an optimal solution.  Compute the value of an optimal solution in a bottom-up fashion.  Construct an optimal solution from computed information.

13 13Computer Sciences Department Greedy Algorithms TUTORIAL 8

14 Computer Sciences Department14 OBJECTIVES Huffman algorithm.  Fixed length codeword.  Variable length codeword. Example.

15 Computer Sciences Department15 Huffman codes EDCBA Characters 301562520 Frequency Construct the Huffman code tree for the given characters with their frequencies, and give the binary code for each character.

16 Computer Sciences Department16 C : 6 D : 15 E :30 A : 20 B : 25 45 Huffman codes (Fixed length) 21 30 66 30 96 0 1 1 1 10 0 0 0 0

17 Computer Sciences Department17 C : 6D : 15E :30A : 20B : 25 (a) A : 20 C : 6D : 15 21 B : 25E :30 (b) 10 Huffman codes (Variable length)

18 Computer Sciences Department18 A : 20 C : 6D : 15 21 B : 25E :30 (c) 41 1 1 0 0 Huffman codes (Variable length)

19 Computer Sciences Department19 A : 20 C : 6 D : 15 21 B : 25E :30 (d) 41 55 1 1 1 0 0 0 Huffman codes (Variable length)

20 Computer Sciences Department20 A : 20 C : 6 D : 15 21 B : 25E :30 (e) 41 55 96 0 0 0 0 1 1 1 1 Huffman codes (Variable length)

21 Computer Sciences Department21 Huffman codes Fixed length codeword Variable length codeword Frequency Count File value 0000020A 0011025B 010 6C 011 15D 1001130E

22 Computer Sciences Department22 Conclusion Huffman algorithm :  The Huffman encoding method assigns the shortest code to the most frequently occurring value in the file, and the longest code is assigned to the least frequently occurring value.  When tree is complete, all left sub trees are labeled with the binary value 0, and all right sub trees are labeled with the binary value 1.


Download ppt "1Computer Sciences Department. 2 Advanced Design and Analysis Techniques TUTORIAL 7."

Similar presentations


Ads by Google