Question

In: Computer Science

Some questions about Binary Tree's What a binary search tree is and what its advantages/disadvantages are?...

Some questions about Binary Tree's

  1. What a binary search tree is and what its advantages/disadvantages are?
  2. What trees and binary trees are?
  3. How data is inserted into a binary tree?
  4. What full and complete binary trees look like?
  5. How to perform pre, in, and post-order traversals of a tree?

Solutions

Expert Solution

1.BINARY SEARCH TREE:

A binary search tree is a binary tree which is either empty or satisfies the following rules:

i)The value of key in the left child or left sub-tree is less than the value of root.

ii) The value of key in the right child or right sub-tree is more than or equal to the value of root.

iii)All the sub-trees of the left and right children, follow the above two rules.

ADVANTAGES:

i)Binary Search Tree is fast in insertion and deletion etc. when balanced.

ii) Very efficient and its code is easier than other data structures.

iii) Stores keys in the nodes in a way that searching, insertion and deletion can be done efficiently.

DISADVANTAGES:

i)The shape of the binary search tree totally depends on the order of insertions, and it can be degenerated.

ii)When inserting or searching for an element in binary search tree, the key of each visited node has to be compared with the key of the element to be inserted or found, i.e., it takes a long time to search an element in a binary.

2. TREE:

A tree is a non-primitive, non-linear data structure in which items are arranged in a sorted sequence. It is used to represent hierarchical relationship existing among several data items.

BINARY TREE:

A binary tree is a finite set of data items which is either empty or consists of a single item called the root and two disjoint binary trees called the left sub-tree and right sub-tree.

In a binary tree, the maximum degree of any node is atmost 2.

3.

For insertion in binary tree you will have to follow the given conditions:

· If a node in the binary tree does not have its left child, then insert the given node (the one that we have to insert) as its left child.

· If a node in the binary tree does not have its right child then insert the given node as its right child.

· If the above-given conditions do not apply then search for the node which does not have a child at all and insert the given node there.

4.

A full binary tree is a tree in which every node other than the leaves has two children.

A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.

5.

PREORDER TRAVERSAL:

The preorder traversal of non-empty binary tree is defined as follows:

i)Visit the root node.

ii)traverse the left sub-tree in preorder.

iii)traverse the right sub-tree in preorder.

INORDER TRAVERSAL:

The inorder traversal of non-empty binary tree is defined as follows:

i)traverse the left sub-tree in inorder.

ii) Visit the root node.

iii) traverse the right sub-tree in inorder.

POSTORDER TRAVERSAL:

The postorder traversal of non-empty binary tree is defined as follows:

i)traverse the left sub-tree in postorder.

ii)traverse the right sub-tree in postorder.

iii)Visit the root node.


Related Solutions

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
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
​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.
What is a binary search tree or BST? Discuss its characteristics. What are other types of...
What is a binary search tree or BST? Discuss its characteristics. What are other types of binary trees as well?
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 . •...
What does the level of a binary search tree mean in relation to its searching efficiency?...
What does the level of a binary search tree mean in relation to its searching efficiency? In your response discuss what the maximum number of levels to implement a search tree with 100 nodes and what is the minimum number of levels for 100 nodes. In your response to other students discuss if you agree with the other student’s number of levels, how the number of levels was determined and the Big-O efficiency of the maximum and a minimum number...
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
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...
Write the binary tree representation for the Binary Search for also 17 elements and give the...
Write the binary tree representation for the Binary Search for also 17 elements and give the worst-case
I require some assistance with the following problem: Create a binary search tree for 6 randomly...
I require some assistance with the following problem: Create a binary search tree for 6 randomly chosen vegetables. - Carrots - Green beans - Cucumber - Corn - Peas - Spinach Thank you.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT