Question

The INORDER traversal output of a binary tree is U,N,I,V,E,R,S,I,T,Y and the POSTORDER traversal output of the same tree is N,U,V,R,E,T,I,S,I,Y

 a. The INORDER traversal output of a binary tree is U,N,I,V,E,R,S,I,T,Y and the POSTORDER traversal output of the same tree is N,U,V,R,E,T,I,S,I,Y. Construct the tree and determine the output of the PREORDER traversal output.  

 b. One main difference between a binary search tree (BST) and an AVL (Adelson-Velski and Landis) tree is that an AVL tree has a balance condition, that is, for every node

 in the AVL tree, the height of the left and right subtrees differ by at most 1. Starting with an empty BST and AVL tree, insert elements into the two trees with the following keys:

 27, 32, 89, 45, 10, 63, 57, 17

 c. Based on what you have done for Question 1b, what is the big-O (worst case) complexity of the total time required to build a binary search tree (BST) consisting of n nodes? Explain your answer. Answer without explanation gains no mark. (Hint.

 A tricky question. The question asks for worst case complexity. Think properly.)

 d. Similarly, from what you have done for Question 1b, what is the big-o (worst case) complexity of the total time required to build an AVL tree consisting of n nodes? Explain your answer. Answer without explanation gains no mark. (Hint. The question asks for worst case complexity.)


3 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution:

(a) & (b):

Explanation:

(c)

Explanation:

=>Worst case time complexity of building BST(binary search tree) = O(n^2) where n is the number of elements to be inserted into the empty binary search tree.

Calculations:

=>Searching for a key takes time in worst case = O(n) as height of tree can be O(n)

=>After searching the key insertion takes time = O(1)

=>Total time for one key in worst case = O(n) + O(1)

=>Total time for one key in worst case = O(n)

=>Total time for n keys = n*O(n)

=>Total time for n keys = O(n^2)

(d)

Explanation:

=>Worst case time complexity of AVL tree insertion for n elements = O(nlogn)

Calculations:

=>Searching for a key takes time in worst case = O(logn) as height of tree can be O(logn)

=>After searching the key insertion takes time = O(1)

=>Total time for one key in worst case = O(logn) + O(1)

=>Total time for one key in worst case = O(logn)

=>Total time for n keys = n*O(logn)

=>Total time for n keys = O(nlogn)

Add a comment
Know the answer?
Add Answer to:
The INORDER traversal output of a binary tree is U,N,I,V,E,R,S,I,T,Y and the POSTORDER traversal output of the same tree is N,U,V,R,E,T,I,S,I,Y
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
  • I need help on question 12 please An inorder tree traversal of a binary search tree...

    I need help on question 12 please An inorder tree traversal of a binary search tree produces a listing of the tree nodes in alphabetical or numerical order. Construct a binary search tree for "To be or not to be, that is the question, " and then do an inorder traversal. Construct a binary search tree for "In the high and far off times the Elephant, O Best Beloved, had no trunk, " and then do an inorder traversal.

  • 1.    Consider the following function for an AVL tree with n nodes. void _removeLeftmost(struct Node *cur) {...

    1.    Consider the following function for an AVL tree with n nodes. void _removeLeftmost(struct Node *cur) { while(cur->left != 0) { cur = cur->left } free(cur); } What is the average case big-O complexity of _removeLeftmost()? a.    O(1) b.    O(log n) c.    O(n) d.    None of the above 2. Refer to _removeLeftmost() from Question 1. What is the worst case big-O complexity of _removeLeftmost() for a binary search tree (not necessarily an AVL tree) with n nodes? a.    O(1) b.    O(log n) c.    O(n) d.    None of the above

  • In regards to binary search tree, can you answer why a BST with N nodes has...

    In regards to binary search tree, can you answer why a BST with N nodes has at least log2N levels and at most N levels. so the runtime complexity is best case 0(logN) and worst case 0(N). Can you explain this with the following numbers in this order? 7,1,64,28,77

  • fill in the blank Binary Search Tree AVL Tree Red-Black Tree complexity O(log N), O(N) in...

    fill in the blank Binary Search Tree AVL Tree Red-Black Tree complexity O(log N), O(N) in the worst case O(log N) O(log N) Advantages - Increasing and decreasing order traversal is easy - Can be implemented - The complexity remains O(Log N) for a large number of input data. - Insertion and deletion operation is very efficient - The complexity remains O(Log N) for a large number of input data. Disadvantages - The complexity is O(N) in the worst case...

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

  • C++ Question 5 5 pts In a min-heap of N elements, if we want to find...

    C++ Question 5 5 pts In a min-heap of N elements, if we want to find the max element, we have to search all the leaves. What is the big-o running time of findMax? O(N^2) Oſlog N) O(N) OIN log N) Question 6 5 pts An AVL tree is a Binary Search Tree that has the following additional property for every node in the tree, the height of the left and right subtrees is the same none of the above...

  • using java to write,show me the output. please write some common. You CAN NOT use inbuild...

    using java to write,show me the output. please write some common. You CAN NOT use inbuild functions for Tree ADT operations. using code below to finsih public class Main {    public static void main(String[] args) {        BinaryTree tree = new BinaryTree(); tree.root = new Node(1); tree.root.left = new Node(2); tree.root.right = new Node(3); tree.root.left.left = new Node(4); tree.root.left.right = new Node(5); tree.root.right.left = new Node(6); tree.root.right.right = new Node(7); tree.root.left.left.left = new Node(8); tree.root.left.left .right= new Node(9);...

  • C++ Binary Search Tree question. I heed help with the level 2 question please, as level...

    C++ Binary Search Tree question. I heed help with the level 2 question please, as level 1 is already completed. I will rate the answer a 100% thumbs up. I really appreciate the help!. Thank you! searching.cpp #include <getopt.h> #include <iostream> #include <sstream> #include <stdlib.h> #include <unistd.h> using namespace std; // global variable for tree operations // use to control tree maintenance operations enum Mode { simple, randomised, avl } mode; // tree type // returns size of tree //...

  • C++ Binary Search Tree question. I heed help with the level 2 question please, as level...

    C++ Binary Search Tree question. I heed help with the level 2 question please, as level 1 is already completed. I will rate the answer a 100% thumbs up. I really appreciate the help!. Thank you! searching.cpp #include <getopt.h> #include <iostream> #include <sstream> #include <stdlib.h> #include <unistd.h> using namespace std; // global variable for tree operations // use to control tree maintenance operations enum Mode { simple, randomised, avl } mode; // tree type // returns size of tree //...

  • Java eclipse question. Given a binary search tree -------------M ---------G ---------N ------D----- H ---B----F How woul...

    Java eclipse question. Given a binary search tree -------------M ---------G ---------N ------D----- H ---B----F How would you find the farthest from the root and most right side of the node? So, in this case, farthest nodes are B and F with height of 4 But the most right side of the node is F Therefore answer is F. I have //Will call helper method. public T findRightmostLowest(){ int lv = height();//This is the maxium height of the tree(4 in this...

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