Question

Consider the given binary search tree (BST). 1. What is the maximum size of the array required to implement the above BST? 2.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. The maximum size of the array required to represent this tree is equal to 2n-1, where n being the numeber of levels.

In this case we have 4 levels, so 24-1 = 16-1 = 15. The maximum size of the array needed to represent this binary tree is 15.

2. BST = [\0, 3, \0, 8, 6, \0, 3, 6, -1, \0, 8, \0, \0, 14, 10, \0]

\0 = Null Value

-1 = root node

Explanation:

Theory: The name of the parent is written where the index is equal to the child.

e.g. If 9 and 11 are children of 10; then 10 is written at index values 9 and 11 of the array.

  1. An array of size 2n-1 is drawn; in this case 15
  2. 8 is the root node, so -1 is written at array index 8.
  3. 3 and 10 are chidren of 8; so 8 is written at indexes 3 and 10 of the array.
  4. 1 and 6 are children of 3; so 3 is written at indexes 1 and 6 of the array.
  5. 4 and 7 are chidren of 6; so 6 is written at indexes 4 and 7 of the array.
  6. 14 is the child of 10; so 10 is written at index 14 of the array.
  7. 13 is the child of 14; so 14 is written at index 13 of the array.
  8. write '\0' or any other value at the remaining positions to represent that they don't exist.

How to convert array to Binary Search Tree:

  1. Locate -1. The index value of -1 is the value root node.
  2. Locate the value of the root node; the indexes where the value of root node is present are the children of the root node. (e.g. 8 is the root node and 8 is present at array indexes 3 and 4; means that 3 and 4 are children of 8. 3 is the left child and 4 is the right child)
  3. The smaller value is the left child and the larger value is the right child.
  4. Repeat steps 2 and 3 until all nodes are represented.

3. InOrder output of the BST is 1,3,4,6,7,8,10,13,14

Steps:

  1. The order followed in InOrder is Left->Root->Right
  2. First, go to the leftmost subtree and write down Left->Root->Right.
  3. Our leftmost subtree does not have any children. so, we write 1.
  4. Then we write the root of that sub-tree 3.
  5. Then the right node of that sub-tree is a sub-sub-tree; so we follow Left->Root->Right for that too and write down 4(left), 6(root), 7(right).
  6. The left part is complete; so now we write down the original root node 8.
  7. Then wee traverse to the right part of the tree.
  8. We go to the leftmost node in the right subtree(because this is a binary search tree and the order of the nodes need to be low-high)
  9. The leftmost node is 10(the root of right sub-tree); so we write it down.
  10. Then the right part of this sub-tree is another sub-sub-tree; so we follow Left->Root->Right for this too.
  11. Then we write 13(left) and 14(root) of the right sub-tree.
  12. since we have written down all the nodes; we now stop.

Right Sub the Root Right 13 ,14 (1,3,4,6,73 [8] 20 a 3 ay 1,3, 4, 6, 7, 8, 10, 13, 14 In order final Output

Add a comment
Know the answer?
Add Answer to:
Consider the given binary search tree (BST). 1. What is the maximum size of the array...
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
  • e Construct a binary search tree (BST) using the following array elements 60,63,15, 81,30,74,35,38,93,41,53,45,86,90). e For...

    e Construct a binary search tree (BST) using the following array elements 60,63,15, 81,30,74,35,38,93,41,53,45,86,90). e For the above BST, show the use of post-order traversal to delete node 53. . For the above BST, show the path to search the node 86 and to insert a node with key

  • help 2. Do the following problems: Create a binary search tree (BST), with the following words...

    help 2. Do the following problems: Create a binary search tree (BST), with the following words inserted: Int, Char, Return, Break, Float, While, Short, Sort, Double, For, Continue. a. b. Insert the following words into the BST built in (a): Tree, Table, Binary, Network, Visit, Seekk, Traversal c. Where is the minimum key value in a BST? (Give a concrete example) d. Where is the maximum key value in a BST? (Give a concrete example) e. How many comparisons are...

  • Use the Binary Search Tree (BST) insertion algorithm to insert 0078 into the BST below. List...

    Use the Binary Search Tree (BST) insertion algorithm to insert 0078 into the BST below. List the nodes of the resulting tree in pre-order traversal order separated by one blank character. For example, the tree below can be described in the above format as: 75 53 24 57 84 77 76 82 92 0075 0053 0084 0024 0057 0077 OON 0076 0082

  • Use the Binary Search Tree (BST) deletion algorithm to delete 0075 from the BST below. List...

    Use the Binary Search Tree (BST) deletion algorithm to delete 0075 from the BST below. List the nodes of the resulting tree in pre-order traversal order separated by one blank character. For example, the tree below can be described in the above format as: 75 53 24 57 84 77 76 82 92 0075 0053 0034 0024 0057 0077 0092 0078 0082

  • Given the following hexadecimal number DEAB 16. what is its binary and decimal equivalent? Binary: Decimal...

    Given the following hexadecimal number DEAB 16. what is its binary and decimal equivalent? Binary: Decimal HTML Editor BIVA - A - Ix 5 3 3 3 3 x x : E - O N V celom V 11 12pt - Paragraph O words

  • A binary search tree(BST) relies on the property that keys that are less than the parent...

    A binary search tree(BST) relies on the property that keys that are less than the parent are found in the left subtree, and keys that are greater than the parent are found in the right subtree. Implement a BST with the following basic components 1. Create a BST for a list of data (= 10, 5, 8, 2, 4, 12, 11, 4, 9, 15)[ use insert(value) function\ 2. Print the values in inorder, preorder, and post order Please code in...

  • 1. Construct a Binary Search Tree 50 Write code to implement a BST. Implement an add) method and ...

    C++ program 1. Construct a Binary Search Tree 50 Write code to implement a BST. Implement an add) method and a remove) method. Use the following input to construct a BST: 50,20,75,98,80,31,150, 39, 23,11,77 20 75 31 98 0 (150 Hint on removing If the node to be removed is: a leaf node a node with a left child only a node with a right child only a node with both children Then take this action replace with null replace...

  • Question 23 Not yet graded /0 pts Given a Binary Search Tree that is populated with...

    Question 23 Not yet graded /0 pts Given a Binary Search Tree that is populated with numerical data, write an algorithm that will determine the sum, average, least and greatest of the values maintained in the tree. Express your algorithm in Java-like pseudodode. You may use any of the operations supported by the Binary Search Tree implementation used for Programming Project #5. Your solution must be developed at the application level. Your Answer For the next two questions you must...

  • C++ ONLY Threaded Binary Search Tree Since a binary search tree with N nodes has N...

    C++ ONLY Threaded Binary Search Tree Since a binary search tree with N nodes has N + 1 NULL pointers, half the space allocated in a binary search tree for pointer information is wasted. Suppose that if a node has a NULL left child, we make its left child pointer link to its inorder predecessor, and if a node has a NULL right child, we make its right child pointer link to its inorder successor. This is known as a...

  • Write a C++ program that implements a binary search tree (BST) to manage a number of...

    Write a C++ program that implements a binary search tree (BST) to manage a number of integer items with different priorities. In order to do so, you will need to maintain a queue as an item in the tree. Each queue item is an integer. All items in a given queue will have the same priority. As a new item with a user-specified priority comes in, it should be enqueued in the queue with items of that priority. A new...

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