Binary Search Trees

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

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

View Full Document Right Arrow Icon
The search Tree ADT— Binary Search Trees
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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 );
Background image of page 3

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

View Full DocumentRight Arrow Icon
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; };
Background image of page 4
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 )
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online