views:

607

answers:

32

We all, as programmers, have something that we really like and always when we are trying to solve a problem we would like to solve it on our personal choice of programming language/algorithm.

But the question that I've chatted with other developers at work about, was "Which is your favorite data structure" so I've met developers who was using arrays and didn't want to hear about other data structures but some others like me who was using linked lists.

I know sometimes you have to choose a data structure which will fit on the solution but sometimes you love one and you use it at every time you have to store some data in memory.

So please don't start a flame war or something but I didn't find some similar question like this and I started up this question.

So folks which is your favorite data structure? I am a big fan of linked lists.

+5  A: 

List<T> in c#

lomaxx
This is an implementation of a data structure!
Ali A
+1  A: 

I typically wind up using the equivalent of a hash of hashes of hashes...up to however many dimensions I need. At least while I am developing. After I get the data shape riht in my mind I might change it.

EBGreen
"After I get the data shape riht in my mind I might change it" ? wtf? how about getting the design right up front!
Mitch Wheat
Perhaps I should have been more clear. If the design clearly indicates the data structure then I use whatever fits best. If however I'm doing a quick adhoc app/script where rapid development is more important that efficiency, then I use an adhoc data structure.
EBGreen
I concur... how many times do you need to write something *RIGHT NOW*, and don't have time for legit planning? Certainly lots of one-off scripts are in that category. Or, you might plan it, then end up needing to refactor/redesign later
warren
Generally speaking it is a "we need something working now" item that will only be used once...then it is used once a day forever, so I refactor it at that time.
EBGreen
A: 

As a Silverlight and WPF(.NET3.0) developer I like the "ObservableCollection<T>" - it is nothing but a special List<T> which helps in XAML bindings

Jobi Joy
+4  A: 

In C, my favorite data structure is void *; it's just so darn flexible.

paxdiablo
I like a little more structure in my data structures.
tvanfosson
I prefer void over void*. ;)
dalle
A: 

If I had to pick, it's the lowly array - simple, fast, and cheap.

Honestly, though - I don't care: I use the one I need for the job at hand :)

warren
+7  A: 

Each one has it's advantages and disadvantages. I try to pick the one that's suited to the requirements of where I'm using it... depending on size, expected usage, Do I only need to iterate through it? Only in one direction? Do I need to add, remove items dynamically, FIFO or LIFO, Do I need to be able to search it ? treat it as an array? etc..

Charles Bretana
Right. I don't ask my doctor what's his favorite medicine.
Mike Dunlavey
Or yr dentist which is his favorite tooth
Charles Bretana
A: 

I'm a really big fan of a two-dimensional 2x3 six-pack array. :)

Mr. Brownstone
+1  A: 
IDictionary<string,Delegate>

for 'touch-up' work

Steven A. Lowe
+2  A: 

I recommend the humble, null-terminated string.

tvanfosson
I almost always prefer strings that know their own size.
Jimmy
... and know their limitations
Charles Bretana
A: 

In C# any form of generics e.g. List, Dictionary etc

John_
+1  A: 

python tuple

Alan
+6  A: 

Very strange question... You use whatever is best suited for the task at hand...

ykaganovich
I agree with you... it's like asking about your favorite color =)
Zach Scrivena
I like to fly an airplane. But I don't use it to go to the grocery store. I've seen junior programmers sneer at arrays just because they were arrays, not lists.
Mike Dunlavey
+3  A: 

I like the trie data structure, because it makes everyone say "Don't you mean tree?"

Bill the Lizard
...and that always reminds me of the Knights who say "Ni!"
Bill the Lizard
I would have mentioned Trie, had not you done it already.
Winston Smith
+1  A: 

Triple graph.

Ali A
+3  A: 

I'm surprised nobody has mentioned the Stack.

It's so versatile and elegant it can even be used as a memory architecture as in a Stack Machine as well as every day programming tasks.

Shatrat
A: 

This is nothing fancy, but I've found the TStringList in Delphi to be very handy.

