Book contents
- Frontmatter
- Contents
- Preface
- 1 Introduction to recursion
- 2 Recursion with linked-linear lists
- 3 Recursion with binary trees
- 4 Binary recursion without trees
- 5 Double recursion, mutual recursion, recursive calls
- 6 Recursion with n-ary trees and graphs
- 7 Simulating nested loops
- 8 The elimination of recursion
- Further reading and references
- Index of procedures
6 - Recursion with n-ary trees and graphs
Published online by Cambridge University Press: 05 February 2012
- Frontmatter
- Contents
- Preface
- 1 Introduction to recursion
- 2 Recursion with linked-linear lists
- 3 Recursion with binary trees
- 4 Binary recursion without trees
- 5 Double recursion, mutual recursion, recursive calls
- 6 Recursion with n-ary trees and graphs
- 7 Simulating nested loops
- 8 The elimination of recursion
- Further reading and references
- Index of procedures
Summary
In Chapter 2 we considered a very simple data structure, the linked-linear list; and in Chapter 3 we moved on to binary trees. In this chapter we look at two much more general structures.
Firstly we shall consider trees in which nodes may have more than two branches, and in which the number of branches may vary from node to node. For want of a better name we shall call them n-ary trees.
Secondly we shall consider even more general structures which arise when more than one branch leads into a node. These structures are called directed graphs. Clearly they are more general than n-ary trees, which, therefore, may be regarded as a special case.
B-trees
We consider first the n-ary tree, and, in this section, its use in searching applications. Such trees are usually called B-trees, a convention we shall follow.
When we discussed binary trees in Chapter 2 we noted that searching, insertion and deletion were all O(log n), provided that the tree remained balanced. Although we did not discuss the topic of balance in much detail there, we referred the reader to a number of relevant techniques. B-trees arise in this connection too, though here we shall approach them from a different point of view.
Let us imagine first of all that we have a sequence of variable-length items in the store with an item with an infinite key placed at the end.
- Type
- Chapter
- Information
- Recursion via Pascal , pp. 115 - 141Publisher: Cambridge University PressPrint publication year: 1984