Question

Binary Search Tree Diagram: How do you draw the result of adding multiple elements to a...

Binary Search Tree Diagram:

How do you draw the result of adding multiple elements to a binary search tree? Also, how do you know which level a value appears at, which nodes are the ancestor of the value and how many children does a value have.

Thank you! I need help in understanding this.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
  1. First, we pass a value and create a new node
  2. Check if there is a root, if not, set this newly created node to the root node
  3. If there is a root node, we create a variable declared “current”, and set its value to the root node
  4. If the newly created node.value is smaller than the root node, we will move left
  5. We keep comparing this node.value to left nodes.
  6. If the value is small enough and we reach a point where there are no more left nodes, we place this item here.
  7. If the node.value is greater we repeat the same steps as above except we move along the right.
  8. We need the break statements because there is no count step to terminate the while loop
Add a comment
Know the answer?
Add Answer to:
Binary Search Tree Diagram: How do you draw the result of adding multiple elements to a...
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
  • Suppose a binary search tree has multiple nodes containing the same key value, k. Let node...

    Suppose a binary search tree has multiple nodes containing the same key value, k. Let node p be the lowest common ancestor of such nodes. Then, the key of p must be also k. If this is true, provide an argument. Otherwise, provide a counterexample.

  • 1 Binary Search Trees (25 points) Consider the binary tree as shown in Figure 1. 9...

    1 Binary Search Trees (25 points) Consider the binary tree as shown in Figure 1. 9 5 15 10 17 8 Figure 1: Binary Tree: The letter next to each node (e.g., a, b) denotes the tree node, and the number inside each node is the key. 1.1 Correctness (10 points) Is this binary tree a valid binary search tree? In other words, does it satisfy the binary search tree property? If not, which node(s) violates the binary search tree...

  • Beginning with an empty binary search tree, what binary search tree is formed when you add the following letters in the order given?

    Trees-related questionsBeginning with an empty binary search tree, what binary search tree is formed when you add the following letters in the order given? J, N, B, A, W, E, TRepresent the following binary tree with an array  What is the result of adding 3 and 4 to the 2-3 tree shown below?Why does a node in a red-black tree require less memory than a node in a 2-3-4 tree?Why can’t a Red-Black Tree have a black child node with exactly...

  • Q1: How many levels your binary search tree has (including level 0)? Is the binary search tree you created height balanc...

    Q1: How many levels your binary search tree has (including level 0)? Is the binary search tree you created height balanced? 2.1 Click the animations “Binary Search Tree”. Click “Insert” button to insert the following elements in the sequence, “50, 20, 30, 70, 90, 80, 40, 10, 5, 60, 85, 95”. http://algoanim.ide.sk/index.php?page=showanim&id=44 Q2: What is the insertion process of the binary search tree? The new identical element is inserted as left or right child of the existing same value? 2.3...

  • Q1: How many levels your binary search tree has (including level 0)? Is the binary search...

    Q1: How many levels your binary search tree has (including level 0)? Is the binary search tree you created height balanced? 2.1 Click the animations “Binary Search Tree”. Click “Insert” button to insert the following elements in the sequence, “50, 20, 30, 70, 90, 80, 40, 10, 5, 60, 85, 95”. http://algoanim.ide.sk/index.php?page=showanim&id=44 Q2: What is the insertion process of the binary search tree? The new identical element is inserted as left or right child of the existing same value? 2.3...

  • IN JAVA create a binary search tree gui where you can insert and remove nodes, also...

    IN JAVA create a binary search tree gui where you can insert and remove nodes, also move around the tree, thank you. The simpler the better.

  • I need question 9-10 answered. Thank you Question 1 iShow the resulting binary search tree if...

    I need question 9-10 answered. Thank you Question 1 iShow the resulting binary search tree if we are to insert following elements into the tree in given order, [34, 12, 23, 27,31,9,11,45, 20, 37. i) Show the resulting balanced binary search tree if we are to insert following sorted elements into the tree, [9,12,21, 23, 29, 31, 34, 45, 48, 52, 55] iii What is the pre-order traversal of the balanced binary search tree? v) What is the post-order traversal...

  • 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...

  • A collection of nodes is arranged as a binary search tree ordered on the field INFO which contain...

    A collection of nodes is arranged as a binary search tree ordered on the field INFO which contains distinct positive integers for each of the nodes. In addition to INFO, LLINK and RLINK, each node has three other fields CLASS SUCC and PRED CLASS is an information field containing a single letter that denotes the class to which the node belongs (there being up to 26 classes). The nodes in each class are arranged as a doubly-linked circular list with...

  • answer number 7 5. Draw the binary search tree that would result from inserting the following...

    answer number 7 5. Draw the binary search tree that would result from inserting the following numbers into an initially empty tree in the order given: 45, 37, 62, 67, 49, 51, 16, 8, 73, 71, 64, 65 6. Given the tree created in problem 5, draw the tree that would result if you deleted the 37 from the tree? 7. Given the tree created in problem 5, draw the tree that would result if you deleted the 62 from...

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