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

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 DocumentRight Arrow Icon
Binary Search Trees (BST) b 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 b Can be implemented in at least 2 ways s As linked structures (IN CLASS) s As arrays
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Searching a BST b For every node, compare the key to be located with the value stored in the node currently pointed at s 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 DocumentRight 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 DocumentRight 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 DocumentRight 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

This note was uploaded on 11/26/2009 for the course MATH AND C CSCI255 taught by Professor Dr.ikergondraluja during the Spring '09 term at St. Francis Xavier, Antigonish.

Page1 / 10

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

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online