lec0309-traversals-ann - Today’s announcements: MP4...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 10
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 12
Background image of page 13
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Today’s announcements: MP4 available, EC due 3/4, due 3/11. 11:59p. Today: Trees Complete tree: http://innux.nist.gov/dads//HTML/completeBinaryTree.htrnl ' / (/3 /°\ /\ (F C ' Al; NO Rooted. directed. ordered, binary trees a" — Inc-t undo a! QOIL and “gut \ubttuo ponntur\ class n n public: ll IVA n private: EVA struck. trooNodot '1' data: Ble’ee ADTZ troouod. 4» 1.1:,- . creeNode " right: Insert r remove treeNode * root traverse Theorem: ifthoro are n data items in a binary tree. than there are N I null pointers. PF.“ 3 Pas. T.“ 0-“ avbi‘h’u3 _ "ilekfl ifs 5"“ Traversal — scheme for visiting every node. FMz1—-/bc*d¢ /\ inOrhki‘b/C*d*e’ 9\ /U\p«eonluzbc/-Ae* + /"\ y 9 y y 0 At each node, two choices for direction (left, right) - After both subtrees of a node are complete, move back up tree - Each node is “visited” 3 times in a traversal. - Each of those visit times corresponds to a particular kind of traversal. http://nova.umuc.edu/-jarcfidsvllessor\1 .html Traversals: template<claaa T) void b1nazflzee<T>= : m_Ozdez (txeeNode ' czoot) ( 1t (crooi :- null [ . yd (woo alabbj Werdertcroot-nert): ‘ Pi! Ordctlcroot ->right): Traversals: template<c1aaa T) . void binazyrree<T>z : \“ Order It reeNode it (croot :— nullH o I!‘ Order (0100?: ->1et‘ '19“ (wt-9%; ‘n Order (croot ->riqht) : Traversals: template-:claaa T) void bxnazflzeefl'n: h Order ltzeeflode ' czoot) I It (croot :- nullH Mk Order lcroot —>1ett) : ihg. L Order lcroot ->right ) : \i “ (croft *7 m) Traversals: A few mechanical questions... What is the 2nd letter printed in an inOrder traversal of this tree? In what position is C printed in a postOrder traversal of this tree? Which traversal prints the data of the tree in ABC ordef? Draw and label a tree containing 8 integers so that an inOrder traversal of the tree prints the numbers in order. Draw and label a tree containing 8 integers so that a preOrder traversal of the tree prints the numbers in order. A °\ E / B\ D/ Traversals: A few discussion questions... tanplate<clasa T) void binarflroo<f>::prwtdcrtttooflodo ' crootii /\ 1t (croot :- null” . . yell (erect-manta) ; ‘\ pteOzde:(croot->1ett)1 v“ v» preOIdet (ctoot ->right) l .0 JD What is running time? Is pneOrder public or private? How could we make this function employ a different function upon a visit? Traversals: a broader view... template<c1ass T> treeNode ' binaryTree<T>x:copyttreeflode ' croot)( Traversals: another broader view... template<c1aas T) void binaryTree<T>|nclear(treeNode ' croot)( Traversals: something totally different... template<claoa 'l'> voxd b1naryTzee<T>| slaveIOrder (troubled. " croot) ( ...
View Full Document

Page1 / 13

lec0309-traversals-ann - Today’s announcements: MP4...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online