CS1102C-Lecture_7-tree - Trees 1 1 Readings...

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

View Full Document Right Arrow Icon
1 1 Trees
Background image of page 1

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

View Full Document Right Arrow Icon
2 2 Readings ± Required [Carrano & Prichard] Chapter 10
Background image of page 2
3 3 Linked list
Background image of page 3

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

View Full Document Right Arrow Icon
4 4 A Tree as a Data Structure • shown upside down • Used to represent relationships • has a hierarchy
Background image of page 4
5 5 Definitions node edge Data objects (the circles) in a tree are called nodes . Links between nodes are called edges .
Background image of page 5

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

View Full Document Right Arrow Icon
6 6 Relationship ± A is a parent of B and C ± B and C are children of A ± B and C are siblings (with the same parent A) D E A B F C
Background image of page 6
7 7 Relationship ± D is an ancestor of B. ± B is a descendant of A and D. ± Definition: Node X is an ancestor of node Y if ² X is a parent of Y, or ² X is a parent of some node Z and Z is an ancestor of Y. D E A B F C
Background image of page 7

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

View Full Document Right Arrow Icon
8 8 Tree Nodes root (has no parent) internal nodes (has one parent and at least one child) leaves (has no children) Every node (except the root) of a tree has one parent. A node with no children is a leaf node.
Background image of page 8
9 9 subtree Subtree A node and all of its descendants form a subtree Q: Can a leaf be a subtree?
Background image of page 9

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

View Full Document Right Arrow Icon
10 10 Tree is recursive ! A tree is either • nothing, or • A node, with some set of subtrees, each of which is a tree ...
Background image of page 10
11 11 Level of a node ± Number of nodes on the path from the root to the node ² level of root is 1 ² level of A is 2 A B C level
Background image of page 11

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

View Full Document Right Arrow Icon
12 12 Height of a tree ± Maximum level of the nodes in the tree is the height of the tree A B C height = 4
Background image of page 12
13 13 Size of a tree ± Number of nodes in the tree is the size of the tree A • The size of this tree is 10. • The size of the subtree rooted at A is 4.
Background image of page 13

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

View Full Document Right Arrow Icon
14 14 Applications of Trees A tree can be used to represent data that is hierarchical in Nature
Background image of page 14
15 15 File systems Desktop My Documents My Computer C: D: H: I:
Background image of page 15

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

View Full Document Right Arrow Icon
16 16 Arithmetic Expressions (a+b) * (a-b) + 2 + 2 * - + a b a b Q: How do you construct such a tree from a given arithmetic expression?
Background image of page 16
17 17 General Trees ± An n -ary tree ² A tree whose nodes each can have no more than n children
Background image of page 17

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

View Full Document Right Arrow Icon
18 18 Binary Trees Each node has at most 2 ordered children
Background image of page 18
19 19 Binary Tree Each node has at most 2 ordered children. Q: What is the meaning of “ order ”?
Background image of page 19

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

View Full Document Right Arrow Icon
20 20 Binary Tree is Recursive
Background image of page 20
21 21 Full Binary Tree ± All nodes at a level < h have two children. (where h is the height of the tree) h Q: Is this definition the same as “all nodes except the leaf nodes have 2 children”?
Background image of page 21

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

View Full Document Right Arrow Icon
22 Complete Binary Tree ± Full down to level h-1 ± level h filled in from left to right. h
Background image of page 22
Image of page 23
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 76

CS1102C-Lecture_7-tree - Trees 1 1 Readings...

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

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