开发者

binary search tree

开发者 https://www.devze.com 2023-01-04 16:40 出处:网络
This is my homework and I have thought a lot about it but I could not get the answe开发者_如何学Pythonr I need your guidance ,please help me thanks

This is my homework and I have thought a lot about it but I could not get the answe开发者_如何学Pythonr 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>


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


<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.

0

精彩评论

暂无评论...
验证码 换一张
取 消