Unit 6Trees
Follows IGNOU MCS-208, Unit 6
Arrays, lists, stacks and queues are linear: every item has at most one item before it and one after it. Many kinds of data are not like that. Folders contain folders, a company has departments with sub-departments, and an arithmetic expression has sub-expressions inside sub-expressions. A tree is the data structure for such hierarchies. This unit introduces tree terminology, counts nodes and edges in trees, then concentrates on binary trees: how to store them, how to visit every node (traversal) with and without recursion, and where they are used.
In this unit you will learn to
- use the vocabulary of trees: root, parent, child, leaf, level, depth, height, degree;
- state the tree ADT and the recursive definition of a tree;
- count nodes, edges, leaves and internal nodes in m-ary and binary trees;
- represent general trees and binary trees with pointers and with arrays;
- traverse a tree in preorder, inorder, postorder and level order;
- write traversals with recursion, with an explicit stack, and with threads;
- apply trees to file systems, binary search trees and expression trees.
Sections in this unit
- 6.1Tree Terminology and the Tree ADTWhat a rooted tree is, its recursive definition, the words root, parent, child, leaf, level, depth and height, and the tree ADT.11 min
- 6.2Counting in m-ary TreesEdges equal nodes minus one, counting nodes per level, full m-ary tree formulas for leaves and internal nodes, and the Check Your Progress 1 answers.11 min
- 6.3General Trees: Representation and TraversalStoring a general tree with k child pointers or as first-child/next-sibling, and preorder, postorder and level-order traversal of general trees.10 min
- 6.4Binary Trees and Their PropertiesThe definition of a binary tree, full, complete and perfect binary trees, and the properties that bound nodes, height, leaves and NULL links.10 min
- 6.5Representing Binary Trees in MemoryThe linked node with left and right pointers, the array (sequential) representation with index formulas, and the corrected Figure 6.11.8 min
- 6.6Recursive Traversals: Preorder, Inorder, Postorder and Level OrderThe four binary tree traversals by hand and as recursive C functions, expression trees, and corrected answers to Check Your Progress 2.14 min
- 6.7Non-Recursive Traversals and Threaded Binary TreesPreorder and inorder traversal with an explicit stack, a corrected Program 6.5, and threaded binary trees that traverse without a stack.17 min
- 6.8Applications of TreesBinary search trees, expression trees and their evaluation, decision and game trees, and other uses of trees in computing.14 min