which data structure to use, and when

S

sakcee

Hi

I hope that I can learn from your experience . I want to know if you
have seen a perticular problem and used a perticular data structure ,
and why?

I usually end up using just arrays, ArrayList, or hash maps for most
of day to day work.
If there is a perticular algorithm needs to be implemented then I try
to think of trees or linked list.

I was wondering how do you decide , which one is better. what are the
tradeoffs.

thanks
 
V

Victor Bazarov

I hope that I can learn from your experience . I want to know if you
have seen a perticular problem and used a perticular data structure ,
and why?

Find a copy of "C++ Data Structures" book and try reading. Couldn't
hurt. Also, see "Effective STL" for recommendations on how to choose
standard containers.

I've seen so many particular problems and used so many particular data
structures and it would take me a month to type them all up (that is
if I can remember).
I usually end up using just arrays, ArrayList, or hash maps for most
of day to day work.

Lucky you.
If there is a perticular algorithm needs to be implemented then I try
to think of trees or linked list.

Do you usually succeed?
I was wondering how do you decide , which one is better. what are the
tradeoffs.

Algorithms are usually written around some kind of collection, and
different collection can fit the bill. The performance requirements
are usually the deciding factor when more than one data structure is
capable of just doing the grunt work. See the "Effective STL" and
other books in its bibliography.

V
 
M

Mark P

Hi

I hope that I can learn from your experience . I want to know if you
have seen a perticular problem and used a perticular data structure ,
and why?

Ever? You must be joking...
I usually end up using just arrays, ArrayList, or hash maps for most
of day to day work.
If there is a perticular algorithm needs to be implemented then I try
to think of trees or linked list.

What are you programming? I suppose it's conceivable that arrays and
hashes are sufficient for what you do, but for a great many of us
they're not.
I was wondering how do you decide , which one is better. what are the
tradeoffs.

Cost-benefit analysis, basically. What features does the data structure
provide, what the are costs (time, space, etc.) to using them, and how
well does this combination suit the particular algorithm I have in mind?
 
J

Jim Langston

Hi

I hope that I can learn from your experience . I want to know if you
have seen a perticular problem and used a perticular data structure ,
and why?

I usually end up using just arrays, ArrayList, or hash maps for most
of day to day work.
If there is a perticular algorithm needs to be implemented then I try
to think of trees or linked list.

I was wondering how do you decide , which one is better. what are the
tradeoffs.

thanks

Nowadays I only use arrays for const data, that is when I know both the size
and the contents at compile time, otherwise I use std::vector.

I normally use vector or map in day to day programming, although I have use
queue on one occasion for messaging between threads (encapsulated within a
class with locking of course). I've not yet found a use for the other
containers in my day to day programming.

Is this what you were asking?
 
S

sakcee

Yes, thanks

I also have not used other data structures much, that is why I was
wondering how other people use it.
queue as you mentioned , for thread messaging, priority for worker type
threads etc

lists for random insertion or deletion within bunch of records.

probably tree for reading data from files and storing them for
particular arrangement e.g. sorted.

One programmer in my company implemented multilevel access control
hierarchy with some tree structure.

I have yet to encounter a graph related problem at work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,775
Messages
2,569,601
Members
45,182
Latest member
alexanderrm

Latest Threads

Top