Is there a difference between 'data structure' and 'data type'?

后端 未结 3 1695
挽巷
挽巷 2020-12-28 21:57

Two of the questions that often come up in the Uni exam, where I study, are:

  • Define data types. Classify and explain datatypes
  • Define data structures. Cl
  • 3条回答
    •  误落风尘
      2020-12-28 22:28

      The distinction is between abstract and concrete data structures. Some CS textbooks refer to abstract data structures as "data types", which is confusing because not all data types are data structures. They use "data structure" to specifically mean a concrete data structure.

      An abstract data structure, also called an abstract data type, is the interface of the data structure. Java often represents them using interfaces; examples are List, Queue, Map, Deque, Set. (But there are others not represented in Java, such as bags/multisets, multimaps, graphs, stacks, and priority queues.) They are distinguished by their behavior and how you use the data structure. For instance, a set is characterized by forbidding duplicates and not recording order, whereas a list allows duplicates and remembers the order. A queue has a restricted interface that only lets you add to one end and remove from the other.

      A concrete data structure is an implementation of an abstract data structure. Examples are ArrayList and LinkedList. These are both implementations of lists; while their list interface is the same, the programmer might still care about their different performance characteristics. Note that LinkedList also implements Queue.

    提交回复
    热议问题