Question
The first and second picture are the definition of 2-3 tree,3rd and 4th are the pre-condition and post-condition. Please use these question to solve problem 8,the last photo.
2-3 Trees: Definition Suppose that E is an ordered type, that is, a nonempty set of values that have a total order. A 2-3-tre
(3, 9,20) (1, 3) (5,9) (10, 16, 20) 3 10 16 Figure 1: A 2-3 Tree each of the values stored at the leaves of the second subtre

2-3 Trees: Insertions Consider, now, the problem of inserting an element into the set stored by a 2-3 tree. If this is to be

} Figure 3: An Incomplete Algorithm to Search in a Subtree of this 2-3 Tree Postcondition: (a) If the input key is not alread


I 8. Briefly describe how to solve the above problem in the following cases. (a) T is an empty tree, so that its root is a nu
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Insertion into 2-3 Tree:

a) T is an empty tree,so that it's root is a null node.

simplified algorithm

Suppose we are to insert 2 values (5,6) into the empty tree

1. Initially create a node which will also serve as the root node for this case

2. Insert the first value into this node

3. to insert the next value

if (this.value > prev.value)   //check if the next value to be inserted is greater than the previous value in root node

then insert to the right of the prev.value

else

then insert to the left of the prev.value

4.continue with normal insertion algorithm (if) for more elements.

STEP 1 STEP 2 5 STEP 3 6 LO LO

In this situation the only root node is also leaf node

b) T is not empty, but the set it represents has size one (so that it's root is a leaf)

simplified algorithm

Suppose the root node already contains the element 5 and now the insertion data is (6,7)

1.to insert the first value

if (this.value > prev.value)  

then insert to the right of the prev.value

else

then insert to the left of the prev.value

2.to insert the next value

   //here prev.value is the last item that has been inserted

if (this.value > prev.value)

then insert to the right of the prev.value

else

then insert to the left of the prev.value

3.if (length(node) >= 3)    //such that the node now has more than two elements

1. create a new node,push up and set it as root node

2.insert middle.value of the leaf node into the root node.   //the median value is pushed up

4.continue with normal insertion algorithm (if) for more elements.

STEP 1 7 STEP 2 5 7 6 STEP 3 5 7 5 LO LC LC

I hope my answers satisfy your requirements. I have made the algorithm simplified,case specific and not added additional functions such a checking if the value has occurred before,and if yes then to return a ElementFoundException.

If you have any questions leave them in the comments. If you are satisfied with the answer please leave a thumbs up, it really matters.

Thank You.

Add a comment
Know the answer?
Add Answer to:
The first and second picture are the definition of 2-3 tree,3rd and 4th are the pre-condition...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 3. [5 marks] Suppose T is a binary tree that stores an integer key value in...

    3. [5 marks] Suppose T is a binary tree that stores an integer key value in each node. Assume the following notation/operations on a binary tree. » the key T.key is the root node's integer key value . the left child T.left is T's left subtree, which is possibly an empty tree (or null) the right child T.right is T's right subtree, which is possibly an empty tree (or null) (a) Write an efficient algorithm FINDMAxPrODuCT(T) in pseudocode that returns...

  • 2. A regular binary tree is a binary tree whose internal nodes all have two subtrees...

    2. A regular binary tree is a binary tree whose internal nodes all have two subtrees (left and right). In other words, all their nodes have either zero subtrees (in which case they are leaves) or two subtrees (in which case they are internal nodes). Suppose that you have a boolean function that tells you, for each node of the tree, whether it is a leaf or not (call it: leaf(n), for node n). a) Write a recursive function that...

  • k-d tree Background One generalization of binary trees is the k-d tree, which stores k-dimensional data....

    k-d tree Background One generalization of binary trees is the k-d tree, which stores k-dimensional data. Every internal node of a k-d tree indicates the dimension d and the value v in that dimension that it discriminates by. An internal node has exactly two children, containing data that is less-than-or-equal and data that is greater than v in dimension d. For example, if the node distinguishes on dimension 1, value 107, then the left child is for data with y...

  • Can you give me a poste for Science Writing TOPIC: DECISION TREE Decision Tree Algorithm Pseudocode:-...

    Can you give me a poste for Science Writing TOPIC: DECISION TREE Decision Tree Algorithm Pseudocode:- 1) Place the best attribute of the dataset at the root node of the tree. 2) Split the training set into subsets. Subsets should be make in such a way that each subset contains data with the same value for an attribute. 3) Repeat steps 1 and 2 on each subset until you find leaf nodes in all the branches of the tree. Two...

  • QUESTION 8   In the _____ traversal, the root is processed first, before its subtrees. breadth first...

    QUESTION 8   In the _____ traversal, the root is processed first, before its subtrees. breadth first preorder postorder inorder 0.10000 points    QUESTION 9 What kind of traversal does the following algorithm (in pseudo-code) describe? Algorithm traversal (root) if (root is not null)      traversal (leftSubTree)      process (root)      traversal (rightSubTree) end if end traversal breadth first preorder inorder postorder 0.10000 points    QUESTION 10 What kind of traversal does the following algorithm (in pseudo-code)  describe? Algorithm traversal (root) if...

  • 1. Game Tree (1) In the following tree, fill in the Minimax values for the internal nodes using t...

    1. Game Tree (1) In the following tree, fill in the Minimax values for the internal nodes using the given values at the leaves. (2) Perform Alpha-Beta pruning twice on this tree, first assuming left-to-right node expansion, and second assuming right-to-left node expansion. In this tree, the root node is the maximizer player. ST 6 12 N O 6 12 6 -1 1. Game Tree (1) In the following tree, fill in the Minimax values for the internal nodes using...

  • In C++ I need the printRange function, and the main.cpp program. Thanks. (Binary search tree) Write...

    In C++ I need the printRange function, and the main.cpp program. Thanks. (Binary search tree) Write a function printRange that takes as input a binary search tree t and two keys, k1 and k2, which are ordered so that k1 < k2, and print all elements x in the tree such that k1 <= x <= k2. You can add this function in BinarySearchTree.h (click the link) that we used in the lecture and lab 7. public: void printRange(int k1,...

  • . [25 pts.] Tree node with largest value children. Consider a complete ternary tree where each...

    . [25 pts.] Tree node with largest value children. Consider a complete ternary tree where each node apart from the leaves has exactly 3 children and is associated with a numeric key k. a [15 pts.] Write the pseudo-code of a procedure that returns the node whose children have the largest sum of keys, i.e. the score of a node is the sum of its children key values. Note that leaves would not be considered as they do not have...

  • 1. A node that is a descendant of another node is called its a. root b....

    1. A node that is a descendant of another node is called its a. root b. sibling c. parent d. child 2. Any node in a tree that does not have any children is refered to as a a. leaf b. tail c. head d. root 3. A binary search tree is a binary tree with what property? a. An internal node is greater than all of its children b. An internal node is less than all of its children...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT