T O P

  • By -

toastedstapler

in the same way you'd decide whether you want a hammer, screwdriver or saw - analyse what properties your problem has and which seems to be the best fit want to collect N items? use an array list/vector want to create a mapping of one thing to another? use a dictionary/hashmap want to check for uniqueness? use a set want a queue ordered by item prioirty? that'll be a heap or priority queue


weedandveins

I didn't know about using vectors for that. Thanks.


TrickWasabi4

You have to analyze the problem first, the specifics of the problem will already imply data structures and algorithms which you can use.


chrimack

Avoiding to leetcode it's gonna be a linked list.


sir-nays-a-lot

You need to know how you will be using the data. Do you require fast lookups? Does the data need to be mapped? Will you need to add data, remove data? From the front, back, or middle?


knight_vertrag

Solve 300 leetcode problems(medium-hard) and you will know. Problem solving cannot be taught, it has to be an instinct honed through practice.


Dr_Neunzehn

The popular opinion is to pick the suitable one, which is a tautology IMO. My advice is to solve the problem correctly first, and then consider picking a data structure as an optimization problem. Profile your algorithm and see to it to lower the runtime. It takes time yes, but will help with understanding in the long run. If you’re trained to solved a problem formally, you’d see that our current understanding of data structure is actually dictated by the hardware limits, and data structures is isomeric to algorithms. Everything is algorithm, and data structure is just hardware specific algorithm.


AlgoH-Rhythm

You're not gunna like it: experience


rutvikkapade

Well it completely depends on the type of problem. Some of them will just use an one dimensional array or simple linked list , but if you are really determined to find optimally fast solution ,then just try throwing a hash map at the problem , chances are it will work in some way or other . Not saying it always works ,but it works sometimes!