views:

55

answers:

2
+1  Q: 

binary search tree

Hi This is my homework and I have thought a lot about it but I could not get the answer I need your guidance ,please help me thanks

Q:

we have keys from 1 to 1000 in BST and we want to find the key = 363

which of these following searching is not correct?

    <925, 202, 911, 240, 912, 245, 363>
    <924, 220, 911, 244, 898, 258, 362, 363>
+5  A: 

Hint: When searching in a sorted BST, the upper and lower bounds should only get tighter.

KennyTM
+2  A: 
<925, 202, 911, 240, 912, 245, 363>

Doesn't make sense

From 911, you're taking the smaller branch to 240. You then somehow arrive at 912. This should be impossible.

If the left child of any node is smaller than its parent, then ALL elements in the left subtree should be smaller than their parent. 912 > 911, therefore it's in the wrong subtree.

Jamie Wong
aha,I get it the left sub tree should be less than the right sub treethanks for your answer
@matin1234 What I was trying to say is that the entire left sub tree should be less than the parent, not just less than the right sub tree
Jamie Wong
aha now I get the whole thanks