1112 answer if the index entries are inserted in

Info iconThis preview shows pages 10–12. Sign up to view the full content.

View Full Document Right Arrow Icon
11.12 Answer: If the index entries are inserted in ascending order, the new entries get directed to the last leaf node. When this leaf node gets Flled, it is split into two. Of the two nodes generated by the split, the left node is left untouched and the insertions takes place on the right node. This makes the occupancy of the leaf nodes to about 50 percent, except the last leaf. If keys that are inserted are sorted in descending order, the above situation would still occur, but symmetrically, with the right node of a split never getting touched again, and occupancy would again be 50 percent for all nodes other than the Frst leaf. 11.13 Answer: a. The cost to locate the page number of the required leaf page for an insertion is negligible since the non-leaf nodes are in memory. On the leaf level it takes one random disk access to read and one random disk access to update it along with the cost to write one page. Insertions which lead to splitting of leaf nodes require an additional page write. Hence to build a B + -tree with n r entries it takes a maximum of 2 n r random disk accesses and n r + 2 ( n r / f ) page writes. The second part of the cost comes from the fact that in the worst case each leaf is half Flled, so the number of splits that occur is twice n r / f . The above formula ignores the cost of writing non-leaf nodes, since we assume they are in memory, but in reality they would also be written eventually. This cost is closely approximated by 2 ( n r / f ) / f , which is the number of internal nodes just above the leaf; we can add further terms to account for higher levels of nodes, but these are much smaller than the number of leaves and can be ignored. b. Substituting the values in the above formula and neglecting the cost for page writes, it takes about 10 , 000 , 000 20 milliseconds, or 56 hours, since each insertion costs 20 milliseconds.
Background image of page 10

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Exercises 11 c. function insert in leaf(value K , pointer P ) if (tree is empty) create an empty leaf node L , which is also the root else Find the last leaf node in the leaf nodes chain L if ( L has less than n 1 key values) then insert ( K , P ) at the ±rst available location in L else begin Create leaf node L 1 Set L . P n = L 1; Set K 1 = last value from page L insert in parent(1, L , K 1, L 1) insert ( K , P ) at the ±rst location in L 1 end function insert in parent(level l , pointer P , value K , pointer P 1) if (level l is empty) then begin Create an empty non-leaf node N , which is also the root insert( P , K , P 1) at the starting of the node N return else begin Find the right most node N at level l if ( N has less than n pointers) then insert( K , P 1) at the ±rst available location in N else begin Create a new non-leaf page N 1 insert ( P 1) at the starting of the node N insert in parent( l + 1, pointer N , value K , pointer N 1) end end The insert in leaf function is called for each of the value, pointer pairs in ascending order. Similar function can also be build for de- scending order. The search for the last leaf or non-leaf node at any level can be avoided by storing the current last page details in an array. The last node in each level might be less than half ±lled. To make
Background image of page 11
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page10 / 12

1112 Answer If the index entries are inserted in ascending...

This preview shows document pages 10 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online