How to Deleting Array Element in O(1) Time
OriginalAbout 4519 words
Note
Now all the plugins has supported English. I'm still improving the website...
This article will resolve
LeetCode | Difficulty |
---|---|
380. Insert Delete GetRandom O(1) | 🟠 |
710. Random Pick with Blacklist | 🔴 |
Prerequisite Knowledge
Before reading this article, you need to learn:
This article discusses two data structure design problems that involve some clever techniques, both related to random element retrieval. I have also written about similar issues in the previous article Random Algorithms in Games.
One key point in these problems is how to combine hash tables and arrays so that the time complexity of the delete operation in the array also becomes O(1). Let's go through these problems one by one.