Midterm Review2.0

Midterm Review2.0 - Tree ADT We use positions to abstract...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Tree ADT We use positions to abstract nodes Generic methods: Query methods: integer size() boolean isInternal(p) boolean isEmpty() boolean isExternal(p) Iterator iterator() boolean isRoot(p) Iterable positions() Update method: Accessor methods: object replace(p, o) position root() Additional update methods may be defined by data structures implementing the Tree ADT position parent(p) positionIterator children(p) CSE 2011 Prof. J. Elder - 46 - Last Updated: 1/7/10 10:14 AM Preorder Traversal A traversal visits the nodes of a tree in a systematic manner In a preorder traversal, a node is visited before its descendants Algorithm preOrder(v) visit(v) for each child w of v preOrder (w) 1 Make Money Fast! 2 5 1. Motivations 2. Methods 3 4 1.1 Greed 1.2 Avidity CSE 2011 Prof. J. Elder 9 6 7 2.1 Stock Fraud - 47 - 2.2 Ponzi Scheme References 8 2.3 Bank Robbery Last Updated: 1/7/10 10:14 AM Postorder Traversal In a postorder traversal, a node is visited after its descendants Algorithm postOrder(v) for each child w of v postOrder (w) visit(v) 9 cs16/ 3 7 homeworks/ todo.txt 1K programs/ 1 2 h1c.doc 3K h1nc.doc 2K CSE 2011 Prof. J. Elder 8 4 5 DDR.java 10K - 48 - Stocks.java 25K 6 Robot.java 20K Last Updated: 1/7/10 10:14 AM Properties of Proper Binary Trees Notation Properties: n number of nodes e=i+1 e number of external nodes n = 2e - 1 i number of internal nodes h i h height h (n - 1)/2 e 2h h log2e h log2(n + 1) - 1 CSE 2011 Prof. J. Elder - 49 - Last Updated: 1/7/10 10:14 AM BinaryTree ADT The BinaryTree ADT extends the Tree ADT, i.e., it inherits all the methods of the Tree ADT Additional methods: position left(p) position right(p) boolean hasLeft(p) boolean hasRight(p) Update methods may be defined by data structures implementing the BinaryTree ADT CSE 2011 Prof. J. Elder - 50 - Last Updated: 1/7/10 10:14 AM ...
View Full Document

This note was uploaded on 02/14/2012 for the course CSE 2011Z taught by Professor Elder during the Fall '11 term at York University.

Ask a homework question - tutors are online