【发布时间】:2016-02-07 06:45:06
【问题描述】:
给定一个大小为 n 的方阵(数据结构),操作如下
read(i,j) returns the element
write(i,j,x) write the new element
initalize() set matrix to zero
并且读取和写入在(最坏情况)恒定时间内执行。 如何扩充它,以便在(最坏情况)恒定时间内执行以下操作?
emptyrow(i) if the ith row is empty then return true
emptycol(j) if the jth col is empty then return true
我的第一个想法是我不需要增强。我可以简单地使用一个 for 循环和 read(i,j) 来得到我的结果,在最坏的情况下将只是常数时间 n。我是在正确的轨道上还是我仍然需要以某种方式扩充数据结构。任何帮助表示赞赏,谢谢。
【问题讨论】:
标签: arrays data-structures time-complexity