Question

3 AVL Trees Assume the following notation/operations on AVL trees. An empty AVL tree is denoted E. A non-empty AVL tree T has
[3 marks] Describe an alternative version of the RANGECOUNT(T, lo, hi) function that runs in O(log n) time. . You do not have

just need to answer the second question
3 AVL Trees Assume the following notation/operations on AVL trees. An empty AVL tree is denoted E. A non-empty AVL tree T has
3 AVL Trees Assume the following notation/operations on AVL trees. An empty AVL tree is denoted E. A non-empty AVL tree T has three attributes: . The key T.key is the root node's key. The left child T.left is T's left subtree, which is an AVL tree (possibly E). The right child T.right is T's right subtree, which is an AVL tree (possibly E)
[3 marks] Describe an alternative version of the RANGECOUNT(T, lo, hi) function that runs in O(log n) time. . You do not have to write an algorithm in pseudo code to answer part (b) of this ques tion. We are expecting that you write a short paragraph or a short list of bullet points describing the important steps of the algorithm In your answer, you may augment the AVL tree notation/operations listed above. For example, you may include additional node attributes such as T.bal indicating the balance factor of the AVL tree, or T.sum indicating the sum of all key values in the tree with root T, and possibly even T.parent that points to the parent node of current root, T. If uetto do w pleaeat you ioan
3 AVL Trees Assume the following notation/operations on AVL trees. An empty AVL tree is denoted E. A non-empty AVL tree T has three attributes: . The key T.key is the root node's key. The left child T.left is T's left subtree, which is an AVL tree (possibly E). . The right child T.right is T's right subtree, which is an AVL tree (possibly E) (a) 5 marks] Write a function RANGECoUNT(T, lo, hi) to count the number of nodes in an AVL tree with root T, where the key value is in the range lo key S hi. Your algorithm should run in O(n) time, assuming that n is the number of nodes in the AVL tree, T. (b) 13 marksl Describe an alternative version of the RANGECoUNT (T, lo, hi) function that runs in O(log n) time . You do not have to write an algorithm in pseudo code to answer part (b) of this ques- tion. We are expecting that you write a short paragraph or a short list of bullet points describing the important steps of the algorithm . In your answer, you may augment the AVL tree notation/operations listed above. For example, you may include additional node attributes such as T.bal indicating the balance factor of the AVL tree, or T.sum indicating the sum of all key values in the tree with root T, and possibly even T.parent that points to the parent node of current root, T.I you elect to do so, please make sure that you explain your representation.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

(2)AT each node of your AVL Tree, also keep count of the number of values in the tree that are lesser than its value .

Now, first find the node containing the value lo(or node with smallest value greater than lo). Get the count of values lesser than lo(or node with smallest value greater than lo) which has been stored at this node(say it n1).
This step is Log(n).

Now find the node containing the value hi(or node with larger value lesser than hi). Get the count of values lesser than hi(or node with larger value lesser than hi) which are stored in this node(say it n2). This step is also Log(n).

Print value n2-n1(will give number of node lies in[lo,hi]). Total complexity of this search is 2*Log(n) = O(Log(n)).

Add a comment
Know the answer?
Add Answer to:
just need to answer the second question 3 AVL Trees Assume the following notation/operations on AVL trees....
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
  • Assume the following notation/operations on AVL trees. An empty AVL tree is denoted E. A non-empty AVL tree T has three...

    Assume the following notation/operations on AVL trees. An empty AVL tree is denoted E. A non-empty AVL tree T has three attributes The key T.key is the root node's key. The left child T.left is Ts left subtree, which is an AVL tree (possibly E). The right child T.right is T's right subtree, which is an AVL tree (possibly E). (a) 5 marsl Write a function RANGECOUNT(T, lo, hi) to count the number of nodes in an AVL tree with...

  • Assume the following notation/operations on AVL trees. An empty AVL tree is denoted E. A non-empty AVL tree T has three...

    Assume the following notation/operations on AVL trees. An empty AVL tree is denoted E. A non-empty AVL tree T has three attributes: • The key T.key is the root node’s key. • The left child T.left is T’s left subtree, which is an AVL tree (possibly E). • The right child T.right is T’s right subtree, which is an AVL tree (possibly E). (a) [5 marks] Write a function RangeCount(T, lo, hi) to count the number of nodes in an...

  • 3. [5 marks] Suppose T is a binary tree that stores an integer key value in...

    3. [5 marks] Suppose T is a binary tree that stores an integer key value in each node. Assume the following notation/operations on a binary tree. » the key T.key is the root node's integer key value . the left child T.left is T's left subtree, which is possibly an empty tree (or null) the right child T.right is T's right subtree, which is possibly an empty tree (or null) (a) Write an efficient algorithm FINDMAxPrODuCT(T) in pseudocode that returns...

  • The first and second picture are the definition of 2-3 tree,3rd and 4th are the pre-condition...

    The first and second picture are the definition of 2-3 tree,3rd and 4th are the pre-condition and post-condition. Please use these question to solve problem 8,the last photo. 2-3 Trees: Definition Suppose that E is an ordered type, that is, a nonempty set of values that have a total order. A 2-3-tree, for type E, is a finite rooted tree T (like a binary search tree or a red-black tree) that satisfies the following 2-3 Tree Properties: (a) Every leaf...

  • Need help in the below question. Answer in java Start with the tree.java program (Listing 8.1)...

    Need help in the below question. Answer in java Start with the tree.java program (Listing 8.1) and modify it to create a binary tree from a string of letters (like A, B, and so on) entered by the user. Each letter will be displayed in its own node. Construct the tree so that all the nodes that contain letters are leaves. Parent nodes can contain some non-letter symbol like +. Make sure that every parent node has exactly two children....

  • I need help with this code, I'm stuck on it, please remember step 4, I'm very...

    I need help with this code, I'm stuck on it, please remember step 4, I'm very much stuck on that part. It says something about putting how many times it appears Assignment #1: Sorting with Binary Search Tree Through this programming assignment, the students will learn to do the following: Know how to process command line arguments. 1 Perform basic file I/O. 2. Use structs, pointers, and strings. Use dynamic memory. 3. 4. This assignment asks you to sort the...

  • JAVA 3 PLEASE ANSWER AS MANY QUESTIONS AS POSSIBLE! ONLY 2 QUESTIONS LEFT THIS MONTH!!! Question...

    JAVA 3 PLEASE ANSWER AS MANY QUESTIONS AS POSSIBLE! ONLY 2 QUESTIONS LEFT THIS MONTH!!! Question 12 pts Which is a valid constructor for Thread? Thread ( Runnable r, int priority ); Thread ( Runnable r, String name ); Thread ( int priority ); Thread ( Runnable r, ThreadGroup g ); Flag this Question Question 22 pts What method in the Thread class is responsible for pausing a thread for a specific amount of milliseconds? pause(). sleep(). hang(). kill(). Flag...

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