Binary Search Trees

# Binary Search Trees - Lecture 15 Introduction to Binary...

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

1 Lecture 15: Introduction to Binary Search Trees PIC 10B Todd Wittman Note : There is no Big C++ reading for trees. Instead read the notes I placed online. Binary Search Trees s A binary search tree (BST) is an ordered collection of items organized into nodes which have two pointers: left and right. s The values in a BST must satisfy the following rule. s The BST Property : If node x is to the left of node y, then x y. If x is right of y, then x>y. s A BST can hold any type of item, as long as the item can be ordered (defined <, >, ==). 2 left x 2 right x>2 15 5 16 3 12 7 20 18 23 13 10 6 When visualizing a BST, we generally don't draw the pointers to NULL.

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

View Full Document
2 BST Terminology: Nodes s The node at the top is called the root node. 15 is the root of this tree s If x links to y, then x is called a parent and y is called a child . 16 is the parent of 20 15 5 16 3 12 7 20 18 23 13 10 6 s If x can follow some path down to y, then x is called an ancestor of y. And y is called a descendent
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 4

Binary Search Trees - Lecture 15 Introduction to Binary...

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

View Full Document
Ask a homework question - tutors are online