14-BST

# 14-BST - Binary Search Tree(BST Properties Each node has a...

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

Properties: - Each node has a value - The left subtree contains only values less than the parent node’s value - The right subtree contains only values greater than or equal to the parent node’s value Binary Search Tree (BST) Binary Search Tree (BST)

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

View Full Document
BST Example BST Example
if the root is NULL then the item is not found else if the root->Data == searchData then return the root else if the root->Data > searchData then recursively search left subtree else recursively search right subtree end if end if BST Search Algorithm BST Search Algorithm

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

View Full Document
If the tree is full BST search requires O(logN) operations, which is the same as O(h) where h is the height of the tree. BST Search Performance BST Search Performance Height (h) 1 2 3 4
if the root is NULL then replace the empty tree with the new node else if the root->Data == insertData then do nothing, the item is already in the tree else if the root->Data > insertData then recursively insert into the left subtree else recursively insert into the right subtree end if end if Insertion into BST Insertion into BST

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.

## This note was uploaded on 03/18/2010 for the course CSE 122 taught by Professor Yoxheimer,ericch during the Spring '07 term at Penn State.

### Page1 / 13

14-BST - Binary Search Tree(BST Properties Each node has a...

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

View Full Document
Ask a homework question - tutors are online