0% found this document useful (0 votes)
183 views4 pages

Multiway Trees

This document discusses multiway trees, which are tree structures allowing more than two branches per node, and introduces m-way search trees where each node can have up to m subtrees. It explains the properties of m-way trees, such as the arrangement of data entries and the relationship between subtrees, and outlines how to structure a node in an m-way tree. Additionally, it notes that binary search trees are a specific case of m-way trees with an order of 2.

Uploaded by

Irfan Ul Haq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
183 views4 pages

Multiway Trees

This document discusses multiway trees, which are tree structures allowing more than two branches per node, and introduces m-way search trees where each node can have up to m subtrees. It explains the properties of m-way trees, such as the arrangement of data entries and the relationship between subtrees, and outlines how to structure a node in an m-way tree. Additionally, it notes that binary search trees are a specific case of m-way trees with an order of 2.

Uploaded by

Irfan Ul Haq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Multiway Trees

In Chapter 6, we learned about the basic ideas of trees. We also covered three kinds of binary
trees: binary search trees (Chapter 7), AVL trees (Chapter 8), and heaps (Chapter 9). As binary
trees grow bigger, their height can increase a lot. For example, a tree with 1,000 items has a
height of at least 10, and a tree with 100,000 items has a height of at least 17. If the tree isn’t
balanced, its height can be even greater.

In this chapter, we’ll look at trees that can have more than two branches per node, but still follow
the main rules of binary search trees. Unlike binary trees, where each node holds just one item,
these trees (called multiway trees) can store several items in one node and connect to more
subtrees. These types of trees are useful in things like search engines, spell checkers, and file
systems.

M-Way Search Trees (Simplified)

An m-way tree is a type of search tree where each node can have up to m subtrees. The number
m is called the order of the tree. For a non-empty m-way tree, here are the main features:

1. Each node can have 0 to m subtrees.


2. If a node has k subtrees, it will contain k - 1 data entries.
3. In each subtree:
o The values in the first subtree are smaller than the first entry in the parent node.
o The values in other subtrees are greater than or equal to their parent entry.
4. The data entries in a node are arranged in increasing order: key1 ≤ key2 ≤ ... ≤ keyk.
5. All subtrees are also m-way trees.

Figure 10-1 shows an example of an m-way tree with an order of 4.

M-way Tree of Order 4


Explanation of Figure 10-1

Take a close look at Figure 10-1. It has a structure similar to a binary search tree:

1. Ordering in Subtrees:
o Subtrees to the left of an entry have keys that are less than the key of that entry.
o Subtrees to the right of an entry have keys that are greater than or equal to the
key of that entry.
o This is easiest to understand when looking at the first and last subtrees.
2. Middle Subtrees:
o For example, the second subtree contains keys that are greater than or equal to
k1 and less than k2.
o This subtree acts as the right subtree for k1 and the left subtree for k2.
o Whether a subtree is considered "left" or "right" depends on which node entry
you're focusing on.
3. Extra Subtree:
o Each node has one more subtree than it has entries.
o The first subtree in the node contains all keys that are smaller than the first entry.
4. Entry Count:
o Since nodes can have a variable number of entries, we need to track how many
entries each node currently holds.
o This is done using an entry count, though it is not shown in Figure 10-1.

Figure 10-2 provides an example of a four-way tree, showing how this structure works in
practice.

Four-way Tree

Coding the Structure of an M-Way Tree Node

To represent a node in an m-way tree, we first need to define how the entries are structured.
Here's what we need to consider:
1. Entries:
o Each node contains a variable number of entries, up to a maximum limit.
o Since the number of entries can vary, an array is a suitable way to store them.
2. Each Entry Contains:
o The key for the data (used to organize the tree).
o The data itself (or a pointer to the data if it’s stored somewhere else).
o A pointer to the right subtree connected to that entry.

Figure 10-3(a) visually represents this structure, showing how the key, data, and right subtree
pointer are organized within the entries of a node.

M-way Node Structure

M-Way Tree Node Structure

The structure of an m-way tree node includes the following components:

1. First Pointer:
o A pointer to the subtree that contains entries smaller than the key of the first
entry in the node.
2. Entry Count:
o A value that keeps track of how many entries are currently in the node.
3. Array of Entries:
o An array that holds the entries for the node.
o Each entry contains a key, the data (or a pointer to it), and a pointer to its right
subtree.
o The array has space for m - 1 entries, where m is the order of the tree.
Figure 10-3(b) shows this structure, combining the first pointer, entry count, and the array of
entries into a cohesive node representation.

A Final Note:

A binary search tree is simply a special case of an m-way tree with order 2. This means each
node in a binary search tree can have up to two subtrees and one key, following the same general
rules of an m-way tree.

B-trees…?

You might also like