Lecture7

Lecture7 - Lecture 7, Oct. 12, 2010 Data Structures - Heaps...

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

View Full Document Right Arrow Icon
1 84 Data Structures - Heaps We will be developing data structures that support queries and updates . Example where a (priority queue) data structure will help: » Event driven system- simulating phone calls of known length » event: (start of call i , time when i starts) (end of call j , time when j ends) » Processing a new call introduces 2 events - start and end . » Simulator: pick next event , process it, maybe update event queue. » How to maintain events ? Need support for fast: enter new event pick “next event”, i.e. event with smallest time key. Lecture 7, Oct. 12, 2010 85 Several possible approaches Keep all events in a list . » Easy to insert - O(1) » hard to extract - (n) Sorted list : » Easy to extract - O(1) » Hard to insert - (n) We would like something like: » insert O(lg n) » extract O(lg n) Explain why ! Explain why ! Tradeoff
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 86 Heaps Nearly complete binary tree with: Claim: max is at the root (by induction on the size of the heap) Pointers are not the most efficient solution.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/08/2011 for the course CS 161 at Stanford.

Page1 / 5

Lecture7 - Lecture 7, Oct. 12, 2010 Data Structures - Heaps...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online