Lecture14

# Lecture14 - CMPSC 24: Lecture 14 Trees, Binary Trees, &...

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

1 CMPSC 24: Lecture 14 Trees, Binary Trees, & Binary Search Trees Divyakant Agrawal Department of Computer Science UC Santa Barbara 5/16/10 1 Lecture Plan • Tree ADT – Binary Search Tree (BST) ADT 2 3 Owner Jake Manager Chef Brad Carol Waitress Waiter Cook Helper Joyce Chris Max Len Jake’s Pizza Shop UNIQUE PATH BETWEEN NODES

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

View Full Document
2 4 Owner Jake Manager Chef Brad Carol Waitress Waiter Cook Helper Joyce Chris Max Len Nomenclature ROOT NODE LEAF NODE LEVEL 0 LEVEL 1 LEVEL 2 PARENT, CHILD, ANCESTOR, DESCENDANT SUBTREE 5 Trees Level: Distance of a node from root Height: The maximum level 6 Trees Why is this not a tree ?
3 7 A node can have at most two children. The two children of a node are called the left child and the right child, if they exist. Binary Tree 8 A Binary Tree Q V T K S A E L 9 How Many Leaf Nodes? Q V T K S A E L

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

View Full Document
4 10 How Many Descendants of Q? Q V T K S A E L 11 How Many Ancestors of K? Q V T K S A E L 12 Trees How many different binary trees can be made from 2 nodes? 4 nodes? 6 nodes?
5 13 Implementing a Binary Tree with Pointers and Dynamic Data Q V T K S A E L 14 Structure of a Tree Node Possible to add a parent pointer 15 A special kind of binary tree in which: 1. Each node contains a distinct data value, 2. The key values in the tree can be compared using “greater than” and “less than”, and 3. The key value of each node in the tree is less than every key value in its right subtree , and greater than every key value in its left subtree.

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 12/27/2011 for the course CMPSC 24 taught by Professor Agrawal during the Fall '09 term at UCSB.

### Page1 / 13

Lecture14 - CMPSC 24: Lecture 14 Trees, Binary Trees, &...

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

View Full Document
Ask a homework question - tutors are online