trees1(1) - Trees Examples of Tree structure Definition of...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Trees Examples of Tree structure Definition of trees Binary tree Height of tree Tree traversals Finding max Finding sum
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Trees You have seen that using linked lists you can represent an ordered collection of values without using arrays. Although linked lists require more memory space than arrays ( as they have to store address at each node), they have definite advantages over arrays. Insertion and deletion of items can be carried out with out involving considerable movement of data. The ordering relationship amongst a set of values is obtained through use of pointers. However, we need not restrict ourselves to only linear structures. In this chapter we shall extend the use of pointers to define a non-linear structure to model hierarchical relationships, such as a family tree. In such a tree, we have links moving from an ancestor to a parent, and links moving from the parent to children. We have many other examples of tree-structured hierarchies. Directory Hierarchies : In computers, files are stored in directories that form a tree. The top level directory represents the root. It has many subdirectories and
Background image of page 2
3 files. The subdirectories would have further set of subdirectories. Organization charts: In a company a number of vice presidents report to a president. Each VP would have a set of general managers, each GM having his/her own set of specific managers and so on. Biological classifications : Starting from living being at the root, such a tree can branch off to mammals, birds, marine life etc. Game Trees: All games which require only mental effort would always have number of possible options at any position of the game. For each position, there would be number of counter moves. The repetitive pattern results in what is known a game tree. Tree as a data structure A tree is a data structure that is made of nodes and pointers, much like a linked list. The difference between them lies in how they are organized: The top node in the tree is called the root and all other nodes branch off from this one.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Every node in the tree can have some number of children. Each child node can in turn be the parent node to its children and so on. Child nodes can have links only from a single parent. Any node higher up than the parent is called an ancestor node. Nodes having no children are called
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 24

trees1(1) - Trees Examples of Tree structure Definition of...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online