数据结构 哈夫曼树.ppt

  1. 1、本文档共47页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
数据结构 哈夫曼树

Each element of S forms a equivalence subset of their own. S1,S2,…,Sn Read an equivalence pair x ≡ y, determine which subset that x and y are belong to. If they are different, then the two sets are to be replaced by their union. After processing all equivalence relations, these non-empty subsets are equivalence classes of R on S. Equivalence Classes Generation Algorithm The Algorithm Initialize N disjoint sets; /* read in all the relations */ while ( read in a ≡ b ) { if ( ! (Find(a) == Find(b)) ) Union the two sets; } /* output the result */ output all remaining sets; 0 1 2 3 4 5 6 data parent Representation :Parent linked list A B C D E F 〖Example〗 S1 = { 6, 7, 8, 10 }, S2 = { 1, 4, 9 }, S3 = { 2, 3, 5 } 10 6 8 7 4 1 9 2 3 5 A possible forest representation of these sets Note: Pointers are from children to parents ? Operations : (1) Union( i, j ) ::= Replace Si and Sj by S = Si ? Sj (2) Find( i ) ::= Find the set Sk which contains the element i. Representation :Parent linked list ? Union ( i, j ) Idea: Make Si a subtree of Sj , or vice versa. That is, we can set the parent pointer of one root to the other’s root. 10 6 8 7 4 1 9 4 1 9 10 6 8 7 S1 ? S2 S2 ? S1 Note: the parent of root is -1. The root’s index represents the set name. 10 6 8 7 4 1 9 2 3 5 〖Example〗The array representation of the three sets are: ( S1 ? S2 ? S1 ) ? S [ 4 ] = 10 [1] 4 [2] -1 [10] -1 [9] 4 [8] 10 [7] 10 [6] 10 [5] 2 [4] -1 [3] 2 S ? Union ( i, j ) 10 6 8 7 4 1 9 2 3 5 [1] 4 [2] -1 [10] -1 [9] 4 [8] 10 [7] 10 [6] 10 [5] 2 [4] 10 [3] 2 S int find( MFSet S, int i){ if( i1 || iS.n) return -1; for( j=i; S.nodes[j].parent=0; j=S.nodes[j].parent); return j; } int Union( MFSet s, int i, int j){ if( i1||iS.n||j1||jS.n) return ERROR; S.nodes[i].parent=j; return j; } O(tree height) O( 1) Smart Union Strategies 4 2 9 30 5 13 11 1 7 8 3 22 6 10 20 16 14 12 union(7,13) Which tree should become a subtree of the other? Height Rule M

文档评论(0)

shuwkb + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档