Advanced programmers lessons - Architect of the road (3) - Linear table

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/m0_37609579/article/details/99484349

First, the definition of the linear form

[Baidu Encyclopedia] linear table is the most basic, simplest and most commonly used data structures. Linear table (linear list) is a data structure of one, a linear table is a finite sequence of n data elements having the same characteristics.

A linear relationship between the tables is one to one relationship between data elements, i.e. in addition to the first and last data element, other data elements are end to end (note that most of these words only for the linear form , but not all. For example, on the circulation list logical hierarchy table is also a linear (chain stores belonging to the storage hierarchy), but the tail pointer points to the last data element of the first node).

  1. Linear table (List) is a collection of zero or more data elements
  2. Between data elements in the table is a linear sequential
  3. The number of data elements in a linear table is limited
  4. Linear table type data elements must be the same

Life linear form:

It is also a linear array table.

Second, the classification of the linear form

1. order table

          The basic idea: storage element is continuous. Are sequentially stored in the memory, the memory area division is continuous. Storage structure as follows:

2. list

          The basic idea: the storage elements are discrete, separate (physical), they can be logically link pointer makes it the overall list. It is divided into two portions and pointers stored. Storage structure shown below:

Circular list and single linked list can be traversed in one direction only; and doubly-linked circular list, the first node and a last node are connected together, it can be regarded as "no no tail"; double-linked list can move in two directions, and more flexibility Big.

Three common operations, the linear form

  1. Create a linear table
  2. Destruction linear table
  3. Empty linear table
  4. Element into the linear form
  5. To remove elements from the linear table
  6. Obtain linear elements in the table to a location
  7. 获取线性表的长度

四、选择合适的数据结构

1.基于存储的考虑

顺序表的存储空间是静态分配的,在程序执行之前必须明确规定它的存储规模,也就是说事先对"MAXSIZE"要有合适的设定,过大造成浪费,过小造成溢出。可见对线性表的长度或存储规模难以估计时,不宜采用顺序表;链表不用事先估计存储规模,但链表的存储密度较低(存储密度是指一个结点中数据元素所占的存储单元和整个结点所占的存储单元之比,显然链式存储结构的存储密度是小于1的)。

2.基于运算的考虑

在顺序表中按序号访问的时间性能为O(1),而链表中按序号访问的时间性能O(n),所以如果经常做的运算是按序号访问数据元素,显然顺序表优于链表;而在顺序表中做插入、删除时平均移动表中一半的元素,当数据元素的信息量较大且表较长时,这一点是不应忽视的;在链表中作插入、删除,虽然也要找插入位置,但操作主要是比较操作,从这个角度考虑显然后者优于前者。

3.基于环境的考虑

顺序表容易实现,任何高级语言中都有数组类型,链表的操作是基于指针的,相对来讲前者简单些,也是用户考虑的一个因素。


我的微信公众号:架构真经(id:gentoo666),分享Java干货,高并发编程,热门技术教程,微服务及分布式技术,架构设计,区块链技术,人工智能,大数据,Java面试题,以及前沿热门资讯等。每日更新哦!

参考资料:

  1. https://www.cnblogs.com/yaowen/p/4272310.html
  2. https://www.cnblogs.com/itgungnir/p/6671855.html

Guess you like

Origin www.cnblogs.com/anymk/p/11470480.html