Question

Looking for some help, i'm trying to understand Good and Bad BSTs a little better. What...

Looking for some help, i'm trying to understand Good and Bad BSTs a little better.

What are some examples of GOOD (i.e., nearly balanced) BST's. and then another example of BAD BST's.

For example, {1, 2, 3, 4, 5, 6, 7} = bad BST

while {4, 2, 6, 1, 3, 5, 7} = good BST.

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

For understanding good/bad BST, you need to understand the purpose of existence of BST

In BST every node van have atmost 2 child nodes and also nodes are placed such that smaller values are placed to its left and larger values to right.

On implementing a balanced binary search tree, the cost of insertion, deletion and searching is O(logN) where N is the number of nodes in the tree So the benefit really is that lookups can be done in logarithmic time which matters a lot when N is large.

For N nodes if the height of the tree is O(log N) and every operation described above can be performed in O(log N) then tree is considered to be good BST as it is accomplishing the task for which it is designed.

Disadvantages of Binary Search Trees -

The shape of the tree depends on the order of insertions, and it can be degenerated.When inserting or searching for an element, the key of each visited node has to be compared with the key of the element to be inserted/found.
Keys may be long and the run time may increase much.Trees thus formed are bad BST

Just consider the trees for the given keys for better understanding -

Bad BST -

Good BST -

Say you want to search whether 7(key) is present in the tree or not.In bad BST, you need to compare the key(7) to be searched with 1,2,3,4,5,6 and then finally 7 will be found That is you need to make 7 comparisons

Say we have N elements arranged in the same form then in worst case N comparisons are made Hence time complexity of searching is O(N) and similarly another operations like insert and delete will also require O(N) in this case Hence time complexity is same as that of linear search/insert/delete and that's why it is good BST

Now in good BST you will compare key(7) with 4,6 and 7 that is you need to make 3 comparisons

Say we have N elements arranged in the same form then in worst caseO(log N) comparisons are made Hence time complexity of searching is O(log N) and similarly another operations like insert and delete will also require O(log N) in this case Hence time complexity is reduced and that's why it is good BST

Hope i have answered your question satisfactorily.Leave doubts in comment section if any.In case the image is not clear, tell me through comments and I will post a better image in terms of both quality and writing.

Add a comment
Know the answer?
Add Answer to:
Looking for some help, i'm trying to understand Good and Bad BSTs a little better. What...
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
  • Please give little explanation, I'm trying to understand why. 2. List appropriate Worst Case Big O...

    Please give little explanation, I'm trying to understand why. 2. List appropriate Worst Case Big O Notation under the different algorithms or data structure operations. O(1) O(n) O(n ^ 2) O(log n) A. Directly Accessing value in a 2-dimensional by [row][column] B. Selection Sort then Binary Search on a 1,000,000 element array C. Binary Search D. Highest element algorithm for 10,000 element array. E. Traversal of 6 character string O(n) 3. Give examples of Implicit declarations for Python and C++....

  • I'm trying to understand how to do the problem. I'm not just looking for an answer....

    I'm trying to understand how to do the problem. I'm not just looking for an answer. Please show the formulas used to solve the problem. If you can, please also explain why we are using that formula. Thank you. 8. Valuing Callable Bonds Assets, Inc., plans to issue $5 million of bonds with a coupon rate of 7 percent, a par value of $1,000, semiannual coupons, and 30 years to maturity. The current market interest rate on these bonds is...

  • Hi, I'm trying to understand how oxygen and nitrogen, when in a molecule with 4 bonds...

    Hi, I'm trying to understand how oxygen and nitrogen, when in a molecule with 4 bonds to them, for example, NH4+ and H3O+ bear a POSITIVE charge when they gain that additional proton? I think I understand that nitrogen's FC would be calculated 5-0-4= +1, but now, I'm having the same problem with nitrogen because wouldn't the formal charge be calculated 6-3-3=0?? Do I have the formula wrong? What is GOING ON!!?

  • I'm a little crunched for time and need some help with these first two questions. Thank...

    I'm a little crunched for time and need some help with these first two questions. Thank you! Question 1.) Write a Java program that reads in sequence of integers from the user until user enters a negative number and stores them in an Integer ArrayList. Once read, display a bar chart based on the values stored in the ArrayList. For example, if the user inputs 2, 5, 3, 8, 4, and -1, then your program should display the bar chart...

  • I need help i am very good at looking at examples to understand this problem Contents...

    I need help i am very good at looking at examples to understand this problem Contents should share 3 appropriate and interesting facts about yourself with the audience. For example, what you have done or your work experience; what you are doing now or your academic training you are pursuing at School; and, a future personal or career goal

  • Language : C Im more trying to understand this, an example would help which is why...

    Language : C Im more trying to understand this, an example would help which is why i'm posting this question Write script that after coordinates are inputted, prints quadrant or line that the point is on. Should have function that returns a character indicating the quadrant or the line. Probable Return values: X (X-axis) Y (Y-axis) 1 (1st quadrant) 2 (2nd quadrant) 3 (3rd quadrant) 4 (4th quadrant) The printing of the quadrant should be handled inside the main function....

  • 1. Eamon says, "Knowing is good, but knowing everything is better." Give one example 2. One...

    1. Eamon says, "Knowing is good, but knowing everything is better." Give one example 2. One of the fundamental principles of The Circle is "Sharing is Caring." Give one 3. In your opinion, what would be the BEST part of working for The Circle. Use details 4. The marble sized, wireless, nearly invisible cameras The Circle creates, what Eamon from your own life that proves this statement is NOT true. specific example from your own life that proves this statement...

  • I am doing an assignment for a class and need a little help trying to understand...

    I am doing an assignment for a class and need a little help trying to understand how to get started on this assignment. This is needing to be program in python and any help is greatly appreciated. Distributed Computing with XML-RPC Description Common tasks in distributed computing applications often require the ability of one computer to be able to remotely invoke a procedure on another computer in the distributed system. This assignment introduces this idea further using XML-RPC and Python....

  • The following are questions from a study guide, could I get some good examples of c++...

    The following are questions from a study guide, could I get some good examples of c++ code with comments for a better understanding, thanks! 2.Be prepared to implement a stack, queue, or priority queue using a linked list (singly or doubly linked). 3.Be prepared to implement a “weird” method that you’ve never heard of before to prove you truly understand what you are doing.  Here is an example: a.Implement ‘void decimate()’ which deletes every 10th item from the list: https://en.wikipedia.org/wiki/Decimation_(Roman_army) Recurison:...

  • I'm trying to solve question 4c and 5 I'm a little lost on how to do...

    I'm trying to solve question 4c and 5 I'm a little lost on how to do it Dozier Company produced and sold 1000 units during its first month of operations. It reported the following costs and expenses for the month: $ 83, Direct materials Direct labor Variable manufacturing overhead Fixed manufacturing overhead Total manufacturing overhead Variable selling expense Fixed selline expense Total selling expense Variable inistrative expense Fixed adninistrative expense Total administrative expense $ 20, 32,20 $32.880 $14, see 23,60e...

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