rec09 - Heap Algorithms Parent(A,i) // Input: A: an array...

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

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Heap Algorithms Parent(A,i) // Input: A: an array representing a heap, i: an array index // Output: The index in A of the parent of i // Running Time: O(1) 1 if i == 1 return NULL 2 return i/2 Left(A,i) // Input: A: an array representing a heap, i: an array index // Output: The index in A of the left child of i // Running Time: O(1) 1 if 2 ∗ i ≤ heap-size[A] 2 return 2 ∗ i 3 else return NULL Right(A,i) // Input: A: an array representing a heap, i: an array index // Output: The index in A of the right child of i // Running Time: O(1) 1 if 2 ∗ i + 1 ≤ heap-size[A] 2 return 2 ∗ i + 1 3 else return NULL Max-Heapify(A,i) // Input: A: an array where the left and right children of i root heaps (but i may not), i: an array index // Output: A modified so that i roots a heap // Running Time: O(log n) where n = heap-size[A] − i 1 l ← Left(i) 2 r ← Right(i) 3 if l ≤ heap-size[A] and A[l] > A[i] 4 largest ← l 5 else largest ← i 6 if r ≤ heap-size[A] and A[r] < A[largest] 7...
View Full Document

This note was uploaded on 11/11/2011 for the course MATH 180 taught by Professor Byrns during the Spring '11 term at Montgomery College.

Page1 / 2

rec09 - Heap Algorithms Parent(A,i) // Input: A: an array...

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

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