数据结构与程序设计(王丽苹)30multiwaysearch.ppt
《数据结构与程序设计(王丽苹)30multiwaysearch.ppt》由会员分享,可在线阅读,更多相关《数据结构与程序设计(王丽苹)30multiwaysearch.ppt(40页珍藏版)》请在三一办公上搜索。
1、9/18/2023,数据结构与程序设计,1,数据结构与程序设计(30),王丽苹,9/18/2023,数据结构与程序设计,2,Multiway Search Trees,An m-way search tree is a tree in which,for some integer m called the order of the tree,each node has at most m children.If k=m is the number of children,then the node contains exactly k-1 keys,which partition all th
2、e keys into k subsets consisting of all the keys less than the first key in the node,all the keys between a pair of keys in the node,and all keys greater than the largest key in the node.,9/18/2023,数据结构与程序设计,3,9/18/2023,数据结构与程序设计,4,Balanced Multiway Trees(B-Trees)p536,DEFINITION A B-tree of order m
3、is an m-way search tree in which:1.All leaves are on the same level.2.All internal nodes except the root have at most m nonempty children,and at least m/2 nonempty children.3.The number of keys in each internal node is one less than the number of its nonempty children,and these keys partition the ke
4、ys in the children in the fashion of a search tree.4.The root has at most m children,but may have as few as 2 if it is not a leaf,or none if the tree consists of the root alone.,9/18/2023,数据结构与程序设计,5,B-Trees,9/18/2023,数据结构与程序设计,6,Data Structure-B_node(1)P539,template struct B_node/data members:int c
5、ount;Entry dataorder-1;B_node*branchorder;/constructor:B_node();,9/18/2023,数据结构与程序设计,7,Data Structure-B_node(1)P539,Data structure of B-tree node:,Example of one 6 order B-tree node:count=4,A C E I K,9/18/2023,数据结构与程序设计,8,Discuss-B_node(2),count gives the number of Entrys in the B_node.If count is n
6、onzero then the node has count+1 children.branch0 points to the subtree containing all Entrys with keys less than that in data0.For 1=position=count-1,branchposition points to the subtree with keys strictly between those in the subtrees pointed to by dataposition-1 and dataposition.branchcount point
7、s to the subtree with keys greater than that of datacount-1.,9/18/2023,数据结构与程序设计,9,Data Struct-B_node(3),template B_node:B_node()/data members:count=0;,9/18/2023,数据结构与程序设计,10,Method in B-tree,Search target in B-Tree.P540-541Insertion a node to B-Tree.P542-547Remove a node in B-Tree.P548-554,9/18/202
8、3,数据结构与程序设计,11,B-tree Search Method Declaration,#includeB_node.cppenum Error_codenot_present,duplicate_error,overflow,success;template class B_tree public:/Add public methods.Error_code search_tree(Entry,9/18/2023,数据结构与程序设计,12,B-tree constructor,template B_tree:B_tree()/data members:root=NULL;,9/18/
9、2023,数据结构与程序设计,13,B_tree Search implementation,template Error_code B_tree:search_tree(Entry,9/18/2023,数据结构与程序设计,14,How to search target Key u or h,9/18/2023,数据结构与程序设计,15,template Error_code B_tree:recursive_search_tree(B_node*current,Entry,9/18/2023,数据结构与程序设计,16,B-tree search a node,template Error_c
10、ode B_tree:search_node(B_node*current,const Entry,9/18/2023,数据结构与程序设计,17,Discuss:B-tree search a node,For B-trees of large order,this function should be modified to use binary search instead of sequential search.Another possibility is to use a linked binary search tree instead of a sequential array
11、of entries for each node.,9/18/2023,数据结构与程序设计,18,Insertion into a B-Tree,In contrast to binary search trees,B-trees are not allowed to grow at their leaves;instead,they are forced to grow at the root.General insertion method:,9/18/2023,数据结构与程序设计,19,Insertion into a B-Tree P538,1.Search the tree for
12、the new key.This search(if the key is truly new)will terminate in failure at a leaf.2.Insert the new key into to the leaf node.If the node was not previously full,then the insertion is finished.Full node Split:3.When a key is added to a full node,then the node splits into two nodes,side by side on t
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构 程序设计 王丽苹 30 multiwaysearch
链接地址:https://www.31ppt.com/p-6050250.html