第一范文网 - 专业文章范例文档资料分享平台

基于matlab构造最优二叉树

来源:用户分享 时间:2025/6/7 2:37:48 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

xxxx20xx届本科生毕业设计(论文)

disp('% p is a vector with the probability'); disp(p');

ltr=length(tr);% augment with the growing of the huffman tree lp=length(p);% decrease with the growing of huffman tree roolp=3; while lp>1

%if(length(list)-lp+1 <= 9)

%subplot(roolp,roolp,length(list)-lp+1); figure(length(list)-lp+1); drawhufftree(tr,list,tempp); %end

% merge p(lp) and p(lp-1); p(lp-1)=p(lp-1)+p(lp); p=p(1:lp-1);

% tr(ltr+1) is a new node of the huffman tree

% tr(find(tr==lp)) and tr(find(tr==lp-1)) is its two children ltr=length(tr); tr(find(tr==lp))=ltr+1; tr(find(tr==lp-1))=ltr+1; tr(ltr+1)=lp-1;

tempp(ltr+1)=p(lp-1); % record the probability of this node % sort p again after merging; pp=-p; [pp t]=sort(pp); p=-pp; %[p,t]=sort(p,'descend'); lp=length(p);

% tempp(1:lp-1)=p(1:lp-1); % update the order of probability to display % update the pointer of tr then temp=tr; for j=1:lp

tr(find(temp==t(j)))=j; end

%show the middle result disp('tr:(huffman tree)'); disp(tr');

disp('tempp:(probability on the tree)'); disp(tempp');

13

xxxx20xx届本科生毕业设计(论文)

disp('p:(probability)'); disp(p');

disp('t:(sort of p)'); disp(t'); end

tr(length(tr))=0; % the root of huffman tree %draw the result

figure(length(list)-lp+1); drawhufftree(tr,list,tempp); end

经过matlab的仿真可得到如下最优二叉树图形:

图4-1 最优二叉树仿真图(1)

14

xxxx20xx届本科生毕业设计(论文)

图4-2 最优二叉树仿真图(2)

15

xxxx20xx届本科生毕业设计(论文)

图4-3 最优二叉树仿真图(3)

16

搜索更多关于: 基于matlab构造最优二叉树 的文档
基于matlab构造最优二叉树.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c0l4zf7k9tn9vfqx3dfpk_5.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top