{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# lecture18 - s If the key is greater than the value try the...

This preview shows pages 1–10. Sign up to view the full content.

CSCI-255 Advanced Data Structures Lecture 18

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Binary Search Trees (BST) box3 A binary tree with the following property: For each node of the tree, all values stored in its left subtree (the tree whose root is the left child) are less than the value stored in the node, and all values stored in the right subtree are greater than the value stored in the node
Implementing Binary Trees box3 Can be implemented in at least 2 ways square6 As linked structures (IN CLASS) square6 As arrays

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Searching a BST box3 For every node, compare the key to be located with the value stored in the node currently pointed at square6 If the key is less than the value, go to the left subtree and try again

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: s If the key is greater than the value, try the right subtree s If the key is the same as the value, obviously the search stops Searching a BST (cont’d) b Example: Search for the key 15 Recursive version of search? (DONE IN CLASS) Inserting an Element into a BST b Search for the position in the tree where the element would be found b Insert the element in the position s Note: A newly inserted node is a leaf Inserting an Element into a BST (cont’d) Inserting an Element into a BST (cont’d) Exercise: Write a recursive version of insert (DONE IN CLASS) Do 6.22(e) (DONE IN CLASS) Running Time?...
View Full Document

{[ snackBarMessage ]}