请教一下,多谢# Living
f*w
1 楼
Assuming that you are only allowed a constant amount of time for
initialization, design a representation for a table that allows one to
search, insert, and delete values in worst case time O(1), assuming that
each value is in the range 1 to m.
You may assume that no more than n insertions will be done and, that m+n + c
units of
space are available for you to use, where c is a small constant of your
choosing (e.g. 3 or 4).
Note that in this problem m and n are problem inputs, hence they are not
constants, hence initializing the entire space is not allowed, since that
would require time O(m+n).
我开始想的是初始化一个m维数组存个数……但人家说了m不是常数,不能直接这样分配
initialization, design a representation for a table that allows one to
search, insert, and delete values in worst case time O(1), assuming that
each value is in the range 1 to m.
You may assume that no more than n insertions will be done and, that m+n + c
units of
space are available for you to use, where c is a small constant of your
choosing (e.g. 3 or 4).
Note that in this problem m and n are problem inputs, hence they are not
constants, hence initializing the entire space is not allowed, since that
would require time O(m+n).
我开始想的是初始化一个m维数组存个数……但人家说了m不是常数,不能直接这样分配