求助一个算法问题!N+K Algorithm Creation
Suppose you are given n+k words of memory to use and a sequence of n INSERT, DELETE, and MEMBER operations to process. The integers 1 through k are the values of the operations (e.g., INSERT 1, MEMBER k,...). Explain how to do each of the three operations in constant time, using at most a constant amount of additional storage space beyond the alloted n+k words.
Note: You cannot use preprocessing to initialize memory.
假设有n+k的内存空间,运行n次操作INSERT, DELETE, and MEMBER等。操作的对象是1到k的整数。
INSERT 1 是插入1
DELETE 1 是删除1
MEMBER 1 则return 1 是否已经在内存中,是return true,否return false
设计算法是这三种操作在常数时间内完成。在n+k内存空间之外最多允许使用的额外空间为常数,常熟不随n,k变化而变化
注:不允许预先初始化内存空间。
先谢过啦!!!