Work Note 8, DM803, fall 2016

Exercises November 3

  1. Some of you have likely heard of the array doubling technique. Here we will prove that it works. We work with arrays of sizes that are powers of two. We want arrays because we want to be able to perform look-ups and updates in constant time. Now, we also want to append, i.e., extend our array by one extra entry. If the number of elements, n, is not a power of two, there are unused entries in the array and we just increment n and use the next entry. Otherwise, the array is filled up, and we allocate a new array of double the size, move all elements to the new array, and deallocate the old array (this just means that we inform the operating system that we will not use it again and so it does not count as space we are using). Define a potential function and show that we can implement append in amortized constant time. What is the space overhead?

    Now we also want to be able to shrink the array by one from the end, i.e., a reverse operation to append. It could make sense to refer to the operations as push and pop instead. Decide on a strategy for when to reallocate to a smaller array so that the space overhead is O(n) and such that you can define a potential function and show that push and pop (any mix of these) are both amortized constant.

  2. Now, we want to do the same as above, supporting push and pop, but we want all times to be worst-case instead of amortized. To that end, we must anticipate reallocation to smaller and larger arrays and get it done gradually. This will increase our space overhead, but it should still be O(n). Devise an algorithm and argue that it works. (Doing something like this is referred to as global rebuilding.) What is your space overhead?
  3. Review the lower bound argument on page 55 of [M??]. Is there an underlying assumption in establishing this Ω(√n) lower bound?
  4. In [M??], we compute ⌊log n⌋ in constant time using a table of size n. Could we do it in constant time using a table of size n?
  5. We will wrap up the discussion of dynamization and 2-d trees.

Lecture November 7

Announcement


Last modified: Mon Nov 28 09:04:29 CET 2016
Kim Skak Larsen (kslarsen@imada.sdu.dk)