0

In order to understand B-tree-algorithms I'm trying to write such in C style pseudocode. I suppose a B-tree algorithm is like a linked list but with an array of pointers and an integer that with the value of the length of the array. Am I right? Below is pseudocode for a linked list and my understanding of a B-tree. The problem I got with my B-tree-algorithm is that it only works for the first generation of children. Does anyone have any idea what is wrong?

Thanks in advance for help!

Linked list:


    struct node
        datatypes for content...
        struct node *next;

    struct node* head = NULL
    struct node* p = NULL
    struct node* n = NULL

    head = malloc(sizeof *head)
    head→next = malloc(sizeof(struct node))
    p = head→next
    p→content = malloc(sizeof string)
    while (...)
        input content
        p→next = malloc(sizeof(struct node))
        n = p→next
        n→content = malloc(sizeof content)
        p=n

B-tree:


    struct node
        datatypes for content...
        int children
        struct node *next [children]
    struct node* head = NULL
    struct node* p = NULL
    struct node* n = NULL
    head = malloc(sizeof *head);
    int children = input a value
    for i in length of children
        head→next[i] = malloc(sizeof(struct node));
        head→next = malloc(sizeof(struct node));
        p = head→next;
        p→content = malloc(sizeof content);
    while (...)
        input content
        p→next = malloc(sizeof(struct node))
        n = p→next;
        n→children = input a value
        for i in length of children
               p→next[i] = malloc(sizeof(struct node))
               p→content = malloc(sizeof content)
               p=n

  • 1
    B-trees can have multiple levels. The basic idea is that, when a node becomes too full, it is split, and its contents are redistributed, to keep the tree balanced (with nodes that are not too full and not too empty). When the topmost (root) node becomes too full, the tree grows a new level. – Eduardo Apr 29 '16 at 06:14
  • 1
    The important part, which @Eduardo did not write is that when the node is split, the superfluous item from it is passed back to *a higher level* of the tree — so if the root node is split, the new node appears *above* it. This specific tree grows in the root direction, unlike most tree structures which grow from the root to leaves. – CiaPan Apr 29 '16 at 06:46

0 Answers0