Question

a) Create a binary search tree with the 4 2 2 0 1 4 5 9...

a) Create a binary search tree with the 4 2 2 0 1 4 5 9 7 1 5 3 6 number. b) Provide the Preorder, Inorder and Postorder traversal of tree obtained in part (a). Show all the steps.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

a) BST(Binary search tree)

Insert nodes into BST, if the number is less than root insert as the left child and if the number is greater than or equal to root insert as the right child.

4 4 4 2 2 2 N 2 2 0 2

4 4 4 2 4 2 4 2 4 0 0 2 5 0 5 1 9

4 4 2 4 2 4 0 2. 5 0 5 N 1 9 9 7

2 4 2 4 0 2 0 5 N 1 9 3 9 1 7 5 5

N 4 N 5 1 3 9 1 7 5 6

b) Postorder traversal(LRV)

Start from the root node, travel in the order of Left then Right at last visit.

1 1 0 3 2 2 6 5 7 9 5 4 4

2 4 0 5 N 1 3 9 1 7 5 6

2 0 2 5 9 1 7 5 6

2 4 0 5 1 3 1 7 5

2 4 2 4 2 5 0 5 N 3 3 1 7 1 7 5 5 6 6

4 4 2 4 2 1 0 2 5 0 2 5 3 9 3 9 1 7 1 7 5 5 6 6

4 2 4 N 0 5 0 N N 5 1 1 3 9 1 3 7 7 5 5 6 6

4 4 2 4 2 0 2 6 0 2 5 3 9 3 9 1 7 1 7 5 5 6 6

2 4 N 0 2 5 0 2 5 1 3 9 1 3 9 1 7 1 7 5 5 6 6

Inorder traversal (LVR):

Start from the root node, travel in the order of Left then visit at last Right.

0 1 1 2 2 3 4 4 5 5 6 7 9

4 2 4 4 N 0 2 5 0 2 5 9 1 3 9 7 1 7 5 5 6 6

N N 0 2 5 0 2 5 1 3 9 1 3 9 1 7 1 7 5 5 6 6

4 4 2 N 2 5 0 2 5 1 3 9 1 3 9 1 7 1 7 5 5 6 09

4 4 2 4 N 2 5 O 2 5 1 3 9 3 9 7 7 5 5 09 6

4 4 4 2. N N 5 0 2 1 1 1 1 1 1 ! 1 9 1 3 9 7 7 5 5 6 6

4 4 2 2 9 2 5 0 2 5 1 1 1 1 1 3 9 3 9 7 7 5 5 6 09

4 2. 2 5 1 3 9 1 7 5 6

Preorder traversal (VLR)

Start from the root node, travel in the order of Visit then Left at last Right.

4 2 0 1 1 2 3 4 5 9 7 5 6

4 4 2 4 N 0 2 5 0 2 5 9 3 7 1 7 5 5 6 6

4 2 4 N 2 5 0 2 5 1 1 1 1 1 1 1 1 3 9 3 9 7 1 7 5 5 6

2 2 2 5 0 5 N 1 1 1 3 9 1 3 1 7 1 7 5 5 6 09

4 2. 4 N 0 2 5 0 2 5 1 1 1 1 1 1 . 3 9 3 9 7 7 5 5 6 6

2. 5 3 1 7 5 6

Add a comment
Know the answer?
Add Answer to:
a) Create a binary search tree with the 4 2 2 0 1 4 5 9...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT