数据结构基本概念
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数据结构基本概念相关的知识,希望对你有一定的参考价值。
摘自《C程序设计》(姜学锋 曹光前 编著,清华大学出版社)
数据
对客观事物的符号表示,能输入到计算机并能被计算机处理的符号的集合。
数据元素
数据的基本单位,计算机内作为一个整体考虑和处理。
数据项
一个数据元素可由若干个数据项组成,数据项是数据不可分割的最小单位,也称为字段或域。
数据对象
性质相同的数据元素的集合,是数据的一个子集。
数据结构
相互之间存在一种或多种特定关系的数据元素的集合。包含
- 数据的逻辑结构(数据元素之间的关系)
- 数据的存储结构(数据元素及其关系在计算机中的表示)
- 对该数据的操作(数据的运算)
三个方面的内容。
4类逻辑结构
- 集合:结构中的数据元素之间除了“同属于一个集合”的关系外,别无其他关系。
- 线性结构:结构中的数据元素之间存在一个对一个的关系。
- 树形结构:结构中的数据元素之间存在一个对多个的关系。
- 图形结构或网状结构:结构中的数据元素之间存在一对多或多对多的关系。线性结构是树形结构的特例,而树形结构又是图形结构的特例。
树形结构和图形结构统称为非线性结构。
4种常用的存储结构
- 顺序存储结构:把逻辑上相邻的元素存储在物理上相邻的存储单元中,元素之间的逻辑关系由存储空间的邻接关系直接体现。优点是节省存储空间,缺点是不便于对元素进行插入和删除运算。
- 链式存储结构:逻辑上相邻的元素并不要求物理上相邻,元素之间的逻辑关系由附加的指针域表示。主要优点是便于插入和删除运算,缺点是需要额外的指针空间,且不能对元素进行随机访问。
- 索引存储结构:在存储元素信息的同时还建立附加的索引表,索引表由关键字和指向元素的指针组成。这种结构大大提高了数据查找的速度,可以对元素进行随机访问,在进行插入、删除运算时速度也很快。缺点是需要额外的空间来存储索引表。
- 哈希存储结构:根据关键字通过哈希函数计算出元素位置,优点是查找速度快,适合快速查找和插入元素的场合。这种结构只存储元素的数据,不存储元素之间的逻辑关系。
抽象数据类型ADT
ADT 抽象数据类型名{
数据对象:数据对象的定义
数据关系:数据关系的定义
基本运算:基本运算的定义
}ADT 抽象数据类型名
其中,基本运算的定义格式为:
基本运算名(参数表) 初始条件:描述初始条件
操作结果:描述运算功能和操作结果
wikipedia
In computer science, a data structure is a particular way of organizing data in a computer so that it can be used efficiently. Data structures can implement one or more particular abstract data types (ADT), which specify the operations that can be performed on a data structure and the computational complexity of those operations. In comparison, a data structure is a concrete implementation of the specification provided by an ADT.
Different kinds of data structures are suited to different kinds of applications, and some are highly specialized to specific tasks. For example, relational databases commonly use B-tree indexes for data retrieval, while compiler implementations usually use hash tables to look up identifiers.
Data structures provide a means to manage large amounts of data efficiently for uses such as large databases and internet indexing services. Usually, efficient data structures are key to designing efficient algorithms. Some formal design methods and programming languages emphasize data structures, rather than algorithms, as the key organizing factor in software design. Data structures can be used to organize the storage and retrieval of information stored in both main memory and in secondary memory.
Data structures are generally based on the ability of a computer to fetch and store data at any place in its memory, specified by a pointer—a bit string, representing a memory address, that can be itself stored in memory and manipulated by the program. Thus, the array and record data structures are based on computing the addresses of data items with arithmetic operations; while the linked data structures are based on storing addresses of data items within the structure itself. Many data structures use both principles, sometimes combined in non-trivial ways (as in XOR linking).
The implementation of a data structure usually requires writing a set of procedures that create and manipulate instances of that structure. The efficiency of a data structure cannot be analyzed separately from those operations. This observation motivates the theoretical concept of an abstract data type, a data structure that is defined indirectly by the operations that may be performed on it, and the mathematical properties of those operations (including their space and time cost).
In computer science, an abstract data type (ADT) is a mathematical model for data types where a data type is defined by its behavior (semantics) from the point of view of a user of the data, specifically in terms of possible values, possible operations on data of this type, and the behavior of these operations. This contrasts with data structures, which are concrete representations of data, and are the point of view of an implementer, not a user.
Formally, an ADT may be defined as a "class of objects whose logical behavior is defined by a set of values and a set of operations"; this is analogous to an algebraic structure in mathematics. What is meant by "behavior" varies by author, with the two main types of formal specifications for behavior being axiomatic (algebraic) specification and an abstract model; these correspond to axiomatic semantics and operational semantics of an abstract machine, respectively. Some authors also include the computational complexity ("cost"), both in terms of time (for computing operations) and space (for representing values).
In practice many common data types are not ADTs, as the abstraction is not perfect, and users must be aware of issues like arithmetic overflow that are due to the representation. For example, integers are often stored as fixed width values (32-bit or 64-bit binary numbers), and thus experience integer overflow if the maximum value is exceeded.
ADTs are a theoretical concept in computer science, used in the design and analysis of algorithms, data structures, and software systems, and do not correspond to specific features of computer languages—mainstream computer languages do not directly support formally specified ADTs. However, various language features correspond to certain aspects of ADTs, and are easily confused with ADTs proper; these include abstract types, opaque data types, protocols, and design by contract. ADTs were first proposed by Barbara Liskov and Stephen N. Zilles in 1974, as part of the development of the CLU language.
Some common ADTs, which have proved useful in a great variety of applications, are
- Container
- List
- Set
- Multiset
- Map
- Multimap
- Graph
- Stack
- Queue
- Priority queue
- Double-ended queue
- Double-ended priority queue
以上是关于数据结构基本概念的主要内容,如果未能解决你的问题,请参考以下文章