20

When programmers talk about "data structures", are they only talking about abstract data types like lists, trees, hashes, graphs, etc.?

Or does that term include any structure that holds data, such as composite types (class objects, structs, enums, etc.) and primitive types (boolean, int, char, etc.)?

I've only ever heard programmers use the term to reference complex data structures or abstract data types, however the Wikipedia article that provides a list of data structures includes both composite types and primitive types in the definition, which is not what I expected (even though it does make sense).

When looking around online I see other places that refer to the term "data structure" in the programming sense as only referring to abstract data types, such as this lecture from Stony Brook University's Department of Computer Science which states

A data structure is an actual implementation of a particular abstract data type.

or this wikibook on data structures, which uses the term in sentences like this:

Because data structures are higher-level abstractions, they present to us operations on groups of data, such as adding an item to a list, or looking up the highest-priority item in a queue

So why do I only ever hear programmers referring to complex data structures or abstract data types when they use the term "data structure"? Do programmers have a different definition for the term than the dictionary definition?

11
  • 1
    The term evolved over time. The CS crowd normally uses the term for generic types of structures that can hold multiple items of related data (linked lists, trees etc...)
    – Oded
    May 9, 2012 at 13:45
  • 2
    isnt it just a terminology thing? a string is actually an array of chars, and it's a data structure which represents a sequence of individual charachters
    – Mithir
    May 9, 2012 at 13:46
  • 4
    Isn't "data structure" a self-defined term? It's any structure for storing data! It's kind of hard to take the question seriously.
    – Michael K
    May 9, 2012 at 14:12
  • 1
    @Rachel So your question is actually whether primitive data types are data structures or not? if programmers mean something different when they talk about data structures is still polling for opinions though.
    – yannis
    May 9, 2012 at 14:15
  • 2
    "Primitive" completely depends on scope. At the binary level there is no such thing as an int, for example. At an even lower level there aren't even bits - just electrical bias. Again, this is a self defining term - not a good question at all.
    – Michael K
    May 9, 2012 at 14:17

3 Answers 3

21

The generic definition of "data structure" is anything that can hold your data in a structured way, so yes this would include composite types and primitive types in addition to abstract data types. For example, a string is a data structure as it can hold a sequence of characters in a structured way.

However, the term also has another meaning to programmers.

Since the term "data structures" is so broad, developers usually use a more specific term to identify what they are talking about, such as class or data object or primitive type, and the specific term used for most complex or abstract data types is "data structure"

This is why you hear "data structure" most frequently being used for abstract data types like Arrays, Lists, Trees and Hashtables, and not for things like primitive data types

20
  • 4
    I think graphs are very common too but they are just rarely represented in standard libraries because they are very hard to build in a generic and efficient way.
    – Klaim
    May 9, 2012 at 13:52
  • So when programmers talk about "data structures", they're usually talking about abstract data types? And although primitive types (such as int, bool, or char) and composite types (like a class, struct, or enum) are still considered data structures by programmers, they are usually referred to by different terms?
    – Rachel
    May 9, 2012 at 13:57
  • 1
    @Rachel technically a data structure could be a homebrewed implementation using pointers/classes ect too. I made some very ugly "data structures" similar to lists as part of a C++ homework assignment. We just don't call classes data structures as often because they're usually something more specific.
    – Ben Brocka
    May 9, 2012 at 14:07
  • @BenBrocka Ahhh so "data structure" is a very broad term which does cover these other objects, however its typically better to be more specific when talking about data structures and to use terms like "primitive data type" or "data object" instead of "data structure". And the commonly used specific term for objects like Lists, Trees, Graphs, etc just happens to be "data structures"
    – Rachel
    May 9, 2012 at 14:11
  • 1
    @Rachel yes, even though everything is a data structure (strictly speaking) the term 'data structure' usually refers to those abstract data types. I'd say the term 'data structure' from a developer's perspective refers to how he's storing the data. It could be a in memory list, a file in the disk or could be a custom data structure he implemented himself.
    – Alex
    May 9, 2012 at 14:13
5

The term refers to both, though things like ints and booleans are typically considered primitive data types (or primitive data structures). The term itself simply referes to anything that stores data in a specific way. Certainly int meets this definition just as well as something like a Hash table, only it's simpler.

Typically, when people use data structure, they refer to more complex data structures, and not the simpler ones but both meet the definition.

2
  • 2
    I don't think I've ever heard someone refer to an int as a "data structure".
    – Qwertie
    May 9, 2012 at 16:12
  • 2
    @Qwertie me neither, but that's still what it is. It's called a "data type" more often, but that pretty much means the same thing as "data structure"
    – Oleksi
    May 9, 2012 at 16:14
0

The simplest and very basic definition, which I have ever heard of data structures, is storing data into the memory in such a way that basic operations like insert, update, delete etc can be performed in an efficient way in terms of time and memory.

So, a data type tells the type of data we have stored into it. It can be integer, decimal, character , string or an object. This can be composite types or primitive types in addition to abstract data types.

But, we use data structures when we want to store any complex data in the memory. This is the reason why we hear only about data types like Arrays, Lists, Trees and Hashtables, and not for things like primitive data types

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.