Announcements HW2 available, due 10/04, 11:59p. MT1 10/10, 7-9p. - - PowerPoint PPT Presentation

announcements
SMART_READER_LITE
LIVE PREVIEW

Announcements HW2 available, due 10/04, 11:59p. MT1 10/10, 7-9p. - - PowerPoint PPT Presentation

Announcements HW2 available, due 10/04, 11:59p. MT1 10/10, 7-9p. Trees: most important nonlinear structure[s] in computer science. -- Donald Knuth, Art of Computer Programming Vol 1 A tree: _____________________________________


slide-1
SLIDE 1

Announcements –

HW2 available, due 10/04, 11:59p. MT1 10/10, 7-9p.

Trees:

“… most important nonlinear structure[s] in computer science.”

  • - Donald Knuth, Art of Computer Programming Vol 1

A tree: _____________________________________ We’ll study more specific trees:

slide-2
SLIDE 2

Tree terminology:

  • One of the vertices is called the root of the tree. Guess which one it is.
  • Make an English word containing the names of the vertices that have a parent but no

sibling.

  • How many parents does each vertex have?
  • Which vertex has the fewest children?
  • Which vertex has the most ancestors? descendants?
  • What is d’s depth? What is d’s height?
  • List all the vertices is b’s left subtree.
  • List all the leaves in the tree.
slide-3
SLIDE 3

Tree terminology: (for your reference)

  • root: the single node with no parent
  • leaf: a node with no children
  • child: a node pointed to by me
  • parent: the node that points to me
  • sibling: another child of my parent
  • ancestor: my parent or my parent’s ancestor
  • descendent: my child or my child’s descendent
  • subtree: a node and its descendents
  • depth of node x: number of edges on path from root to x.
  • height of node x: number of edges on longest path from x to a leaf.
slide-4
SLIDE 4

A rooted tree:

slide-5
SLIDE 5

Branching: d-ary trees (binary if d = 2)

A d-ary tree T is either

  • OR
  • Full d-ary tree:

Perfect d-ary tree: Complete d-ary tree:

slide-6
SLIDE 6

Binary Tree Height height(r) -- length of longest path from root r to a leaf

Given a binary tree T, write a recursive defn of the height of T, height(T): Number of nodes in a perfect tree of height h, N(h):

slide-7
SLIDE 7

Rooted, directed, ordered, binary trees

Tree ADT: insert remove traverse

1 2 3 4 5 6 7 8 9 10 11 12 13 template<class T> class tree { public: … private: struct Node { T data; Node * left; Node * left; }; Node * root; … };

slide-8
SLIDE 8

Theorem: Our implementation of an n item binary tree has ______ null pointers.