n
(correct) remove()
operations on a map that initially contains 2n
entries and
implemented with:
n × n
array
A
consists of 1's and 0's such that, in any row of
A
, all the 1's come before any 0's in that row. Assuming
A
is already in memory, describe a method running in
O(n log n)
time (not O(n2)
time) for
counting the number of 1's in A
.
h(k)
, we check
A[(h(k) + i2) mod N]
, for i = 1,2,...,N - 1
.
i2 mod N
will assume at most
(N + 1)/2
distinct values, for N
prime, as
i
ranges from 1
to N - 1
.
As a part of this justification, note that
i2 mod N = (N - i)2 mod N
for all
i
.N
, such that
N mod 4 = 3
and then to check the buckets
A[(h(k) ± i2) mod N]
as i
ranges from 1
to (N - 1)/2
, alternating
between plus and minus. Show that this alternate version is guaranteed
to check every bucket in A
.