Lecture14

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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

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

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

View Full DocumentRight Arrow Icon
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?
Background image of page 4
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.
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.

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