Linked List vs Array
Both Arrays and Linked List can be used to store linear data of similar types, but they both have some advantages and disadvantages over each other.
Following are the points in favour of Linked Lists.
(1) The size of the arrays is fixed: So we must know the upper limit on the number of elements in advance. Also, generally, the allocated memory is equal to the upper limit irrespective of the usage, and in practical uses, upper limit is rarely reached.
(2) Inserting a new element in an array of elements is expensive, because room has to be created for the new elements and to create room existing elements have to shifted.
For example, suppose we maintain a sorted list of IDs in an array id[].
id[] = [1000, 1010, 1050, 2000, 2040, .....].
And if we want to insert a new ID 1005, then to maintain the sorted order, we have to move all the elements after 1000 (excluding 1000).
Deletion is also expensive with arrays until unless some special techniques are used. For example, to delete 1010 in id[], everything after 1010 has to be moved.
So Linked list provides following two advantages over arrays
1) Dynamic size
2) Ease of insertion/deletion
Linked lists have following drawbacks:
1) Random access is not allowed. We have to access elements sequentially starting from the first node. So we cannot do binary search with linked lists.
2) Extra memory space for a pointer is required with each element of the list.
3) Arrays have better cache locality that can make a pretty big difference in performance.
Please also see thisthread.
References:
http://cslibrary.stanford.edu/103/LinkedListBasics.pdf
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Linked List vs Array的更多相关文章
- 关于Android中ArrayMap/SparseArray比HashMap性能好的深入研究
由于网上有朋友对于这个问题已经有了很详细的研究,所以我就不班门弄斧了: 转载于:http://android-performance.com/android/2014/02/10/android-sp ...
- ArryList vs LinkedList
references: http://www.javaperformancetuning.com/articles/randomaccess.shtml http://stackoverflow.co ...
- The C5 Generic Collection Library for C# and CLI
The C5 Generic Collection Library for C# and CLI https://github.com/sestoft/C5/ The C5 Generic Colle ...
- 给Lisp程序员的Python简介
给Lisp程序员的Python简介 作者:Peter Norvig,译者:jineslong<zzljlu@gmail.com> 这是一篇为Lisp程序员写的Python简介(一些Pyth ...
- amazon interview
I'll be sitting for an Amazon interview in 3 months. Which website should I use to practice: SPOJ, H ...
- [004] last_k_node
[Description] find the k-th node from the last node of single linked list. e.g. Linked-list: 1-2-3-4 ...
- 面试题——ArrayList和LinkedList的区别
List概括 先回顾一下List在Collection的框架图: 从图中可以看出: List是一个接口,他继承Collection接口,代表有序的队列. AbstractList是一个抽象类, ,它继 ...
- Array vs Linked List
Access: Random / Sequential 1. Array element can be randomly accessed using index 2. Random access f ...
- Lintcode489-Convert Array List to Linked List-Easy
489. Convert Array List to Linked List Convert an array list to a linked list. Example Example 1: In ...
随机推荐
- 用cudamat做矩阵运算的GPU加速
1. cudamat简介 cudamat是一个python语言下,利用NVIDIA的cuda sdk 进行矩阵运算加速的库.对于不熟悉cuda编程的程序员来说,这是一个非常方便的GPU加速方案.很多工 ...
- Typical sentences in SCI papers
Beginning 1. In this paper, we focus on the need for 2. This paper proceeds as follow. 3. Th ...
- 隐藏虚拟键盘,解决键盘挡住UITextField问题
再正式开始之前,先来介绍一下IOS的键盘类型: 一.键盘风格 UIKit框架支持8种风格键盘 ? 1 2 3 4 5 6 7 8 9 10 typedef enum { UIKeyboard ...
- linux命令之grep用法介绍
Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来.grep全称是Global Regular Expression Print,表示全局正则表达 ...
- jQuery对input中radio的一些操作
通过jQuery获取页面中的所有radio对象,遍历页面中的radio,取消选中的标签,因为使用到jQuery时间,因此引用到了网上公共的js,这只是本人的一些总结,大神勿喷. <html> ...
- width100%,设置padding或border溢出解决方法
.box { width: 100px; height: 100px; background: red;} .bd { width: 100%; padding: 10px; background: ...
- 使用tortoise git管理gitolite版本库
gitolite-admin是用于管理git版本库的版本库,将其从服务器上clone下来. 使用tortoise git clone的时候需要指定私钥,私钥的格式是ppk的,需要使用putty的PUT ...
- SequoiaDB数据库集群部署
一般在多机环境下部署数据库的集群模式是比较繁琐的,下面我来分享一个如何通过shell脚本的方式简单.方便地部署我们的集群. 首先,我们要给机器配置信任关系,这样我们就无需手动的输入密码来执行ssh和s ...
- 【zendstudio】如何利用zendstudio新建 或导入php项目
一.利用ZendStudio创建 PHP Project 1. 打开ZendStudio, 选择:File à New à PHP Project, 如下图所示: 于是弹出如下界面: 在”Projec ...
- Oracle中的IF...THEN...ELSE判断
if...then...else是最常见的一种判断语句,他可以实现判断两种情况. 标准语法如下: if <condition_expression> then plsql_sentence ...