由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 一个data structure design的问题,求助
相关主题
上个Yahoo电面面经, 给恶心坏了。。还有两个题。
hashmap和hashtable的区别?求教一个onsite面试题目
请教一道数据结构的设计题也问一个算法题
google 一题关于anagram的老题?
google 面试题疑问A家onsite详细面经,求分析
Help, Algorithms questions一道电面题,分享下, 这个题应该用哪几个data structure?
一个小公司面经问道关于LRU的题目
问一道老题求leetcode LRU Java 解法
相关话题的讨论汇总
话题: data话题: array话题: structure话题: insertion
进入JobHunting版参与讨论
1 (共1页)
m*******i
发帖数: 370
1
Assume you have large set of data, say more than 100,000 elements. Each data
element has a unique string associated with it.
What data structures would you use in the implementation of a single new
data structure that has all of the following properties? Explain how this
implementation works.
i) Optimal algorithmic random access time to any element knowing only the
unique string associated with it (as above)
ii) Keeps track of the order of insertion into the data structure, so you
can acquire
r**u
发帖数: 1567
2
看看这样行不行,所有的elements都insert到一个array里,hash table里放element的
index。
给定一个unique string,先到hash table里找到index,再去array找到element。
另外,array是按insert顺序ordered,还可以用any index访问array里的任意元素。

data
the
the

【在 m*******i 的大作中提到】
: Assume you have large set of data, say more than 100,000 elements. Each data
: element has a unique string associated with it.
: What data structures would you use in the implementation of a single new
: data structure that has all of the following properties? Explain how this
: implementation works.
: i) Optimal algorithmic random access time to any element knowing only the
: unique string associated with it (as above)
: ii) Keeps track of the order of insertion into the data structure, so you
: can acquire

e********c
发帖数: 66
3
LinkedHashMap
m*******i
发帖数: 370
4
thanks! 应该是这个。不知道怎么implement的
是使用array吗?比如
MyClass* obj_ptr=new MyClass[N];
根据hash key insert to the array, 然后maintain pointer根据insert 的顺序指向
上一个insert的obj和下一个将要insert的obj?
不知道是不是这样?给解释一下吧,多谢!

【在 e********c 的大作中提到】
: LinkedHashMap
r**u
发帖数: 1567
5
hash_table 放index,
array放elements
hash_table and array are seperate.
key->(hash_table) get index, index->(array) get element.
你现在是要用俩种方式做索引,一种是用key and hash it,令一种是用array的index
,我觉得single DS只能做到用一种索引。

【在 m*******i 的大作中提到】
: thanks! 应该是这个。不知道怎么implement的
: 是使用array吗?比如
: MyClass* obj_ptr=new MyClass[N];
: 根据hash key insert to the array, 然后maintain pointer根据insert 的顺序指向
: 上一个insert的obj和下一个将要insert的obj?
: 不知道是不是这样?给解释一下吧,多谢!

e********c
发帖数: 66
6
Map.Entry has two attributes in HashMap. With LinkedHashMap, each
node has two additional fields: before and after to form a doubly linked
list. The implementation is the same as any Hashtable but you need to update
before and after nodes accordingly upon insertion and deletion.
You can take a look at the implementation in SUN's JDK source code.
s*****i
发帖数: 355
7
赞详细解答

update

【在 e********c 的大作中提到】
: Map.Entry has two attributes in HashMap. With LinkedHashMap, each
: node has two additional fields: before and after to form a doubly linked
: list. The implementation is the same as any Hashtable but you need to update
: before and after nodes accordingly upon insertion and deletion.
: You can take a look at the implementation in SUN's JDK source code.

m*******i
发帖数: 370
8
多谢!

update

【在 e********c 的大作中提到】
: Map.Entry has two attributes in HashMap. With LinkedHashMap, each
: node has two additional fields: before and after to form a doubly linked
: list. The implementation is the same as any Hashtable but you need to update
: before and after nodes accordingly upon insertion and deletion.
: You can take a look at the implementation in SUN's JDK source code.

b****r
发帖数: 1272
9
请问linksedHashMap对第三条怎么实现的:iii) Optimal algorithmic random access
time to any element knowing only the index of insertion.
given index, random access elem in linkedlist?

update

【在 e********c 的大作中提到】
: Map.Entry has two attributes in HashMap. With LinkedHashMap, each
: node has two additional fields: before and after to form a doubly linked
: list. The implementation is the same as any Hashtable but you need to update
: before and after nodes accordingly upon insertion and deletion.
: You can take a look at the implementation in SUN's JDK source code.

s*****i
发帖数: 355
10
first, it's a hashmap

access

【在 b****r 的大作中提到】
: 请问linksedHashMap对第三条怎么实现的:iii) Optimal algorithmic random access
: time to any element knowing only the index of insertion.
: given index, random access elem in linkedlist?
:
: update

相关主题
Help, Algorithms questions还有两个题。
一个小公司面经求教一个onsite面试题目
问一道老题也问一个算法题
进入JobHunting版参与讨论
x***y
发帖数: 633
11
I still don't get it....the index of the order is not the key, and then how
to use hashmap to access it in the constant time?

【在 s*****i 的大作中提到】
: first, it's a hashmap
:
: access

e********c
发帖数: 66
12
values() will return an array of contents in the LinkedHashMap in the
insertion order. You only need to call it once and the query will be O(1)
after the first call.
x***y
发帖数: 633
13
So, basically, LinkedHashMap realizes the 3rd property with an additional
array...
If insertion or deletion happens, we have to adjust array(call value())
again, right?

【在 e********c 的大作中提到】
: values() will return an array of contents in the LinkedHashMap in the
: insertion order. You only need to call it once and the query will be O(1)
: after the first call.

r********9
发帖数: 1116
14
mark
r********9
发帖数: 1116
15
mark
1 (共1页)
进入JobHunting版参与讨论
相关主题
求leetcode LRU Java 解法google 面试题疑问
LRU cache 问题Help, Algorithms questions
关于java synchronized statement和static method or variable一个小公司面经
类似LRU Cache的题应该怎么练习?问一道老题
上个Yahoo电面面经, 给恶心坏了。。还有两个题。
hashmap和hashtable的区别?求教一个onsite面试题目
请教一道数据结构的设计题也问一个算法题
google 一题关于anagram的老题?
相关话题的讨论汇总
话题: data话题: array话题: structure话题: insertion