Introduction to Trees

Introduction to Trees - Introduction to Trees Page 1 of 6...

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

View Full Document Right Arrow Icon
I NTRODUCTION TO T REES Contents z Introduction: Trees and Binary Trees { Representing Trees ± Test Yourself #1 { Tree Traversals ± Test Yourself #2 ± Test Yourself #3 z Answers to Self - Study Questions Introduction Lists, stacks, and queues, are all linear structures: in all three data structures, one item follows another. Trees will be our first non-linear structure: z More than one item can follow another. z The number of items that follow can vary from one item to another. Trees have many uses: z representing family genealogies z as the underlying structure in decision-making algorithms z to represent priority queues (a special kind of tree called a heap ) z to provide fast access to information in a database (a special kind of tree called a b-tree ) Here is the conceptual picture of a tree (of letters): z each letter represents one node z the arrows from one node to another are called edges z the topmost node (with no incoming edges) is the root (node A) z the bottom nodes (with no outgoing edges) are the leaves (nodes D, I, G & J) So a (computer science) tree is kind of like an upside-down real tree. .. Page 1 of 6 Introduction to Trees 2008/3/27 http://pages.cs.wisc.edu/~cs367-1/topics/Trees/
Background image of page 1

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

View Full DocumentRight Arrow Icon
A path in a tree is a sequence of (zero or more) connected nodes; for example, here are 3 of the paths in the tree shown above: The length of a path is the number of nodes in the path, e.g.: The height of a tree is the length of the longest path from the root to a leaf; for the above example, the height is 4 (because the longest path from the root to a leaf is A C E G, or A C E J). An empty tree has height = 0. The depth of a node is the length of the path from the root to that node; for the above example: z the depth of J is 4 z the depth of D is 3 z the depth of A is 1 Given two connected nodes like this: Node A is called the parent , and node B is called the child
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

Introduction to Trees - Introduction to Trees Page 1 of 6...

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

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