Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are we trying to keep trees balanced

Tags:

algorithm

tree

I see many questions that are talking about balanced tree.

For instance R-Tree are better than KD-Tree as they are balanced.

What is the advantage of using a balanced tree over a non-balanced tree?

like image 782
Dejell Avatar asked Feb 01 '26 21:02

Dejell


1 Answers

Searching this tree

O
 \
  O
   \
    O
     \
      O
       \
        O
         \
          O
           \
            O

Is going to take Θ(N) time. Searching this tree

     O
   /   \
  O     O
 / \   / \
O   O O   O

Is going to take Θ(logN) time. Since search time is proportional to the height of the tree.

like image 146
Imre Kerr Avatar answered Feb 03 '26 16:02

Imre Kerr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!