April 12th, 2009, 11:50 PM
#1
[RESOLVED] tree traversals
I have to list to the vertices according to a preorder traversal, an inorder traversal, and a postorder traversal.
Here's what I have so far:
preorder: 0,1,3,6,7,9,10,2,4,5,8,11
inorder: 0,1,2,3,4,5,6,7,8,9,10,11
postorder: need help on how to do this
are the first 2 correct?
Attached Files
April 13th, 2009, 08:12 AM
#2
Re: tree traversals
If you have preorder and inorder, you should be able to do postorder. They're just swapping the orders in which you do things.
preorder:
1. visit node
2. preorder(node.left)
3. preorder(node.right)
inorder:
1. inorder(node.left)
2. visit node
3. inorder(node.right)
postorder:
1. postorder(node.left)
2. postorder(node.right)
3. visit node
Ignoring the base cases for simplicity, of course.
April 13th, 2009, 04:42 PM
#3
Re: tree traversals
Okay so did I do the first two correct?
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width