c++ - What data structure can you use to store elements dynamically and access them efficiently? -


what data structure can use store elements dynamically , access them efficiently?this interview question. should answer std::list (i mean in c++)? or others?

as follow-up question, complexity of finding element in linked list in worst case?

thank opinions.

first question hash table. putting , getting elements using hash table o(1) in average case. linked list have worse case of storing in o(n) , worse case of access in o(n). array has worse case of storing o(1) , worse case of access in o(1). linked list can grow dynamically fast, array need allocate new , bigger array, , copy existing element on achieve dynamically growing capability.

for question 2, complexity of finding element in linked list o(n) since have iterate through elements in list in worse case (consider case element not in list).


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -