二叉树,哈希表

There are many data structures commonly used as dynamic sets such as Binary Search Tree and Hash Table. The operations we need to support here are search() and insert(). For a self-balancing Binary Search Tree (TreeSet or TreeMap in Java), search() and insert() are both O(\log n)O(logn) time. For a Hash Table (HashSet or HashMap in Java), search() and insert() are both O(1)O(1) on average. Therefore, by using hash table, we can achieve linear time complexity for finding the duplicate in an unsorted array.
有许多数据结构常用作动态集,如二进制搜索树和哈希表。 我们需要在这里支持的操作是search()和insert()。 对于自平衡的二进制搜索树(TreeSet或Java中的TreeMap),search()和insert()都是O(\ log n)O(logn)时间。 对于散列表(HashSet或Java中的HashMap),search()和insert()平均都是O(1)O(1)。 因此,通过使用散列表,我们可以实现线性时间复杂度,以查找未排序数组中的重复数据。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容