Trees 5 May 2016 OSU CSE 1 A New Math Type: tree A ubiquitous - - PowerPoint PPT Presentation

trees
SMART_READER_LITE
LIVE PREVIEW

Trees 5 May 2016 OSU CSE 1 A New Math Type: tree A ubiquitous - - PowerPoint PPT Presentation

Trees 5 May 2016 OSU CSE 1 A New Math Type: tree A ubiquitous concept in computing is that of a tree Often we are interested in a binary tree , a special case of a tree in which each node has at most two children An informal


slide-1
SLIDE 1

Trees

5 May 2016 OSU CSE 1

slide-2
SLIDE 2

A New Math Type: tree

  • A ubiquitous concept in computing is that
  • f a tree

– Often we are interested in a binary tree, a special case of a tree in which each node has at most two children

  • An informal introduction (“node”?,

“children”?) follows, using pictures rather than any new mathematical notation

5 May 2016 OSU CSE 2

slide-3
SLIDE 3

Recursive Structure

  • A tree is made up of:

– A root node – A string of zero or more child nodes of the root, each of which is the root of its own tree

  • Since a tree may contain other trees, its

structure is recursive

  • Note: the following explanation of trees is

adequate for present purposes but is not technically complete; details later…

5 May 2016 OSU CSE 3

slide-4
SLIDE 4

5 May 2016 OSU CSE 4

B R K A C T L G S H E P

slide-5
SLIDE 5

Nodes

5 May 2016 OSU CSE 5

B R K A C T L G S H E P ?

slide-6
SLIDE 6

Edges or Branches

5 May 2016 OSU CSE 6

B R K A C T L G S H E P

slide-7
SLIDE 7

5 May 2016 OSU CSE 7

B R K A C T L G S H E P root node (node B)

slide-8
SLIDE 8

5 May 2016 OSU CSE 8

B R K A C T L G S H E P children of root node (or,

  • f node B)
slide-9
SLIDE 9

5 May 2016 OSU CSE 9

B R K A C T L G S H E P parent of node S (for example)

slide-10
SLIDE 10

5 May 2016 OSU CSE 10

B R K A C T L G S H E P siblings of node S

slide-11
SLIDE 11

5 May 2016 OSU CSE 11

B R K A C T L G S H E P leaf nodes

slide-12
SLIDE 12

5 May 2016 OSU CSE 12

B R K A C T L G S H E P root leaf Yes, it’s drawn upside down!

slide-13
SLIDE 13

5 May 2016 OSU CSE 13

B R K A C T L G S H E P size of a tree is its total number of nodes; here, it is 12

slide-14
SLIDE 14

Your Turn!

5 May 2016 OSU CSE 14

Q G H R C T L D What’s the size of each

  • f these 4

trees? C A Y W K P B

slide-15
SLIDE 15

5 May 2016 OSU CSE 15

B R K A C T L G S H E P path from node B to node L; its length is 3

slide-16
SLIDE 16

5 May 2016 OSU CSE 16

B R K A C T L G S H E P height of a tree is the length of the longest path from its root; here, it is 4

slide-17
SLIDE 17

Your Turn!

5 May 2016 OSU CSE 17

Q G H R C T L D What’s the height of each of these 4 trees? C A Y W K P B

slide-18
SLIDE 18

A Tricky One?

5 May 2016 OSU CSE 18

N What’s the height of this tree? D A Y L K P Q B

slide-19
SLIDE 19

5 May 2016 OSU CSE 19

B R K A C T L G S H E P tree rooted at node B

slide-20
SLIDE 20

5 May 2016 OSU CSE 20

B R K A C T L G S H E P subtree 0

  • f tree

rooted at node B (or,

  • f node B)
slide-21
SLIDE 21

5 May 2016 OSU CSE 21

B R K A C T L G S H E P subtree 1

  • f tree

rooted at node B (or,

  • f node B)
slide-22
SLIDE 22

5 May 2016 OSU CSE 22

B R K A C T L G S H E P subtree 2

  • f tree

rooted at node B (or,

  • f node B)
slide-23
SLIDE 23

5 May 2016 OSU CSE 23

B R K A C T L G S H E P Notice the recursive structure: a root plus its subtrees.

slide-24
SLIDE 24

Resources

  • Wikipedia: Tree structure

– http://en.wikipedia.org/wiki/Tree_structure

5 May 2016 OSU CSE 24