Advanced Programming I Lecture Notes

Advanced Programming I Lecture Notes

2 March 2006 • Trees


Outline

Linked Lists Again

Fast Interior Access

Fast-Access Structure

Trees

Node Relations

Implementing Trees

Dynamic Implementation

Trees And Recursion

Binary Tree Operations

Binary-Tree Search

Binary-Tree Add

Removing Nodes

Binary-Tree Remove

Operation Performance

Binary Trees and Order

Binary Search Trees

Binary Search Tree Member

Binary Search Tree Add

Removing Nodes

Binary Search Tree Remove

node * remove(node * r)

  if r.left ≠ nil
    r.left = remove_max(r.left, r.data)

  or r.right ≠ nil
    r.right = remove_min(r.right, r.data)

  or
    delete r
    r = nil

  return r

Performance

Array-Based Trees

Binary Tree Indexing

Heaps

Heap Characteristics

Priority Queues

Heaps as Priority Queues

Example Enqueue