{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

View Full Document Right Arrow Icon
CSCI-255 Advanced Data Structures Lecture 18
Background image of page 1

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

View Full Document Right Arrow Icon
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
Background image of page 2
Implementing Binary Trees box3 Can be implemented in at least 2 ways square6 As linked structures (IN CLASS) square6 As arrays
Background image of page 3

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

View Full Document Right Arrow Icon
Background image of page 4
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
Background image of page 5

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

View Full Document Right Arrow Icon
Background image of page 6
Background image of page 7

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

View Full Document Right Arrow Icon
Background image of page 8
Background image of page 9

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

View Full Document Right Arrow Icon
Background image of page 10
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 ]}