walkccc / CLRS

📚 Solutions to Introduction to Algorithms Third Edition
https://walkccc.me/CLRS
MIT License
4.66k stars 1.26k forks source link

18.1-3 root node max #315

Open nkrusch opened 4 years ago

nkrusch commented 4 years ago

Current version 18.1-3 solution shows tree with a root node that contains 5 keys.

From page 489:

Every node may contain at most 2t - 1 keys. [...] We say that a node is full if it contains exactly 2t - 1 keys.

Given t=2 node is full when it has 2t - 1 = 4 - 1 = 3 keys.

The solution seems to suggest the this max does not apply to the root node. However there is no mention of root being exempt regarding this upper limit. (The min limit of keys in 5.a. explicitly says "other than the root" which makes me think if the max did not apply to the root node, it would be stated as well).

There are other solutions to this question circling around the internet but they have t = 3 which changes the max and makes 5 keys at the root a valid tree. I am looking at 3rd ed. of this book from 2009 that has t = 2.

yjian012 commented 3 years ago

I think you're right, otherwise Exercise 18.1-4 would be unbounded because the root itself can keep unlimited number of keys.

Also, I suppose these are all legal B-trees of degree 2?:

     2
  1     345

         4
  123     5

    2 4
  1  3  5

besides the one in the solution

      3
  12  45

so there are 4 of them?