announcements
play

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: _____________________________________


  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:

  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.

  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.

  4. A rooted tree:

  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:

  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):

  7. Rooted, directed, ordered, binary trees 1 template<class T> 2 class tree { 3 public: 4 … 5 private: Tree ADT: 6 struct Node { 7 T data; 8 Node * left; insert 9 Node * left; 10 }; remove 11 Node * root; 12 … traverse 13 };

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

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend