How to draw a B-Tree using Dot

B-Trees are a really cool data structure. Basically, B-Trees are a special form of search trees, where a node contains multiple keys. A B-Tree has the following properties (where g is a parameter that has to be chosen):

Recently, I needed to draw B-Trees for a presentation. I have often used the Dot tool from the GraphViz package to draw graphs and trees. Unfortunately, Dot does not support drawing B-Trees directly. After some googling and some experiments, however, I found a solution which produces pretty neat results:

digraph {
    graph [margin=0, splines=line];
    edge [penwidth=2];
    node [shape = record, margin=0.03,1.2, penwidth=2, style=filled, fillcolor=white];

    node0[label = "<f0> &bull; | &nbsp;2&nbsp; | <f1> &bull; | &nbsp;6&nbsp; | <f2> &bull; | &nbsp;15&nbsp; | <f3> &bull;"];
    node1[label = "<f0> &bull; | &nbsp;0&nbsp; | <f1> &bull; | &nbsp;1&nbsp; | <f2> &bull;"];
    node2[label = "<f0> &bull; | &nbsp;3&nbsp; | <f1> &bull; | &nbsp;4&nbsp; | <f2> &bull;"];
    node3[label = "<f0> &bull; | &nbsp;7&nbsp; | <f1> &bull; | &nbsp;8&nbsp; | <f2> &bull; | &nbsp;9&nbsp; | <f3> &bull; | &nbsp;12&nbsp; | <f4> &bull;"];
    node4[label = "<f0> &bull; | &nbsp;16&nbsp; | <f1> &bull; | &nbsp;17&nbsp; | <f2> &bull;"];

    node0:f0 -> node1;
    node0:f1 -> node2;
    node0:f2 -> node3;
    node0:f3 -> node4;
}

The code shown above produces the following output:

I thinks this looks preety good and the cool thing is that you can generate the Dot description automatically if you have a working implementation of a B-Tree.