AmortizedAnalysis

# Reada i return ith element of array writea i value

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: n ith element of array. ・WRITE(A, i, value): set ith element of array to value. Assumptions. true in C or C++, but not Java ・Can MALLOC an uninitialized array of length n in O(1) time. ・Given an array, can read or write ith element in O(1) time. Remark. An array does INIT in O(n) time and READ and WRITE in O(1) time. 3 Appetizer Data structure. Three arrays A[1.. n], B[1.. n], and C[1.. n], and an integer k. ・A[i] stores the current value for READ (if initialized). ・k = number of initialized entries. ・C[j] = index of jth initialized entry for j = 1, …, k. ・If C[j] = i, then B[i] = j for j = 1, …, k. Theorem. A[i] is initialized iff both 1 ≤ B[i] ≤ k and C[B[i]] = i. Pf. Ahead. 1 2 3 4 5 6 7 8 A[ ] ? 22 55 99 ? 33 ? ? B[ ] ? 3 4 1 ? 2 ? ? C[ ] 4 6 2 3 ? ? ? ? k=4 A[4]=99, A[6]=33, A[2]=22, and A[3]=55 initialized in that order 4 Appetizer INIT (A, n) READ (A, i) WRITE (A, i, value) ____________________________________________________________________________________...
View Full Document

## This document was uploaded on 02/05/2014.

Ask a homework question - tutors are online