Binary Search Trees

# Binary Search Trees - The search Tree ADT Binary Search...

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

The search Tree ADT— Binary Search Trees

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

View Full Document
Definition A binary search tree is a binary tree. It may be empty. If it is not empty, it satisfies the following properties: (1) Every node has a key which is an integer , and the keys are distinct . (2) The keys in a nonempty left subtree must be smaller than the key in the root of the subtree. (3) The keys in a nonempty right subtree must be larger than the key in the root of the subtree. (4) The left and right subtrees are also binary search trees. 30 5 2 40 20 15 12 25 10 22 60 70 80 65 1. Definition Binary Search Trees
Binary Search Trees 2. ADT Objects : A finite ordered list with zero or more elements. Operations : SearchTree MakeEmpty ( SearchTree T ); Position Find ( ElementType X, SearchTree T ); Position FindMin ( SearchTree T ); Position FindMax ( SearchTree T ); SearchTree Insert ( ElementType X, SearchTree T ); SearchTree Delete ( ElementType X, SearchTree T ); ElementType Retrieve ( Position P );

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

View Full Document
Binary Search Trees Binary search tree declarations struct TreeNode; typedef struct TreeNode *Position; typedef struct TreeNode *SearchTree; struct TreeNode { ElementType Element; SearchTree Left; SerachTree Right; };
3. Implementations Find Position Find( ElementType X, SearchTree T ) { if ( T == NULL ) return NULL; /* not found in an empty tree */ if ( X < T->Element ) /* if smaller than root */ return Find( X, T->Left ); /* search left subtree */ else if ( X > T->Element )

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.

{[ snackBarMessage ]}

### Page1 / 14

Binary Search Trees - The search Tree ADT Binary Search...

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

View Full Document
Ask a homework question - tutors are online