Question

Describe an algorithm that checks if a given binary tree T is a binary search tree. Analyze your algorithm by giving its asymptotic runtime. Show your work.

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

Efficient algorithm will be to use in order traversal:

Algorithm :

1. do in-order traversal of the tree

2. check if the array after traversal is sorted or not ? if sorted then BST otherwise NOT a BST

Complexity :

Line 1 : O(n)

Line2 : O(n)

hence O(n)

for more clarification please comment.

Add a comment
Know the answer?
Add Answer to:
Describe an algorithm that checks if a given binary tree T is a binary search tree....
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