Heap Sort - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Heap Sort

Description:

CS0447: Computer Organization and Assembly. Link for this ... sift(a, 0, end) end := end - 1. function sift(a, start, count) { var int root := start, child ... – PowerPoint PPT presentation

Number of Views:312
Avg rating:3.0/5.0
Slides: 12
Provided by: pani4
Category:
Tags: heap | sift | sort

less

Transcript and Presenter's Notes

Title: Heap Sort


1
Heap Sort
  • Panickos Neophytou
  • Recitation 2 09/19/2005
  • 09/21/2005

CS0447 Computer Organization and Assembly Link
for this presentation www.cs.pitt.edu/panickos/c
ourses/cs0447/heapsort.ppt
2
Heap
  • Definition A heap is a list in which each
    element contains a key, such that the key in the
    element at position k in the list is at least as
    large as the key in the element at position 2k
    1 (if it exists), and 2k 2 (if it exists)

3
Heap
4
Heap sort pseudocode
  • function heapSort(a, count)
  • var int start count 2 - 1, end count - 1
  • while start 0
  • sift(a, start, count)
  • start start 1
  • while end gt 0
  • swap(aend, a0)
  • sift(a, 0, end)
  • end end - 1
  • function sift(a, start, count)
  • var int root start, child
  • while root 2 1 lt count
  • child root 2 1
  • if child lt count - 1 and achild lt achild
    1
  • child child 1

5
Building a Heap
  • Build Heap
  • The above list is not a heap. Lets see how to
    build it into a heap

6
Building a Heap
7
Building a Heap
8
Building a Heap
9
Building a Heap
10
Building a Heap
  • Now, the list becomes a heap

11
Fibonacci
  • Write a recursive assembly program that
    calculates the Fibonacci numbers for a given
    integer n
Write a Comment
User Comments (0)
About PowerShow.com