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 ...
随机推荐
- [GeekBand]C++高级编程技术(2)
本篇笔记主要分为两个主要部分,第一部分关于对象模型,第二部分是关于new和delete的更加深入的学习. 一.对象模型 关于vptr(虚指针)和vtbl(虚函数表) 只要用到了虚函数,对象中就会多一个 ...
- 【风马一族_Android】适合你 --- 大概的描述
适合你:专注于解决毕业生,离校所遗留的闲置教材的去向问题的一款APP. 目前的现状:毕业生的闲置教材,被清理宿舍的阿姨.大叔所清理到垃圾场,或拿到收破烂的地方,卖掉. 在毕业季中,存在的闲置物品不只有 ...
- 在指定的DSN中,驱动程序和应用程序之间的体系结构不匹配
今天在使用plsql通过odbc导入excel数据时发生了一个错误,截图如下: 错误提示为:驱动程序和应用程序之间的体系结构不匹配. 后来百度了一下,得出答案.系统是win10 64位.excel驱动 ...
- SASS语法备忘
sass语法 关于sass 3.3.0更新说明——3.3.0 sublime相关插件为:scss语法高亮,sass语法高亮,编译,保存即编译,格式化 文件后缀名 sass有两种后缀名文件:一种后缀名为 ...
- CSS的IE6、IE7、FF兼容性写法
blue;< /td> Firefox 背景变蓝色 red /9; IE8 背景变红色 *black;< /td> IE7 背景变黑色 _background:orange; ...
- CLR via C# 计算限制的异步操作读书笔记
1. 使用线程池搪行简单的计算限制操作 ThreadPool.QueueUserWorkItem(WaitCallback callback) 2.CLR默认情况下自动使初始线程的执行上下文流向辅助线 ...
- SQLdiag Utility
使用SQLdiag 会进行信息搜集类型 Windows 系统性能日志 Windows 系统日志 SQL Server 性能信息 SQL Server 阻塞信息 SQL Server 配置信息 如何使用 ...
- 通过keepalived实现 MySQL VIP 自动切换
首先配置keepalived.链接如下:http://blog.itpub.net/28939273/viewspace-1808369/ 主服务器keepalived的配置文件内容如下: [root ...
- JavaScript 代码片段
1.无题 if (i && i.charAt(i.length - 1) == "/") { i = i.substr(0, i.length - 1) } 2.无 ...
- Entity Framework(序)
ADO.NET Entity Framework 是一个对象-关系的映射结构,它提供了ADO.NET的一个抽象,可基于引用的数据库获取对象模型.可以通过Entity Framework 使用不同的变成 ...