Type of data structure

Logical data structures:

It refers to the logical structure data of the logical relationship between the elements (real and independent).

Category I: linear and nonlinear structural configuration

  Linear structure: there is only a start node and a terminal node, and all nodes have at most only a direct precursor and a direct successor.

Linear list is a typical linear structure, it has four basic features:

  1. there must only set a "first element";

  2. there must only set a "final element";

  3. In addition to the final element, other data elements are only "immediate successor";

  4. In addition to the first element, other data elements are only "immediate predecessor."

 

 

 Case in life: sugar-coated haws, line up on the subway

Nonlinear structure:

  It corresponds to a linear structure, wherein the logical structure is a nonlinear element may correspond to a plurality of nodes and a plurality of direct precursor immediate successor.

Common nonlinear structure:

  Trees (binary trees, etc.), images (net).

  Tree: a node may correspond to a plurality of direct successor, but each node can correspond to a direct precursor (many)

  FIG. (Net): a node may correspond to a plurality of direct predecessor and successor directly (many)

 

  Tree: Life Stories

      Unit organizational structure, genealogy

 

 

 Technical Case: File System

 

 

 Figure: Life Stories

  Traffic route map, subway map

 

 

Category 2: collection structure, linear structure, a tree structure, the network structure

   There are four basic types of logical structure: a collection structure, linear structure, a tree structure and a network structure.

  Tree Table and are the two most commonly efficient data structures, many efficient algorithm can be used to design these two data structures implemented.

1. collection structure:

  Is a collection of learned mathematics, elements of the collection has three characteristics:

  1). Uncertainty (the set of elements must be determined)

  2) Uniqueness (set of mutually different elements, for example: set A = {1, a}, then a is not equal to 1)

  3) disorder (elements in the set, for example, no particular order: the set {3,4,5} and {3,5,4} the same set count)

 Relationships between data elements of the structure are "belong to the same set", in addition no other relations.

 Because the relationship is weak element in the collection, study without the structure of the data structure.

2. Linear Structure:

  Data structure linear structure means that there is a data structure of "one to one" linear relationship between data elements.

3.树状结构:

  除了一个数据元素(元素01)以外每个数据元素有且仅有一个直接前驱元素,但是可以有多个直接后继元素。

  特点是数据元素之间是1对多的联系

4.网络结构:

  每个数据元素可以有多个直接前驱元素,也可以有多个直接后继元素。特点是数据元素之间是多对多的联系

 

 

举例说明:

  一个班的学生是什么逻辑结构?

答:一个班的学生是一个集合

  排队做某项事情时就是线性结构

  学生会成员上下级关系就是树状结构

  同学之间的座位关系就是网状结构

数据的存储结构

数据的存储结构主要包括数据元素本身的存储以及数据元素之间关系表示,是数据的逻辑结构在计算机中的表示

常见的存储结构有顺序存储,链式存储,索引存储,以及散列存储

1.顺序存储结构:

  把逻辑上相邻的节点存储在物理位置上相邻的存储单元中,结点之间的逻辑关系由存储单元的邻接关系来体现

  由此得到的存储结构为顺序存储结构,通常顺序存储结构是借助于计算机程序设计语言(例如C/C++)的数组来描述的。

数据元素的存储对应于一块连续的存储空间,数据元素之间的前驱和后继关系通过数据元素在存储器中的相对位置来反映。

 

 

 优点:

  1.节省存储空间,因为分配给数据的存储单元全用来存放结点的数据(不考虑C/C++语言中数组需要指定大小的情况),结点之间的逻辑没有占用额外的存储空间。

  2.采用这种方法时,可以实现对节点的随机存取,即每一个节点对应一个序号,由该序号直接计算出来节点的存储地址。

 缺点:

  1.插入和删除操作需要移动元素,效率较低。

  2.必须提前分配固定数量的空间,如果存储元素少,可能导致空间的浪费。

2.链式存储结构:

数据元素的存储对应的是不连续的存储空间,每个存储节点对应一个需要存储的数据元素

  1.每个结点是由数据域和指针域组成。元素之间的逻辑关系通过存储结点之间的链接关系反映出来。

  (每个结点中需要存储本结点的数据和下一个结点数据的指针/地址)

  2.逻辑上相邻的结点物理上不必相邻

 

 

 缺点:

  1.比顺序存储结构的存储密度小(每个结点都由数据域和指针域组成,所以相同空间内假设全存满的话顺序比链式存储更多)。

  2.查找结点时链式存储要比顺序存储慢。

 优点:

  1.插入、删除灵活(不必移动结点、只要改变结点中的指针)。

  2.有元素才会分配结点空间,不会有闲置的结点。

3.索引存储结构:

  除建立存储结点信息外,还建立附加的索引表来标识结点的地址。

比如图书、字典的目录。

 

 

4. 散列存储结构:

  根据每个结点的关键字直接计算出该结点的存储地址HashSet、HashMap

  一种神奇的结构,添加、查询速度快。就像数组中按索引查找。

 

 

 

注意:

  同一种逻辑结构可以对应多种存储结构

  同样的运算,在不同的存储结构中,其实现过程是不同的(运算依赖于存储结构)

 

Guess you like

Origin www.cnblogs.com/zang1998/p/11560379.html