insert, delete, max in O(1)

后端 未结 8 1130
北海茫月
北海茫月 2020-11-29 17:42

Can someone tell me which data structure supports insert/delete/maximum operation in O(1)?

8条回答
  •  抹茶落季
    2020-11-29 18:12

    Like some have already pointed out, the question lacks some information. You don't specify were to insert/delete, nor the nature of the data we are dealing with.

    Some ideas that could be useful: You say,

    insert/delete/maximum operation in O(1)

    note that if we can insert, delete, and find maximun in O(1), then we can use this hipotetical technique to sort in O(n), because we can insert the n elements, and then take max/delete and we get them all sorted. It's proven that no sorting algorithm based in comparisons can sort in less than O(nlogn), so we know that no comparison based aproach will work. In fact, one of the fastest known ways of doing this is the Brodal queue, but it's deletion time exceeds O(1).

    Maybe the solution is something like a radix tree, were the complexity of all these operations is related to the key length as oposed to the amount of keys. This is valid only if they let you bound the key length by some other number, so you can consider it constant.

    But maybe it wasn't something that generic. Another interpretation, is that the insert/delete are the ones of a classic stack. In that restricted case, you can use the double stack solutiom that Can Berk Güder gave you.

提交回复
热议问题