由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 谁来解释下hashtable的iterator是怎么实现的
相关主题
hash_map 的遍历问题hashmap和hashtable的区别?
hashtable的遍历问道大数据的题
问道题目 Map的iterator请教一道LinkedIn面试的经典题
贡献Amazon的电面经验问道关于LRU的题目
Bloomberg 电面问一下STL里的queue, and stack 遍历的问题
算法题an interview question, find mode in a rolling window along data sequence
解法讨论:(给定一个array和一个target,找出是否存在两个数之和为target)Leetcode: Symmetric Tree有没有好的iterative的解法?
又一道linkedin题请教为什么这段程序运行不work?(doubly linked list) (转载
相关话题的讨论汇总
话题: hashtable话题: bucket话题: 释下话题: iterator话题: 来解
进入JobHunting版参与讨论
1 (共1页)
M*******a
发帖数: 1633
1
应该是遍历一下O(n)的时间复杂度,n应该是现有元素个数。
k***g
发帖数: 166
2
C++路过
s**x
发帖数: 7506
3
Linkedlist 呗,very simple.
Remember how LRU cache is implemented? A hash table plus linked list.
z******g
发帖数: 271
4
C路过
But if I were to do it, I would make the iterator data structure contain the
bucket size, a bucket cursor and a reference to the underlying linked list
node. The worst case time complexity would be O(m + n) where m is the bucket
size.
w**z
发帖数: 8232
5
一个一个bucket 走,每个bucket 都走一遍linkedlist
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/

【在 M*******a 的大作中提到】
: 应该是遍历一下O(n)的时间复杂度,n应该是现有元素个数。
M*******a
发帖数: 1633
6
我也这么想的,但是好像实现的有点overhead,相当于任何hashtable实际都是个
linked hashtable.

【在 s**x 的大作中提到】
: Linkedlist 呗,very simple.
: Remember how LRU cache is implemented? A hash table plus linked list.

M*******a
发帖数: 1633
7
这样的话貌似就不是O(n)的iterate了,假设这个hashtable初始的size为100,然后只
有2个元素,这样iterate的话是O(100)而不是O(2)

【在 w**z 的大作中提到】
: 一个一个bucket 走,每个bucket 都走一遍linkedlist
: http://grepcode.com/file/repository.grepcode.com/java/root/jdk/

w**z
发帖数: 8232
8
HashMap 本来就不适合 iterate

【在 M*******a 的大作中提到】
: 这样的话貌似就不是O(n)的iterate了,假设这个hashtable初始的size为100,然后只
: 有2个元素,这样iterate的话是O(100)而不是O(2)

w**z
发帖数: 8232
9
LS说了, O(m + n)

【在 M*******a 的大作中提到】
: 这样的话貌似就不是O(n)的iterate了,假设这个hashtable初始的size为100,然后只
: 有2个元素,这样iterate的话是O(100)而不是O(2)

1 (共1页)
进入JobHunting版参与讨论
相关主题
请教为什么这段程序运行不work?(doubly linked list) (转载Bloomberg 电面
无名小公司 :: 软件设计工程师 :: 面经算法题
谁有那个 nested hashmap iteration 的讨论阿?解法讨论:(给定一个array和一个target,找出是否存在两个数之和为target)
请教个面经里的设计题又一道linkedin题
hash_map 的遍历问题hashmap和hashtable的区别?
hashtable的遍历问道大数据的题
问道题目 Map的iterator请教一道LinkedIn面试的经典题
贡献Amazon的电面经验问道关于LRU的题目
相关话题的讨论汇总
话题: hashtable话题: bucket话题: 释下话题: iterator话题: 来解