Tree Traversal
90 likes | 325 Vues
Explore the concepts of PreOrder, Inorder, and Postorder Traversal in ordered rooted trees. Learn the sequence in which vertices are visited and their significance in complex expressions.
Tree Traversal
E N D
Presentation Transcript
Traversal Algorithms • preorder • inorder • postorder
In which order does a inorder traversal visit the vertices in this ordered rooted tree? procedureinorder(T: ordered rooted tree) r := root of T if r is a leaf then list r else begin l:= first child of r from left to right T(l) := subtree with l as its root inorder(T(l)) list r for each child c of r except for l left to right T(c) := subtree with c as its root preorder(T(c)) end output: j e n k o p b f a c l g m d h i
In which order does a postorder traversal visit the vertices in this ordered rooted tree?
Infix, Prefix, and Postfix Notation represent complicated expressions using an ordered rooted tree (typically binary) • Algebraic expressions • preorder – Polish notation • inorder – infix notation • postorder – reverse Polish notation