Topic 10 Trees Tree Definitions Tree Definitions Tree

  • Slides: 85
Download presentation
Topic 10 Trees

Topic 10 Trees

Tree Definitions

Tree Definitions

Tree Definitions

Tree Definitions

Tree Definitions

Tree Definitions

Binary Search Tree

Binary Search Tree

Traversal • Operations tree

Traversal • Operations tree

Announcements • Participation 4 is up • Homework 3 grading • Homework 4 grading

Announcements • Participation 4 is up • Homework 3 grading • Homework 4 grading

Search

Search

Insertion

Insertion

Deletion • Need – Min/max – Successor/predecessor

Deletion • Need – Min/max – Successor/predecessor

Pseudocode

Pseudocode

Pseudocode

Pseudocode

AVL

AVL

Height of AVL Tree

Height of AVL Tree

Proof

Proof

Insertion

Insertion

Example

Example

Single Right

Single Right

Left-Right

Left-Right

Four cases

Four cases

Deletions

Deletions

Example

Example

Announcements • Test in 2 weeks • Participation due tomorrow – Clarification

Announcements • Test in 2 weeks • Participation due tomorrow – Clarification

Splay Trees

Splay Trees

Amortized Running Time • Runtime:

Amortized Running Time • Runtime:

Basic Operations

Basic Operations

When to Splay

When to Splay

Zig

Zig

Zig-Zag

Zig-Zag

Zig-zig

Zig-zig

Example

Example

Deletion

Deletion

Optimal BST

Optimal BST

Notation

Notation

Example

Example

Example

Example

More Notation • (i, j) • (j+1, j)

More Notation • (i, j) • (j+1, j)

Observations

Observations

Observations

Observations

Announcements • Participation due • Clarifications on previous topics today – Splay tree deletion

Announcements • Participation due • Clarifications on previous topics today – Splay tree deletion – Universal Hashing

Guaranteeing O(n) time

Guaranteeing O(n) time

Birthday Paradox

Birthday Paradox

Universal Hashing (clarification)

Universal Hashing (clarification)

Computing the Optimal BST • How to compute cost? • Subtree at different depths

Computing the Optimal BST • How to compute cost? • Subtree at different depths

w(i, j)

w(i, j)

AST

AST

AST

AST

Example • Sequences/Probabilities

Example • Sequences/Probabilities

Leaves

Leaves

The Big Idea

The Big Idea

Subtrees with one key

Subtrees with one key

Subtrees with 2 keys

Subtrees with 2 keys

Solution

Solution

2 -3 Trees • A search tree • Properties

2 -3 Trees • A search tree • Properties

Insertion

Insertion

Deletion • Remove • Borrow • Coalesce

Deletion • Remove • Borrow • Coalesce

Remove

Remove

Borrow

Borrow

Coalesce

Coalesce

Generalizing/Example

Generalizing/Example