CSE 250: Data Structures Week 7 February 25 - 29, 2008

advertisement
CSE 250: Data Structures
Week 7
February 25 - 29, 2008
Announcements
Homework 3 due 2/29
Midterm 3/3
Project 2 due 3/7
Resign Deadline 3/28
CSE Mentors Lunchtime Chat
Wednesday 3/5 at noon in 224 Bell
Panel discussion with senior undergrad
CS/CEN majors
Week’s Notes
Finished Implementation of AVL Tree
Defined Splay Trees
In-class example of splaying
Introduction to B-Trees
Week’s Notes
Heaps support two main operations:
deleteMin
Insert
Can implement on:
List – not very efficient
Binary Tree – could suffer performance issue if
unbalanced
Balanced Tree
Week’s Notes
We’ll really use a new structure – a Binary
Heap
Binary Heap maintains two invariants:
Structure
Heap order property
Week’s Notes
Heap uses a complete binary tree – all
previous levels must be filled before
adding nodes to the next level.
Lowest level filled left to right.
We can actually use an array as the
underlying implementation for the heap.
Week’s Notes
If we use the array, we need to note the
following:
At index i:
The left child of i is in 2i
The right child of i is in 2i + 1
The parent of i is in floor(i/2)
Week’s Notes
The heap order property is that the
smallest element is stored at the root and
each child of any root of a heap should
also be a heap.
Download