cs 225
play

CS 225 Data Structures Feb. 14 Tre rees Wad ade Fag agen-Ulm - PowerPoint PPT Presentation

CS 225 Data Structures Feb. 14 Tre rees Wad ade Fag agen-Ulm lmschneid ider Lecture Resources Queue.h 4 template <class QE> 5 class Queue { 6 public: 7 class QueueIterator : public


  1. CS 225 Data Structures Feb. 14 – Tre rees Wad ade Fag agen-Ulm lmschneid ider

  2. Lecture Resources

  3. Queue.h 4 template <class QE> 5 class Queue { 6 public: 7 class QueueIterator : public std::iterator<std::bidirectional_iterator_tag, QE> { 8 public: 9 QueueIterator(unsigned index); 10 QueueIterator& operator++(); 11 bool operator==(const QueueIterator &other); 12 bool operator!=(const QueueIterator &other); 13 QE& operator*(); 14 QE* operator->(); 15 private: 16 int location_; 17 18 }; 19 20 /* ... */ 21 22 private: 23 QE* arr_; unsigned capacity_, count_, entry_, exit_; 24 }; 25 26

  4. Big Id Ideas How does the Queue and the QueueIterator interact?

  5. Trees “The most important non -linear data structure in computer science.” - David Knuth, The Art of Programming, Vol. 1 A tree is: • •

  6. A Rooted Tree “Mario Family Line” <http://limitbreak.gameriot.com/blogs/ Caveat-Emptor/Mario-Family-Line>

  7. More Specific Trees We’ll focus on binary trees : • A binary tree is rooted – every node can be reached via a path from the root

  8. More Specific Trees We’ll focus on binary trees : • A binary tree is acyclic – there are no cycles within the graph

  9. More Specific Trees We’ll focus on binary trees : • A binary tree contains two or fewer children – where one is the “left child” and one is the “right child”:

  10. Tree Terminology • What’s the longest “word” you can make using the vertex labels in the tree (repeats allowed)?

  11. Tree Terminology • Find an edge that is not on the longest path in the tree. Give that edge a reasonable name. • One of the vertices is called the root of the tree. Which one? • Make an “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? • Which vertex has the most descendants? • List all the vertices is b’s left subtree. • List all the leaves in the tree.

  12. Tree Terminology • What’s the longest “word” you can make using the vertex labels in the tree (repeats allowed)? • Find an edge that is not on the longest path in the tree. Give that edge a reasonable name. • One of the vertices is called the root of the tree. Which one? • Make an “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? • Which vertex has the most descendants? • List all the vertices is b’s left subtree. • List all the leaves in the tree.

  13. Tree Terminology • What’s the longest “word” you can make using the vertex labels in the tree (repeats allowed)? • Find an edge that is not on the longest path in the tree. Give that edge a reasonable name. • One of the vertices is called the root of the tree. Which one? • Make an “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? • Which vertex has the most descendants? • List all the vertices is b’s left subtree. • List all the leaves in the tree.

  14. Tree Terminology • What’s the longest “word” you can make using the vertex labels in the tree (repeats allowed)? • Find an edge that is not on the longest path in the tree. Give that edge a reasonable name. • One of the vertices is called the root of the tree. Which one? • Make an “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? • Which vertex has the most descendants? • List all the vertices is b’s left subtree. • List all the leaves in the tree.

  15. Tree Terminology • What’s the longest “word” you can make using the vertex labels in the tree (repeats allowed)? • Find an edge that is not on the longest path in the tree. Give that edge a reasonable name. • One of the vertices is called the root of the tree. Which one? • Make an “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? • Which vertex has the most descendants? • List all the vertices is b’s left subtree. • List all the leaves in the tree.

  16. Binary ry Tree – Defined C A binary tree T is either: • S X OR A 2 • 2 5

  17. Tree Property: height C height(T) : length of the longest path from the root to a leaf S X Given a binary tree T: A 2 2 5 height(T) =

  18. Tree Property: fu full C A tree F is full if and only if: 1. S X 2. A 2 2 5

  19. Tree Property: perfect C A perfect tree P is: 1. S X 2. A 2 2 5

  20. Tree Property: complete C Conceptually : A perfect tree for every level except the last, where the last level if “pushed to the left”. S X Slightly more formal : For any level k in A 2 2 5 [0, h-1], k has 2 k nodes. For level h, all nodes are “pushed to the left”. Y Z

  21. Tree Property: complete C A complete tree C of height h , C h : 1. C -1 = {} 2. C h (where h>0) = {r, T L , T R } and either: S X T L is __________ and T R is _________ A 2 2 5 OR Y Z T L is __________ and T R is _________

  22. Tree Property: complete C Is every full tree complete ? S X A 2 2 5 If every complete tree full ? Y Z

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