DesirePRG
DesirePRG

Reputation: 6378

is Tree, a data structure or abstract data type?

I hear many people referring tree as a data structure. But trees are mostly implemented using Linked Lists, or Arrays. So does it make it an abstract data type?

Given a type of structure, how can we determine whether it is a data structure or abstract data type?

Upvotes: 2

Views: 4379

Answers (1)

longtengaa
longtengaa

Reputation: 300

If you are talking about a general Tree without specifying its implementation or any underlying data structure used, itself is an Abstract Data Type(ADT). ADT is any data type that doesn't specify its implementation.

But once you start talking about a concrete Tree with specific implementation using Linked List or Arrays, then that kind of concrete tree is a data structure.

With the above out of the way, the following may help you clear other confusions related to your question. Correct me if I'm wrong!

Data Type

The definition of data type from Wikipedia:

A data type or simply type is a classification identifying one of various types of data.

Data type is only a classification of data. It doesn't have any specifications about how those data are implemented. IMHO, data type is only a theoretical concept.

For example, any real number can be of the data type real. But along with integers, they can both be classified as a numeric data type, say number.

As I just pointed out, ADT is one kind of data type. But whether string, int can be considered as ADTs?

The answer is both yes and no.

Yes, because programming languages can have many ways to implement string and int ; but on one condition that through out all programming languages, these data types must share consistent properties.

No, because these primitive data types are not as abstract as stacks or queues. Since these data types seldom share consistent properties in every programming language, users of them must know the underlying problems like arithmetic overflow, etc.. Two languages may both have the int data type, but one ranges up to infinity and the other up to 2^32. This kind of technical detail must-knows is not what ADTs have promised. Let's look at stacks instead. In every programming language, stack can promise you with consistent procedures like pop, push. No other details on implementation level you should know about them, you just use them however you like it in every language.

Data Structure

Let's see the definition of data structure from Wiki:

A data structure is a particular way of organizing data in a computer so that it can be used efficiently.

As you can see, data structure is all about implementations. It is not conceptual but concrete. In my opinion, every piece of data in a program can by definition be considered as a data structure. A string can. An int can. And a whole bunch of other things like LinkedList_Stack or Array_Stack are all data structures.

Some of you might argue why int is a data structure? It's a data structure in a lower level from a programming language's author's view. Because programming languages can have many ways storing an int data type in a computer. The most common solution is two's complement, other alternatives are offset binary and ones' complement etc. However, from a user's view, we see int as the primitive data type which a programming language offers out of the box, we don't care its implementation. It's just the building block of one programming language. So for us users, any data constructed by these building blocks(primitive data types) of a programming language is more like a data structure. While for authors of programming languages, the building blocks are some lower level machine code, so for them int is definitely a data structure.

Put simply, whether one thing is a data structure or not really depends on how we look at it.

Upvotes: 3

Related Questions