数据结构动态分配空间 c++_数据结构-引言-链式数据结构(2)

链式数据结构由数据记录(节点)集组成,并通过引用(链接或是指针)链接在一起。在链式数据结构中,链接被认为是一种特殊的数据类型,只有三种操作即引用、解引用和比较相等,与数组和其它要求对指针做算术操作的数据结构不同。即使使用数组作为节点的存储结构(指针是数组的索引),只要不对索引做算术运算,该数据结构就是链式数据结构。

有两种建立链接的方式,使用动态分配和使用数组索引链接。链式数据结构有链表、搜索树、表达树和其它多种广泛使用的数据结构。同时也是多种高效算法的关键构造块,如拓扑排序与集合并查找。

评:链式数据结构与数组的本质区别在于是否对地址做算术运算。

常见的链式数据结构


1) 链接链表

链接链表是数据结构的集合,它们不是由内存的物理位置排序的,而是通过存储在结构内部的逻辑链接排序的。结构内有两部分即数据域和地址域,地址域的址为其后继的内存地址。链表的形式有单链表、双链表、多链表、线性链表、循环链表


基本属性

  • 对象(节点)线性相链
  • 一直引用第一个节点,即 'head' or 'front'

7244bd3110b3b6aa3f7ceccbdb03e52c.png

8400d3e5d283d0f93296ae87cc06f490.png

2) 搜索树

搜索树是一种树数据结构,它的节点数据值存储在有序集合中中序遍历即可升序访问存储的值。

基本属性

  • 对象(节点)存储在有序集中
  • 中序遍历提供树中升序的数据读出
  • 其子树嵌套在其内部

相比于数组的优势与劣势

比数组具有更加灵活的数据组织与空间分配的方式,数组是提前分配的连续的内存空间,而链表是动态按需分配可离散的空间。


In array, the array elements have to be in contiguous(connected and sequential) portion of memory. But in linked data structure, the reference to each node gives us the information where to find out the next one.

The nodes of a linked data structure can also be moved individually to different locations without affecting the logical connections between them, unlike arrays. With due care, a process can add or delete nodes to one part of a data structure even while other processes are working on other parts.


On the other hand, access to any particular node in a linked data structure requires following a chain of references that stored in it. If the structure has n nodes, and each node contains at most b links, there will be some nodes that cannot be reached in less than logb n steps. For many structures, some nodes may require worst case up to n−1 steps. In contrast, many array data structures allow access to any element with a constant number of operations, independent of the number of entries.


Broadly the implementation of these linked data structure is through dynamic data structures. It gives us the chance to use particular space again. Memory can be utilized more efficiently by using this data structures. Memory is allocated as per the need and when memory is not further needed, deallocation is done.

一般缺点
Linked data structures may also incur in substantial memory allocation overhead (if nodes are allocated individually) and frustrate memory paging and processor caching algorithms (since they generally have poor locality of reference). In some cases, linked data structures may also use more memory (for the link fields) than competing array structures. This is because linked data structures are not contiguous. Instances of data can be found all over in memory, unlike arrays.


In arrays, nth element can be accessed immediately, while in a linked data structure we have to follow multiple pointers so element access time varies according to where in the structure the element is.


In some theoretical models of computation that enforce the constraints of linked structures, such as the pointer machine, many problems require more steps than in the unconstrained random access machine model.

引用
[1] Donald Knuth, The Art of Computer Programming
[2] Bernard A. Galler and Michael J. Fischer. An improved equivalence algorithm. Communications of the ACM, Volume 7, Issue 5 (May 1964),
pages 301-303. The paper originating disjoint-set forests. ACM Digital Library (http://portal.acm.org/citation.cfm?doid=364099.364331) [3] http://www.cs.toronto.edu/~hojjat/148s07/lectures/week5/07linked.pdf

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值