数据结构 课件 选择树

上传人:仙*** 文档编号:244957014 上传时间:2024-10-06 格式:PPT 页数:43 大小:854.50KB
返回 下载 相关 举报
数据结构 课件 选择树_第1页
第1页 / 共43页
数据结构 课件 选择树_第2页
第2页 / 共43页
数据结构 课件 选择树_第3页
第3页 / 共43页
点击查看更多>>
资源描述
Click to edit Master title style,Click to edit Master text styles,Second level,Third level,Fourth level,Fifth level,*,Selection Trees,Winner trees.,Loser Trees.,Winner Trees,Complete binary tree with,n,external nodes and,n-1,internal nodes.,External nodes represent tournament(,比赛,)players.,Each internal node represents a match played between its two children;the winner of the match(,参赛者,)is stored at the internal node.,Root has overall winner.,Winner Tree For 16 Players,player,match node,Winner Tree For 16 Players,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,Smaller element wins,=min winner tree,.,3,6,1,3,2,4,2,5,3,1,2,2,1,2,1,Winner Tree For 16 Players,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,height is,log,2,n,(excludes player level),3,6,1,3,2,4,2,5,3,1,2,2,1,2,1,Complexity Of Initialize,O(1),time to play match at each match node.,n-1,match nodes.,O(n),time to initialize,n,player winner tree.,Applications,Sorting.,Insert elements to be sorted into a winner tree.,Repeatedly extract the winner and replace by a large value.,Sort 16 Numbers,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,3,6,1,3,2,4,2,5,3,1,2,2,1,2,1,Sort 16 Numbers,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,3,6,1,3,2,4,2,5,3,1,2,2,1,2,1,Sort 16 Numbers,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,3,6,1,3,2,4,2,5,3,1,2,2,1,2,1,Sorted array.,1,Sort 16 Numbers,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,3,6,5,3,2,4,2,5,3,1,2,2,1,2,1,Sorted array.,1,Sort 16 Numbers,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,3,6,3,5,3,2,4,2,5,3,2,2,1,2,1,Sorted array.,1,Sort 16 Numbers,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,3,6,3,5,3,2,4,2,5,3,2,2,3,2,1,Sorted array.,1,Sort 16 Numbers,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,3,6,3,5,3,2,4,2,5,3,2,2,3,2,2,Sorted array.,1,Sort 16 Numbers,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,3,6,3,5,3,2,4,2,5,3,2,2,3,2,2,2,2,Sorted array.,1,2,Sort 16 Numbers,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,3,6,3,5,3,6,4,2,5,3,2,2,3,2,2,2,2,Sorted array.,1,2,Sort 16 Numbers,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,3,6,3,5,3,6,4,2,5,3,4,2,3,2,2,2,2,Sorted array.,1,2,Sort 16 Numbers,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,3,6,3,5,3,6,4,2,5,3,4,2,3,2,2,2,2,Sorted array.,1,2,Sort 16 Numbers,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,3,6,3,5,3,6,4,2,5,3,4,2,3,2,2,2,2,Sorted array.,1,2,Sort 16 Numbers,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,3,6,3,5,3,6,4,2,5,3,4,2,3,2,2,Sorted array.,1,2,2,Sort 16 Numbers,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,3,6,3,5,3,6,4,5,5,3,4,2,3,2,2,Sorted array.,1,2,2,Sort 16 Numbers,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,3,6,3,5,3,6,4,5,5,3,4,5,3,2,2,Sorted array.,1,2,2,Sort 16 Numbers,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,3,6,3,5,3,6,4,5,5,3,4,5,3,4,2,Sorted array.,1,2,2,Sort 16 Numbers,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,3,6,3,5,3,6,4,5,5,3,4,5,3,4,3,Sorted array.,1,2,2,Sort 16 Numbers,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,3,6,3,5,3,6,4,5,5,3,4,5,3,4,3,Sorted array.,1,2,2,3,Time To Sort,Initialize winner tree.,O(n)time,Remove winner and replay.,O(log n)time,Remove winner and replay,n,times.,O(n log n),time,Total sort time is,O(n log n),.,Actually,Theta(n log n),.,Replace Winner And Replay,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,3,6,1,3,2,4,2,5,3,1,2,2,1,2,1,Replace winner with,6,.,Replace Winner And Replay,4,3,6,8,6,5,7,3,2,6,9,4,5,2,5,8,3,6,1,3,2,4,2,5,3,1,2,2,1,2,1,Replay matches on path to root.,Replace Winner And Replay,4,3,6,8,6,5,7,3,2,6,9,4,5,2,5,8,3,6,1,3,2,4,2,5,3,1,2,2,1,2,1,Replay matches on path to root.,Replace Winner And Replay,4,3,6,8,6,5,7,3,2,6,9,4,5,2,5,8,3,6,1,3,2,4,2,5,3,1,2,2,1,2,1,Opponent is player who lost last match played at this node.,Loser Tree,Each match node stores the match loser rather than the match winner.,Min Loser Tree For 16 Players,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,4,3,8,Min Loser Tree For 16 Players,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,4,6,8,3,5,1,7,Min Loser Tree For 16 Players,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,4,6,8,3,5,3,7,1,6,2,9,Min Loser Tree For 16 Players,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,4,6,8,3,5,3,7,2,5,2,8,1,6,4,9,Min Loser Tree For 16 Players,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,4,6,8,3,5,3,7,2,5,5,8,1,6,4,9,Min Loser Tree For 16 Players,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,4,6,8,3,5,3,7,2,5,5,8,1,6,4,9,Min Loser Tree For 16 Players,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,4,6,8,3,5,3,7,2,5,5,8,2,6,4,9,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,4,6,8,3,5,3,7,2,5,5,8,2,6,4,9,1,Winner,Complexity Of Loser Tree Initialize,One match at each match node.,One store of a left child winner.,Total time is,O(n).,More precisely,Theta(n).,Winner,4,3,6,8,1,5,7,3,2,6,9,4,5,2,5,8,4,6,8,3,5,3,7,2,5,5,8,2,6,4,9,1,Replace winner with,9,and replay matches.,9,5,9,3,3,2,Complexity Of Replay,One match at each level that has a match node.,O(log n),More precisely,Theta(log n).,More Selection Tree Applications,k,-way merging of runs during an external merge sort,
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 管理文书 > 施工组织


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!