Goals
insert
operation on 2-3 Trees on
paper.Given the example 2-3 tree above, which of the following changes could be made while keeping it as a 2-3 tree?
Starting from an empty 2-3 tree, insert the following numbers in the order given. Draw the tree after each insertion.
18, 30, 48, 17, 35, 22, 50
Consider implementing a 2-3 tree. Let’s represent our 2-3 tree nodes as follows:
class Node {
Node c1; // left subtree, all values < k1
int k1; // left key
Node c2; // middle subtree, k1 < values < k2
int k2; // right key
Node c3; // right subtree, k2 < values
int degree; // number of keys; must be either 1 or 2
}
Write some pseudocode for a search
method that
returns whether a key is in the tree:
/** Return true if key is in the 2-3 tree rooted at n. */
boolean search(Node n, int key) {
// your implementation here
}
Write some pseudocode for an insert
method with the
following spec; Java doesn’t support multiple return values, but let’s
pretend we can return a 2-tuple.
/** Insert the given key into the 2-3 tree rooted at Node n.
: n is the root of a 2-3 tree, or null for an empty tre.
Pre:
Returns the root of the updated tree and a boolean- If the boolean is true, then the returned node is a degree-1 node resulting
; the new split nodes are already attached as its
from a splitting operation, and the node value being "kicked up" and needs to be added into its
children
parent- If the boolean is false, no further changes to the tree structure are needed
*/
(Node, boolean) insert(Node n, int key) {
// your implementation here
}