Question

In: Computer Science

Prerequisite Knowledge Understand binary search tree structure Understand binary search tree operations Understand binary search tree...

Prerequisite Knowledge

  • Understand binary search tree structure
  • Understand binary search tree operations
  • Understand binary search tree worst case and best case time.

Learning Outcomes

  • Describe AVL tree structure
  • Trace and implement AVL tree operations
  • Explain and prove AVL tree performance

Solutions

Expert Solution

A

/ \

B C

Any tree structure for which every node has at max 2 child nodes is called a binary tree. For instance, the one above.

However, if the binary tree is such that for any node the left sbi tree holds values that are lower than or equal to itself while the right subtree holds higher values only, it is called a binary search tree (BST).

In the example above, the tree would be a BST if the following were true,

B <= A < C

So, the following would be a BST

7

/ \

3 11

/ \ / \

1 5 9 13

Operations and runtime -

Imagine you were to perform a Search operation (say for number 9 above), you would do the following -

1. Starting from the root node (e.g., 7 above)

2. Check if node = search value

3. If true return true and end search

4. Else, if search value is greater than current node, select right child as new node and repeat from step 2

5. Else, if search value is less than current node, sel2ct left child as new node and repeat from step 2

6. If all nodes are visited and you still don't find the node return false and end search.

What do you observe! At every step the remaining number of steps is halved, as you only traverse towards a subtree.

However, imagine if the tree were skewed like this,

13

/ \

1

/ \

3

/ \

5

/ \

11

/ \

9

Would you still have half iterations? Of course not.

I hope this gives you a fair idea. Also, log (n) and n are pretty different ?


Related Solutions

Lab 5: Binary Search Tree Implement operations for a Binary Search Tree class starting from the...
Lab 5: Binary Search Tree Implement operations for a Binary Search Tree class starting from the template provided under the PolyLearn assignment, using the class TreeNode that is also provided. You may (should) implement helper methods that make your code easier to write, read, and understand. You will also need to write test cases of your own as you develop the methods. You may use iterative and/or recursive functions in your implementation. The following starter files are available . •...
​Define a tree. Distinguish between a tree and a binary tree. Distinguish between a binary tree and a binary search tree.
Define a tree. Distinguish between a tree and a binary tree. Distinguish between a binary tree and a binary search tree.
Beginning with an empty binary search tree, what binary search tree is formed when you insert...
Beginning with an empty binary search tree, what binary search tree is formed when you insert the following values in the given order – consider there alphabetical position for comparison. a. W, T, N, J, E, B, A b. W, T, N, A, B, E, J c. A, B, W, J, N, T, E d. B, T, E, A, N, W, J Alphabetical positions: A-1, B-2, E-5, J-10, N-14,T-20,W-23
In MobaXterm, with the use of the binary search tree. Implement four operations of insert, in-order...
In MobaXterm, with the use of the binary search tree. Implement four operations of insert, in-order traversal, preorder traversal, and find. Please separate the code in the four parts and explain in detail what is happening. Also, if you can please basic C language. If not, then I understand. Thank you for your time. The test cases are 'm', 'd', 'g', 'r', 'p', 'b', and 'x'. Output: Enter choice (lower case is also acceptable) --- (I)nsert, (F)ind, (Q)uit: i Enter...
/** * This class implements a basic Binary Search Tree that supports insert and get operations....
/** * This class implements a basic Binary Search Tree that supports insert and get operations. In * addition, the implementation supports traversing the tree in pre-, post-, and in-order. Each node * of the tree stores a key, value pair. * * @param <K> The key type for this tree. Instances of this type are used to look up key, value * pairs in the tree. * @param <V> The value type for this tree. An instance of this...
Binary Tree Create a binary search tree using the given numbers in the order they’re presented....
Binary Tree Create a binary search tree using the given numbers in the order they’re presented. State if the resulting tree is FULL and/or BALANCED. 37, 20, 18, 56, 40, 42, 12, 5, 6, 77, 20, 54
Code using C++ A binary search tree is a data structure designed for efficient item insertion,...
Code using C++ A binary search tree is a data structure designed for efficient item insertion, deletion, and retrieval. These 3 operations share an average run time complexity of O(log(n)). Such time complexities are guaranteed whenever you are working with a balanced binary search tree. However, if you have a tree that begins leaning heavily to either its left or right side, then you can expect the performances of the insertion, deletion, and retrieval operations to degrade. As an example,...
Show how to augment the ordinary Binary Search Tree (BST) data structure so that it supports...
Show how to augment the ordinary Binary Search Tree (BST) data structure so that it supports an efficient procedure which, on input (x, k) where x is the root of a BST and k an integer, output the k-th smallest number store in the BST. Let n denote the total number of elements stored in the BST, what is the running time of your efficient procedure? How does your modification of the BST data structure affect the performance of other...
Compare and Contrast Hash Map to Binary Search Tree. Memory, Time Efficiency for Operations for Retrieving...
Compare and Contrast Hash Map to Binary Search Tree. Memory, Time Efficiency for Operations for Retrieving Singular Values, Maintaining relationships between data. Please be sure to use your own words.
PLEASE READ CAREFULY AND EXPLAIN YOUR WORK: (JavaScript) only Search the Tree: A binary search tree...
PLEASE READ CAREFULY AND EXPLAIN YOUR WORK: (JavaScript) only Search the Tree: A binary search tree is a data structure that consists of JavaScript objects called "nodes". A tree always has a root node which holds its own integer value property and can have up to two child nodes (or leaf nodes), a left and right property. A leaf node holds a value attribute and, likewise, a left and right attribute each potentially pointing to another node in the binary...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT