views:

365

answers:

18

I've been studying my fundamental data structures a bunch recently, trying to make sure I've got them down cold.

By "fundamental", I mean the real basic ones. Fancy ones like Red-Black Trees and Bloom Filters are clearly worth knowing, but they're usually either enhancements of fundamental ones (Red-Black Trees are binary search trees with special properties to keep them balanced) or they're only useful in very specific situations (Bloom Filters).

So far, I'm "fluent" in the following data structures:

  • Arrays
  • Linked Lists
  • Stacks/Queues
  • Binary Search Trees
  • Heaps/Priority Queues
  • Hash Tables

However, I feel like I'm missing something. Are there any fundamental ones that I'm forgetting about?

EDIT: Added these after posting the question

  • Strings (suggested by catchmeifyoutry)
  • Sets (suggested by Peter)
  • Graphs (suggested by Nick D and aJ)
  • B-Trees (Suggested by tloach)
    • I'm a little on-the-fence about whether these are too fancy or not, but I think they're different enough from the fundamental structures (and important enough) to be worth studying as fundamental.
+9  A: 

Sets

As a principle I never say try [anySearhEngine] on it, but you can checkout this list : http://en.wikipedia.org/wiki/List%5Fof%5Fdata%5Fstructures

Peter
A Set is more a modelling construct than a fundamental data structure.
Hassan Syed
IMHO it is a very fundamental data structure
Peter
Oh wow. I did search for stuff like this (both on Wikipedia and Google), but somehow I didn't bump into this list. Thanks so much.
jboxer
A set it totally a fundamental data structure. It's not a list because elements cannot be repeated. It's not a mapping, it's only the keys of a mapping. It's very fundamental.
S.Lott
A set defines what it contains. I think as these definitions can be quite complex and because depend on arbitrary functions to define them, they should be considered too high level to be considered a fundamental data structure.
Hassan Syed
They do have implementations in lot of languages however
Peter
Yes, but data structures should be syntactic-sugar agnostic.
Hassan Syed
It is a mathematical concept, as syntactic agnostic as they come
Peter
often implemented as an iterface over a tree or hash table, but then you can argue that almost any structure is just some abstraction over arrays
jk
@Vainstah : btw even boolean algebra is dependend on it, a set might very well be one of the most fundamental data structures around
Peter
I think a set is a datastructure in much the same way as queues and stacks are. They're sort of "non-terminal" data structures. They can be represented in many different ways, but they should all provide a consistent interface.
Jason Baker
A: 

You've forgot the basic ones: struct, object and enums.

Thomas Jung
These constructs are language specific and may be serialized ontop of fundamental types.
Hassan Syed
I consider these to be data types, not data structures. I imagine there are great arguments on both sides, but I also know these cold, so it's irrelevant for my purposes. Good call though :)
jboxer
Structures are a kind of mapping from name to value. While the C-language `struct` is language-specific. The "record" (in COBOL or Pascal parlance) does exist in multiple languages. This is the basis for "class" definitions. So I would argue that it is not language specific, but exists almost everywhere.
S.Lott
I'm interested to hear about a programming language that does not support a struct-like construct!
Thomas Jung
+4  A: 

B-Trees and other multi-trees

tloach
B-Trees are covered, are you implying fancy ones ?
Hassan Syed
Vainstah: B-Trees are different from Binary Search Trees. Good call tloach, it's been awhile since I've refreshed myself on those.
jboxer
In that case they should be fancy according to his definition.
Hassan Syed
I think "fancy" and "fundamental" is a false dichtomy; B-Trees are both, since they are an absolutely essential component of pretty much any large database.
Michael Borgwardt
Also, they're interesting as an example for how a data structure can be optimized for performance under specific hardware constraints.
Michael Borgwardt
A: 

I would add maps unless you want to consider that to be under sets.

Glenn
A: 

Matrices since they serve as basis for modelling problems such as:

  • Graphs
  • Affine transformations
  • Solving linear systems
  • Markov chains
  • etc
dfa
Not fundamental imo as they can be emulated using arrays.
Hassan Syed
what can't be emulated using arrays?
jk
@jk everything can be, perhaps you should change the answer to be "sparse" matrices. These should not be emulated using arrays and I would think are fundamental.
Hassan Syed
+10  A: 

Also the Graph data structure is fundamental.

Nick D
Graphs are a mondelling construct and a data structure. +1
Hassan Syed
Awesome. I've been studying various graph algorithms, but I should refresh on the data structure itself.
jboxer
A: 

For help, read the Java Collections documentation. They break things down into an abstract tier (Set, List and Map) and an implementation tier (ArraySet, HashSet, ArrayList, LinkedList, TreeMap, HashMap).

For help, read the Python Collections documentation. They break things down into abstract base classes like Set, Sequence and Map which are built up from mixin features of a collection.

S.Lott
offtopic post, he is not asking about the names of programming manuals.
Hassan Syed
Sorry, but the reference material in these language references will answer the question.
S.Lott
Well most of those types exist to provide complexity guarantees, and as such are not fundamental. I doubt the manuals are going to be discussing the containers in a language neutral way either.
Hassan Syed
The "reading" part of the answer is central. Read the descriptions. Learn what other people thing fundamental data structures are.
S.Lott
@S. Lott --I agree, hardly off-topic. It's not like you're shilling for the publishers.
Klay
+2  A: 

Matrices

Graphs

aJ
+4  A: 

strings, although they may be implemented as arrays under the hood (as are several other data structures).

Any program that interacts with the user will use strings. It's important to know how to manipulate strings.

catchmeifyoutry
Variadic data types, lots of implementation cruft to be considered a fundamental data type.... but +1 as they are too important to ignore.
Hassan Syed
Fair enough. I'm a little on-the-fence about whether strings deserve separate consideration from arrays, but it can't hurt, especially since they're so important.
jboxer
+1  A: 

some may be considered less fundamental than others:

  • mathematical vectors/matricies
  • graphs, adjacency lists/matricies
  • tries prefix/suffix trees
  • spatial indexing - quad trees/ kd-trees r-trees
  • streams/ sequences null terminated strings / big ints
jk
There are quite fancy tho :/
Hassan Syed
+2  A: 

Quadtrees, as the most simple kind of spatial index.

Michael Borgwardt
interesting and complex, but imo as it applies closely to 2-d space it is fundamental.
Hassan Syed
might I also suggest R-trees or QR-trees? they're an interesting extension of quadtrees. http://en.wikipedia.org/wiki/R-tree
rmeador
ok, to clarify, the R-tree is more like an extension of a B-tree, and the QR-tree is a fusion of a quadtree and an R-tree
rmeador
Those are very specific to GIS.
wheaties
Not at all specific to GIS, useful anywhere you have 2-d data
jk
+1  A: 

Bit array is not fundamental but it is very handy and it can represented efficiently using integers (and bitwise operators)

dfa
+1 use them everyday- very easy and fast!
0A0D
A: 

You might consider union/find datastructures. They are fundamental to some graph algorithms.

Jason Baker
+1  A: 

Associative Array is the generic way of saying Dictionaries, Maps, etc. You can find this in almost every framework.

http://en.wikipedia.org/wiki/Associative_array

Matt Dotson
+1  A: 

Tuples.

Also, if I could nominate one not-basic data structure, it would be the persistent bit-partitioned prefix Hash Tries from Clojure. In general, I believe persistence to be a very important and often overlooked property of any data structure.

Jörg W Mittag
+1  A: 

Cons cell. With that you can build several other data structures (lists, trees, etc.)

http://en.wikipedia.org/wiki/Cons

z5h
+1  A: 

i think your question is unclear, because you're mixing implementation and purpose ...

the following types describe implementation:

  • linked list
  • double linked list
  • skip list
  • array
  • dynamic array
  • hash table
  • (binary) tree
  • "managed" (binary) trees (heaps, leveled trees etc., i.e. trees where insertion and deletion is not done directly but through a procedure that guarantees certain constraints for the tree)
  • graph (although very fancy)

the following describe purpose:

  • stack (means FILO & can be implemented by a linked list, but also with an array or vector)
  • queue (means FIFO & can be implemented by a double linked list, or maybe in other sensible ways)
  • dequeue (...)
  • priority queue (means "Highest/Lowest Key First Out" this is an abstract concept, that can be implemented in many different ways)
  • map/associative array/dictionary (means you map keys to values. often requires an extra function to convert keys into valid keys for the underlying hash table or tree)
  • set (means, it's a collection, that is iterable and can tell, whether a value is an element of the set or not. every value, that is an element of the set must apear exactly once during iteration. a set may be mutable, or not (may allow to add or remove elements). routines for intersection, union, difference may be provided (e.g. as methods in OOP). when it comes to implementation, there's a number of possibilities)

well, there'd be one last thing I consider very much worth mentioning: algebraic data types ... depending on the language, they either exist natively, or you have to emulate them ... haXe and C# (as far as I've heard) would be two imperative languages offering them by simply allowing parameters for enums ... they can be used to implement lists, trees and many other nice things ... for example, they are perfect to represent ASTs and a lot of other complex structures ...

greetz

back2dos

back2dos
I understand what you're saying, but they are still distinct data structures; you can be well-versed in linked lists, arrays, and other ways to implement stacks without understanding stacks themselves, and you can be well-versed in stacks without understanding their implementations.I'm attempting to list the fundamental data structures, whether they're implementations or interfaces.
jboxer
A: 

A "function object", "function pointer", or "closure" can't be implemented in certain restrictive languages that have arrays, linked lists, etc. But perhaps they are closer to data types rather than data structures.

The "rope" implementation (as implemented in the "cord" library) is my favorite implementation of the "string" abstract data structure, but perhaps it's not really "fundamental".

David Cary