It is basically an array of strings, with Insert, Delete, and IndexOf methods - not too different from the C# stringlist.

From a theoretical point of view, I always found binary trees to be a really elegant structure. I like them, even though I almost never have to use them.

JosephStyons
A: 

I don't use them very often but I love them,

C#:

  • LinkedList<T>
  • Stack<T>
  • Queue<T>
CMS
+1  A: 

Heaps.

I used to use these all the time for task queues on microcontrollers. Fast and compact.

finnw
A: 

XMLHttpRequest - The class that powers most AJAX-y functionality.

Dictionary is a close second, though.

As for the array vs linked list, I tend to find this to be much more specific implementation details than abstract concepts like a Stack or Queue. Of course I do remember learning how to use linked lists and arrays to implement the functionality of Stacks and Queues and this may cause me to have a different take than most others.

JB King
A: 

Python dictionary, or any kind of map structure in any language. It helps me to prototype the classes without the syntactic overhead and later on I can refactor to classes. The more dynamic type system the language has, the merrier I am with the maps.

utku_karatas
+2  A: 

Hands down: the Dict. Any language that lacks a good Dict with a syntactically pleasant foreach is crippled.

ben mcgraw
A: 

Python Dicts and Lists.

Corey Goldberg
A: 

I like arrays, there fast and simple.

Jared
A: 

favorite little-known data structure: skip lists

I haven't had occasion to use it much but Java 1.6 has an implementation ConcurrentSkipListMap.

Otherwise I like STL's std::deque; you get amortized O(1) performance for both insertion/deletion at either end, as well as random access (but not insert/delete) for any element if you know the index.

Jason S
A: 

How about a nice streamed ResultSet. Lots of data, coming from a db, its a happy place.

Nathan Feger
A: 

Graphs.

Such a versatile data structure when showing relationships between things. Graphs have a huge wealth of algorithms that can be used on them as well.

  • Need directions to get to your friends house? A path finding algorithm is used on a graph of the roads/intersections to find the fastest route.

  • Need to find the best way to route network traffic across a bunch of connections? The graph is your friend.

  • Want to implement a neural network to attempt to solve some interesting problem? Graphs again.

Steve Yegge briefly talks about them in his article Get That Job At Google:

Whenever someone gives you a problem, think graphs. They are the most fundamental and flexible way of representing any kind of a relationship, so it's about a 50-50 shot that any interesting design problem has a graph involved in it. Make absolutely sure you can't think of a way to solve it using graphs before moving on to other solution types. This tip is important!

Simucal
A: 

I like java.util.Collection, myself.

Adam Jaskiewicz
A: 

Python lists and dictionaries

pistacchio
A: 

I like the hypergraph. :)

Eduardo León
+2  A: 

I've come to the view that a big problem in programming is confusion between means and ends. Data structures are ways to accomplish things, not ends in themselves.

What I prefer to see in a programmer is knowledge of a variety of techniques and wisdom about how to match them up to the requirements of any given problem.

If you are sick and go to the doctor, do you want to hear all about the wonderfulness of different kinds of medicines and treatments, and which ones he thinks are really nifty?

No, you want him to be good at understanding what your specific problem is so he can apply just the right treatment, and as little of it as necessary.

Mike Dunlavey
A: 

ThreadSafeObservaleCollection<T> - custom. Dispatches events to the UI thread.

IDictionary<string, Delegate>, IList<T>

Oleg
A: 

I was thinking about asking a question much like this one, but I'll just chime in with my 2 cents instead. I'd say my favorite three are the Bloom Filter, Radix Tree and Judy Array.

I've used bloom filters in a variety of ways ranging from social graph subgroup memberships to spam detection systems. There are some really great articles explaining how and why they work and what you can do with them too.

Radix trees are great for things like type-ahead engines and space-effecient dictionary-like systems.

Its unfortunate that Judy arrays don't get more attention than they do. These small data containers are blazing fast, although more complex than other similar data structures.

Nick Gerakines