CS 4521 Fall Semester, 2012

20 Points

**
The assignment **
consists of two parts: **(1)** coding B-Trees (except delete, but including
** B-Tree-Minimum()** and

You can use the command interpreter below (or modify one from a previous lab) to test your B-tree implementation using the following test files:

Here is an example using ** treetest1**:

treetest1 commands +------------------------------------------------+ | # create tree (done in a constructor) | | c | | | | # insert 10 items | | i 372 | | i 245 | | i 491 | | i 474 | | i 440 | | i 122 | | i 418 | | i 125 | | i 934 | | i 752 | | | | # Show tree structure | | S | | | | # search for item 122 in tree | | s 122 | | | | # search for item 441 not in tree | | s 441 | | | | # end of test | +------------------------------------------------+The output from

treetest1 script using B-trees +-------------------------------------------------------+ | # create tree (done in a constructor) | | # insert 10 items | | # Show tree structure | | | | Structure of Btree (rotated 90 degrees to the left): | | | | 934 | | 752 | | 491 | | 474 | | 440 | | 418 | | 372 | | 245 | | 125 | | 122 | | | | # search for item 122 in tree | | Key 122 found at index 1 in node: | | | | Leaf = True, n = 5 | | Keys: 122 125 245 372 418 | | | | # search for item 441 not in tree | | Key 441 not found | | | | # end of test | +-------------------------------------------------------+

**Discussion of B-tree Implementation: **

As mentioned in class, B-trees are balanced trees designed to hold large
amounts of data and designed to work efficiently with disk memory.
You are given ** ShowTree()**, which displays the
structure of a B-tree (rotated 90 degrees to the left).
So you need to implement
the insert, and search operations (and delete in Lab 10), and auxiliary
operations such as

Here is the overall implementation strategy that I used:
I first implemented the code of
** B-Tree-Create()** in a constructor, then

**Implementation of Insertion, etc. **

I implemented ** B-Tree-Create()** and

**Implementation of ShowTree() **

Here is some pseudocode for ` ShowTree()`:

ShowTree(x, depth) // x points to root of subtree of given depth if not x.leaf ShowTree( x.c_(x.n+1), depth + 1 ) for i = x.n downto 1 print x.key_i right-justified in a field of (depth * 6) + 7 if not x.leaf ShowTree( x.c_i, depth + 1 )

**Implementation of the Search Operation**

For ** B-Tree-Search()**, I first defined a new data type

** Helpful code: **
Here is a
.h file for the BTree class
** btree.h**.
and skeleton code for the BTree class implementation

**B-Tree-Delete pseudocode: **

This is Exercise 18.3-2, page 502.

** What To Hand In: **

- Clearly marked scripts of
and`treetest1`which test insertion. Outline the nodes and draw the child pointers by hand on your output.`treetest2` - Well documented code for your B-tree implementation so far (the rest will be in the next lab assignment).
- Do Exercise 18.3-2, page 502.
Here is some
**useful**.`pseudocode`