Cse 326 data structures lecture 5 heaps more
Download
1 / 13

CSE 326: Data Structures Lecture #5 Heaps More - PowerPoint PPT Presentation


  • 118 Views
  • Uploaded on

CSE 326: Data Structures Lecture #5 Heaps More. Steve Wolfman Winter Quarter 2000. We get slide printouts every class. 4 pages of notes per day  50 students  3 lectures per week  10 weeks per quarter  engineer’s fudge factor  10,000 pages one 60 foot pine tree  80,000 pages

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' CSE 326: Data Structures Lecture #5 Heaps More' - cecily


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Cse 326 data structures lecture 5 heaps more

CSE 326: Data StructuresLecture #5Heaps More

Steve Wolfman

Winter Quarter 2000


We get slide printouts every class
We get slide printouts every class

  • 4 pages of notes per day  50 students  3 lectures per week  10 weeks per quarter  engineer’s fudge factor  10,000 pages

  • one 60 foot pine tree  80,000 pages

  • Frankye Jones’s frantic effort = one paycheck for Steve

  • paycheck + www.americanforests.org = 1 tree / $1

  • How about two trees per person?


Today s outline
Today’s Outline

  • Things Steve Didn’t Finish on Wednesday (Heaps)

  • Extra heap operations

  • d-Heaps

  • Return Quizzes


Other priority queue operations
Other Priority Queue Operations

  • decreaseKey

    • given a pointer to an object in the queue, reduce its priority value

  • increaseKey

    • given a pointer to an object in the queue, increase its priority value

  • remove

    • given a pointer to an object in the queue, remove it

  • buildHeap

    • given a set of items, build a heap


Decreasekey increasekey and remove
DecreaseKey, IncreaseKey, and Remove

void decreaseKey(int obj) {

assert(size >= obj);

temp = Heap[obj];

newPos = percolateUp(obj, temp);

Heap[newPos] = temp;

}

void increaseKey(int obj) {

assert(size >= obj);

temp = Heap[obj];

newPos = percolateDown(obj, temp);

Heap[newPos] = temp;

}

void remove(int obj) {

assert(size >= obj);

percolateUp(obj,

NEG_INF_VAL);

deleteMin();

}


Buildheap floyd s method thank you floyd
BuildHeapFloyd’s Method. Thank you, Floyd.

12

5

11

3

10

6

9

4

8

1

7

2

pretend it’s a heap and fix the heap-order property!

12

5

11

3

10

6

9

4

8

1

7

2


Build this heap
Build(this)Heap

12

12

5

11

5

11

3

10

2

9

3

1

2

9

4

8

1

7

6

4

8

10

7

6

12

12

5

2

1

2

3

1

6

9

3

5

6

9

4

8

10

7

11

4

8

10

7

11


Finally
Finally…

1

3

2

4

5

6

9

12

8

10

7

11

runtime:


Thinking about heaps
Thinking about Heaps

  • Observations

    • finding a child/parent index is a multiply/divide by two

    • operations jump widely through the heap

    • each operation looks at only two new nodes

    • inserts are at least as common as deleteMins

  • Realities

    • division and multiplication by powers of two are fast

    • looking at one new piece of data sucks in a cache line

    • with huge data sets, disk accesses dominate


Solution d heaps
Solution: d-Heaps

1

  • Each node has d children

  • Still representable by array

  • Good choices for d:

    • optimize performance based on # of inserts/removes

    • choose a power of two for efficiency

    • fit one set of children in a cache line

    • fit one set of children on a memory page/disk block

3

7

2

4

8

5

12

11

10

6

9

12

1

3

7

2

4

8

5

12

11

10

6

9


One more operation
One More Operation

  • Merge two heaps. Ideas?


To do
To Do

  • Turn in Project I (due today)

  • Start on Homework II (due Jan 20th)

  • Read chapter 6 in the book


Coming up
Coming Up

  • Mergeable heaps

  • Dictionary ADT and Self-Balancing Trees

  • First project due (January 14th)

  • A day off (January 17th)!

  • Second homework assignment due (January 20th)


ad