Strawberry
Strawberry

Reputation: 67938

How do I implement a 2-3-4 tree?

Deleted old question and wrote a better one. So I had no idea of how am I supposed to do this, so I thought I was supposed to use a linked list, but it seemed like there would be limitations. I noticed a few packages related to trees, such as these.

That also didn't seem to fit what I wanted to do, then I started thinking of creating a class for nodes with methods such as IsThere2Nodes or like IsParentOf(x), etc. I'm being a little vague, but I just want to know if I am I approaching this in the right direction.

Upvotes: 0

Views: 4633

Answers (1)

Ted Hopp
Ted Hopp

Reputation: 234847

You definitely should be creating a class to represent a node of the tree.

To get going, consider the definition of a 2-3-4 tree. A node needs three slots for data and four slots for child pointers. It also needs some sort of indication of how many of these are in use at any particular time. That's the data. Then you need operations on nodes to support the operations on the tree. Analyze how to do each tree operation in terms of what you would do to the nodes and you should be able to figure it all out.

Upvotes: 5

Related Questions