# On the leaf level it takes one random disk access to

• Notes
• 12

This preview shows page 10 - 12 out of 12 pages.

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 filled, 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.

Subscribe to view the full document.

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 first 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 first 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 first 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 filled. To make this index structure meet the requirements of a B + -tree, we can re- distribute the keys of the last two pages at each level. Since the last but one node is always full, redistribution makes sure that both of then are at least half filled. 11.14 Answer: In a B + -tree index or file organization, leaf nodes that are adjacent to each other in the tree may be located at different places on disk. When a file organization is newly created on a set of records, it is possible to allocate blocks that are mostly contiguous on disk to leafs nodes that are contiguous in the tree. As insertions and deletions occur
12 Chapter 11 Indexing and Hashing
• Spring '13
• Dr.Khansari
• hash function, Prime number, Bucket address table

{[ snackBarMessage ]}

###### "Before using Course Hero my grade was at 78%. By the end of the semester my grade was at 90%. I could not have done it without all the class material I found."
— Christopher R., University of Rhode Island '15, Course Hero Intern

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern