CS 4521 Fall Semester, 2009

20 Points

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

You can modify your command interpreter from previous labs 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.
In addition to the standard insert, delete, and search operations,
you need to implement ** ShowTree()**, which displays the
structure of a B-tree (rotated 90 degrees to the left), 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 leaf[x] then ShowTree( c_(n[x]+1)[x], depth + 1 ) for i <- n[x] downto 1 do print key_i[x] right-justified in a field of (depth * 6) + 4 if not leaf[x] then ShowTree( c_i[x], 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 452.

** 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 452.
Here is some
**useful**.`pseudocode`